示例#1
0
        private void OnCommandGetNonce(string[] args)
        {
            Task.Run(async() =>
            {
                string address = args[0].IsHexString() ? args[0] : wallets.TryGetValue(args[0], out var account) ? (string)account.Address : null;
                string arg     = args.Length > 1 ? args[1] : Be4Helper.LATEST;

                if (string.IsNullOrEmpty(address))
                {
                    BConsole.WriteLine("address not found");
                    return;
                }

                (ulong?nonce, string error) = await web4b.GetTransactionCountAsync(address, arg);
                BConsole.WriteLine(Color.DarkGreen, nonce);
            });
        }
示例#2
0
        public async Task ShouldPassBe4CallTest()
        {
            string  error;
            Address coinbase;
            long    number;
            H256    hash;
            ulong?  balance, nonce;
            JObject block, block1;
            int     count;

            // be4_coinbase
            (coinbase, error) = await be4.GetCoinbaseAsync();

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(string.IsNullOrEmpty(coinbase));

            // be4_blockNumber
            (number, error) = await be4.GetBlockNumberAsync();

            Assert.True(string.IsNullOrEmpty(error));

            // be4_getBalance ( earliest )
            (balance, error) = await be4.GetBalanceAsync(coinbase, Be4Helper.EARLIEST);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.NotNull(balance);

            // be4_getBalance ( latest )
            (balance, error) = await be4.GetBalanceAsync(coinbase, Be4Helper.LATEST);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.NotNull(balance);

            // be4_getBalance ( pending )
            (balance, error) = await be4.GetBalanceAsync(coinbase, Be4Helper.PENDING);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.NotNull(balance);

            // be4_getBalance ( number )
            (balance, error) = await be4.GetBalanceAsync(coinbase, Hex.ToString(number, true));

            Assert.True(string.IsNullOrEmpty(error));
            Assert.NotNull(balance);

            // be4_getTransactionCount ( earliest )
            (nonce, error) = await be4.GetTransactionCountAsync(coinbase, Be4Helper.EARLIEST);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.NotNull(nonce);

            // be4_getTransactionCount ( latest )
            (nonce, error) = await be4.GetTransactionCountAsync(coinbase, Be4Helper.LATEST);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.NotNull(nonce);

            // be4_getTransactionCount ( pending )
            (nonce, error) = await be4.GetTransactionCountAsync(coinbase, Be4Helper.PENDING);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.NotNull(nonce);

            // be4_getBalance ( number )
            (nonce, error) = await be4.GetTransactionCountAsync(coinbase, Hex.ToString(number, true));

            Assert.True(string.IsNullOrEmpty(error));
            Assert.NotNull(nonce);

            // be4_getBlockByNumber / be4_getBlockByHash
            (block, error) = await be4.GetBlockByNumberAsync(number, true);

            Assert.True(string.IsNullOrEmpty(error));

            hash = block.Value <string>("hash");

            (block1, error) = await be4.GetBlockByHashAsync(block.Value <string>("hash"), true);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.Equal(block.Value <string>("hash"), block1.Value <string>("hash"));

            // be4_getBlockTransactionCountByHash
            (count, error) = await be4.GetBlockTransactionCountByHashAsync(hash);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.True(count >= 0);

            // be4_getBlockTransactionCountByNumber
            (count, error) = await be4.GetBlockTransactionCountByNumberAsync(number);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.True(count >= 0);
        }