Esempio n. 1
0
        private void OnCommandGetTxHistory(string[] args)
        {
            Task.Run(async() =>
            {
                string address = wallets.TryGetValue(args[0], out var account) ? (string)account.Address : args[0];
                long start     = args.Length > 1 ? Convert.ToInt64(args[1]) : 0;
                bool desc      = args.Length > 2 ? "desc" == args[2].ToLower() : false;
                int max        = args.Length > 3 ? Convert.ToInt32(args[3]) : 100;

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

                (var txs, string error) = await web4b.GetTransactionsByAddressAsync(address, start, desc, max);
                BConsole.WriteLine("history=", txs.ToString());
            });
        }
Esempio n. 2
0
        public async Task ShouldPassBe4TransactionTest(string from, string to)
        {
            PrivateKey sender = from, receiver = to;
            string     error, txid;
            bool?      mining;
            ulong?     balance;
            JArray     pending, history;
            JObject    receipt, tx;

            // sender should has at leat 1 brc for transaction test
            (balance, error) = await be4.GetBalanceAsync(sender.Address);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.NotNull(balance);
            Assert.True(balance >= Coin.ToBeryl(1));

            // should mining
            (mining, error) = await be4.GetMiningAsync();

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

            // send transaction
            (txid, error) = await be4.SendTransactionAsync(sender, receiver.Address, Coin.ToBeryl(0.0001m));

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

            // pending transaction
            (pending, error) = await be4.GetPendingTransactionsAsync();

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(pending is null);
            Assert.True(pending.ToObject <IEnumerable <JObject> >().Where(t => t.Value <string>("hash") == txid).Count() > 0);

            // get transaction receipt
            (receipt, error) = await be4.WaitTransactionReceiptAsync(txid);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(receipt is null);
            Assert.True(receipt.Value <string>("hash") == txid);

            // get transaction
            (tx, error) = await be4.GetTransactionByHashAsync(txid);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(tx is null);
            Assert.True(tx.Value <string>("hash") == txid);

            // get transaction by block hash and index
            (var tx1, string err1) = await be4.GetTransactionByBlockHashAndIndexAsync(tx.Value <string>("blockHash"), Hex.ToNumber <int>(tx.Value <string>("blockIndex")));

            Assert.True(string.IsNullOrEmpty(err1));
            Assert.False(tx1 is null);
            Assert.True(tx1.Value <string>("hash") == txid);

            // get transaction by block number and index
            (var tx2, string err2) = await be4.GetTransactionByBlockNumberAndIndexAsync(Hex.ToNumber <long>(tx.Value <string>("blockNumber")), Hex.ToNumber <int>(tx.Value <string>("blockIndex")));

            Assert.True(string.IsNullOrEmpty(err2));
            Assert.False(tx2 is null);
            Assert.True(tx2.Value <string>("hash") == txid);

            // get transaction history of sender
            (history, error) = await be4.GetTransactionsByAddressAsync(sender.Address, Hex.ToNumber <long>(tx.Value <string>("blockNumber")), true, 20);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(history is null);
            Assert.True(history.ToObject <IEnumerable <JObject> >().Where(t => t.Value <string>("hash") == txid).Count() > 0);

            // get transaction history of receiver
            (history, error) = await be4.GetTransactionsByAddressAsync(receiver.Address, Hex.ToNumber <long>(tx.Value <string>("blockNumber")), false, 20);

            Assert.True(string.IsNullOrEmpty(error));
            Assert.False(history is null);
            Assert.True(history.ToObject <IEnumerable <JObject> >().Where(t => t.Value <string>("hash") == txid).Count() > 0);
        }