private async Task <int> OnExecuteAsync(CommandLineApplication app, IConsole console) { try { var(chain, _) = Program.LoadExpressChain(Input); var senderAccount = chain.GetAccount(Sender); if (senderAccount == null) { throw new Exception($"{Sender} sender not found."); } var receiverAccount = chain.GetAccount(Receiver); if (receiverAccount == null) { throw new Exception($"{Receiver} receiver not found."); } var uri = chain.GetUri(); var unspents = (await NeoRpcClient.GetUnspents(uri, senderAccount.ScriptHash) .ConfigureAwait(false))?.ToObject <UnspentsResponse>(); if (unspents == null) { throw new Exception($"could not retrieve unspents for {Sender}"); } var assetId = NodeUtility.GetAssetId(Asset); var tx = RpcTransactionManager.CreateContractTransaction( assetId, Quantity, unspents, senderAccount, receiverAccount); tx.Witnesses = new[] { RpcTransactionManager.GetWitness(tx, chain, senderAccount) }; var sendResult = await NeoRpcClient.SendRawTransaction(uri, tx); if (sendResult == null || !sendResult.Value <bool>()) { throw new Exception("SendRawTransaction failed"); } console.WriteLine($"Transfer Transaction {tx.Hash} submitted"); return(0); } catch (Exception ex) { console.WriteError(ex.Message); app.ShowHelp(); return(1); } }
private async Task <int> OnExecuteAsync(CommandLineApplication app, IConsole console) { try { var(chain, _) = Program.LoadExpressChain(Input); var account = chain.GetAccount(Account); if (account == null) { throw new Exception($"{Account} account not found."); } var uri = chain.GetUri(); var claimable = (await NeoRpcClient.GetClaimable(uri, account.ScriptHash) .ConfigureAwait(false))?.ToObject <ClaimableResponse>(); if (claimable == null) { throw new Exception($"could not retrieve claimable for {Account}"); } var gasHash = Neo.Ledger.Blockchain.UtilityToken.Hash; var tx = RpcTransactionManager.CreateClaimTransaction(account, claimable, gasHash); tx.Witnesses = new[] { RpcTransactionManager.GetWitness(tx, chain, account) }; var sendResult = await NeoRpcClient.SendRawTransaction(uri, tx); if (sendResult == null || !sendResult.Value <bool>()) { throw new Exception("SendRawTransaction failed"); } console.WriteLine($"Claim Transaction {tx.Hash} submitted"); return(0); } catch (Exception ex) { console.WriteError(ex.Message); app.ShowHelp(); return(1); } }