Send tokens
This commit is contained in:
@@ -239,6 +239,55 @@ public class AccountService : IAccountService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<SwapInfos> SendTokenAsync(User user, string accountName, string recipientAddress, Ticker ticker, decimal amount, int? chainId = null)
|
||||
{
|
||||
// Get the account for the user
|
||||
var account = await GetAccountByUser(user, accountName, true, false);
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
throw new ArgumentException($"Account '{accountName}' not found for user '{user.Name}'");
|
||||
}
|
||||
|
||||
// Ensure the account has a valid address/key
|
||||
if (string.IsNullOrEmpty(account.Key))
|
||||
{
|
||||
throw new ArgumentException($"Account '{accountName}' does not have a valid address");
|
||||
}
|
||||
|
||||
// Validate recipient address
|
||||
if (string.IsNullOrEmpty(recipientAddress))
|
||||
{
|
||||
throw new ArgumentException("Recipient address is required");
|
||||
}
|
||||
|
||||
// Validate amount
|
||||
if (amount <= 0)
|
||||
{
|
||||
throw new ArgumentException("Amount must be greater than zero");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Call the Web3ProxyService to send tokens
|
||||
var swapInfos = await _web3ProxyService.SendTokenAsync(
|
||||
account.Key,
|
||||
recipientAddress,
|
||||
ticker,
|
||||
amount,
|
||||
chainId
|
||||
);
|
||||
|
||||
return swapInfos;
|
||||
}
|
||||
catch (Exception ex) when (!(ex is ArgumentException || ex is InvalidOperationException))
|
||||
{
|
||||
_logger.LogError(ex, "Error sending tokens for account {AccountName} and user {UserName}",
|
||||
accountName, user.Name);
|
||||
throw new InvalidOperationException($"Failed to send tokens: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void ManageProperties(bool hideSecrets, bool getBalance, Account account)
|
||||
{
|
||||
if (account != null)
|
||||
|
||||
Reference in New Issue
Block a user