Ejemplo n.º 1
0
            private async Task <int> OnExecuteAsync(CommandLineApplication app, IConsole console)
            {
                try
                {
                    var(chain, _) = Program.LoadExpressChain(Input);
                    var uri = chain.GetUri();

                    var rawTxResponseTask  = NeoRpcClient.GetRawTransaction(uri, TransactionId);
                    var appLogResponseTask = NeoRpcClient.GetApplicationLog(uri, TransactionId);
                    await Task.WhenAll(rawTxResponseTask, appLogResponseTask);

                    console.WriteResult(rawTxResponseTask.Result);
                    var appLogResponse = appLogResponseTask.Result ?? JValue.CreateString(string.Empty);
                    if (appLogResponse.Type != JTokenType.String ||
                        appLogResponse.Value <string>().Length != 0)
                    {
                        console.WriteResult(appLogResponse);
                    }

                    return(0);
                }
                catch (Exception ex)
                {
                    console.WriteError(ex.Message);
                    app.ShowHelp();
                    return(1);
                }
            }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        static async Task Main(string[] args)
        {
            var uri    = new Uri("http://seed6.ngd.network:20332");
            var client = new NeoRpcClient(uri);

            var index = await client.GetBlockCountAsync();

            Console.WriteLine(index);

            var version = await client.GetVersionAsync();

            Console.WriteLine($"{version.Nonce}-{version.Port}-{version.UserAgent}");

            var hash = await client.GetBlockHashAsync(0);

            Console.WriteLine(hash);

            var header = await client.GetBlockHeaderAsync(hash);

            Console.WriteLine($"{header.Index}-{header.Timestamp}");

            // var peers = await client.GetPeersAsync();
            // Console.WriteLine($"{peers.Connected.Length}-{peers.Unconnected.Length}");
            // Console.WriteLine("connected");
            // foreach (var peer in peers.Unconnected)
            // {
            //     Console.WriteLine($"\t{peer.address}:{peer.port}");
            // }
            // Console.WriteLine("unconnected");
            // foreach (var peer in peers.Unconnected)
            // {
            //     Console.WriteLine($"\t{peer.address}:{peer.port}");
            // }

            // Console.WriteLine("\nValidators");
            // foreach (var validator in await client.GetValidatorsAsync())
            // {
            //     Console.WriteLine($"\t{validator.PublicKey}");
            // }

            var valid = await client.ValidateAddressAsync("AQVh2pG732YvtNaxEGkQUei3YA4cvo7d2i");

            Console.WriteLine($"AQVh2pG732YvtNaxEGkQUei3YA4cvo7d2i {valid}");

            var txHash = UInt256.Parse("165aaffd421198fc1dd07b845537a182e173cefb526e026972fff325d532bf9a");
            var tx     = await client.GetRawTransactionAsync(txHash);
        }
Ejemplo n.º 4
0
        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);
            }
        }