Exemplo n.º 1
0
        /// <summary>
        /// Returns the hash of the tallest block in the main chain.
        /// </summary>
        public async Task <RpcBlock> GetBlockAsync(string hashOrIndex)
        {
            var result = int.TryParse(hashOrIndex, out int index)
                ? await RpcSendAsync(GetRpcName(), index, true).ConfigureAwait(false)
                : await RpcSendAsync(GetRpcName(), hashOrIndex, true).ConfigureAwait(false);

            return(RpcBlock.FromJson(result));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns the hash of the tallest block in the main chain.
 /// </summary>
 public RpcBlock GetBlock(string hashOrIndex)
 {
     if (int.TryParse(hashOrIndex, out int index))
     {
         return(RpcBlock.FromJson(RpcSend("getblock", index, true)));
     }
     return(RpcBlock.FromJson(RpcSend("getblock", hashOrIndex, true)));
 }
Exemplo n.º 3
0
        public void TestToJson()
        {
            var rpcBlock = new RpcBlock
            {
                Block         = TestUtils.GetBlock(1),
                Confirmations = 1,
                NextBlockHash = UInt256.Zero
            };
            var json = rpcBlock.ToJson();

            json["previousblockhash"].AsString().Should().Be("0x0000000000000000000000000000000000000000000000000000000000000000");
            json["confirmations"].AsNumber().Should().Be(1);
        }
Exemplo n.º 4
0
        public void TestToJson()
        {
            var rpcBlock = new RpcBlock();
            var block    = new Block();

            TestUtils.SetupBlockWithValues(block, UInt256.Zero, out UInt256 _, out UInt160 _, out ulong _, out uint _, out Witness _, out Transaction[] _, 1);
            rpcBlock.Block = block;
            var json = rpcBlock.ToJson();

            json["previousblockhash"].AsString().Should().Be("0x0000000000000000000000000000000000000000000000000000000000000000");
            json.Should().NotBeNull();

            rpcBlock.Confirmations = 1;
            rpcBlock.NextBlockHash = UInt256.Zero;
            json = rpcBlock.ToJson();
            json["confirmations"].AsNumber().Should().Be(1);
        }