示例#1
0
        public async Task <(JArray txs, string error)> GetTransactionHistoryAsync(long start, bool desc, int max, int id = 0)
        {
            if (ReferenceEquals(Cyprus, null))
            {
                return(null, "cyprus provider not exists");
            }

            return(await Cyprus.GetTransactionsByAddressAsync(address, start, desc, max, id));
        }
        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;
                }

                (JArray txs, string error) = await web4b.GetTransactionsByAddressAsync(address, start, desc, max);
                BConsole.WriteLine("history=", txs, ", error=", error);
            });
        }
示例#3
0
        public async Task ShouldPassCyprusTransactionTest(string from, string to)
        {
            PrivateKey sender = from, receiver = to;
            string     error, txid;
            bool?      mining;
            ulong?     balance;
            JObject    receipt, tx;
            JArray     history;

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

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

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

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

            // send transfer
            (txid, error) = await cyprus.SendTransferAsync(sender, receiver.Address, Coin.ToBeryl(0.0001m));

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

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

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

            // get transaction
            (tx, error) = await cyprus.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 cyprus.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 cyprus.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 cyprus.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 cyprus.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);

            // send withdraw
            (txid, error) = await cyprus.SendWithdrawAsync(sender, sender.Address, Coin.ToBeryl(0.1m));

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

            // wait for withdraw confirm
            (receipt, error) = await cyprus.WaitTransactionReceiptAsync(txid);

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