示例#1
0
        public void GetBlockByHash(NodeCoreAdminClient adminClient)
        {
            Console.WriteLine("GetBlockByHash");
            Console.WriteLine("NC_CLI command: getblockfromhash <blockHash>");

            String blockHash = "0000000000002A866690AF6E6B7B784151DDB0565BE16EE0";


            BlockFilter filter = new BlockFilter();

            filter.Hash = blockHash.ToByteString();
            GetBlocksRequest request = new GetBlocksRequest();

            request.Filters.Add(filter);
            request.SearchLength = 2000;

            GetBlocksReply reply = adminClient.AdminClient.GetBlocks(request);

            if (reply.Success)
            {
                if (reply.Blocks.Count > 0)
                {
                    //Display info
                    int iBlockIndex = reply.Blocks[0].Number;
                    Console.WriteLine("BlockIndex={0}", iBlockIndex);
                }
            }

            Console.WriteLine("--------------------");
            Console.WriteLine();
        }
示例#2
0
        public void GetBlockByIndex(NodeCoreAdminClient adminClient)
        {
            Console.WriteLine("GetBlockByIndex");
            Console.WriteLine("NC_CLI command: getblockfromindex <blockIndex>");

            int iBlockIndex = 100;

            BlockFilter filter = new BlockFilter();

            filter.Index = iBlockIndex;
            GetBlocksRequest request = new GetBlocksRequest();

            request.Filters.Add(filter);
            request.SearchLength = 2000;

            GetBlocksReply reply = adminClient.AdminClient.GetBlocks(request);

            if (reply.Success)
            {
                if (reply.Blocks.Count > 0)
                {
                    //Display info
                    String blockHash = reply.Blocks[0].Hash.ToHexString();
                    Console.WriteLine("BlockHash={0}", blockHash);
                }
            }

            Console.WriteLine("--------------------");
            Console.WriteLine();
        }
示例#3
0
        public override async Task <GetBlocksReply> GetBlocks(GetBlocksRequest request, ServerCallContext context)
        {
            var epochBlocks = await this._databaseProxy.GetEpochBlocks(context.CancellationToken, request.EpochNumber).ConfigureAwait(false);

            var reply = new GetBlocksReply();

            reply.Blocks.AddRange(epochBlocks.Select(b => new BlockDetail
            {
                Block = new Block
                {
                    Hash             = BitConverter.ToString(b.Hash),
                    BlockNumber      = b.BlockNumber,
                    EpochNumber      = b.EpochNumber,
                    EpochSlotNumber  = b.EpochSlotNumber,
                    SlotNumber       = b.SlotNumber,
                    Size             = b.Size,
                    SlotLeader       = b.SlotLeaderId,
                    PreviousID       = b.PreviousID,
                    Timestamp        = b.Timestamp.ToTimestamp(),
                    TransactionCount = b.TransactionCount
                },
                TotalFees   = b.TotalFees,
                TotalOutSum = b.TotalOutSum.ToInt128()
            }));

            return(reply);
        }