コード例 #1
0
        private static GetBlockByHashResponse BlockToJSON(Header blockHeader, UInt64 blockHeight, HashList txHashes,
                                                          decimal blockReward, UInt64 currentHeight, byte[] nextBlockHash,
                                                          UInt64 serializedBlockSize, PoolsInfo.PoolInfo poolInfo)
        {
            BigInteger.TryParse(blockHeader.ProofString, out var proof);
            var blockJson = new GetBlockByHashResponse();

            blockJson.hash              = Binary.ByteArrayToHexString(blockHeader.Hash);
            blockJson.size              = serializedBlockSize;
            blockJson.height            = blockHeight;
            blockJson.version           = blockHeader.Version;
            blockJson.merkleroot        = Binary.ByteArrayToHexString(blockHeader.Merkle);
            blockJson.tx                = BlockTxsToJSON(txHashes);
            blockJson.time              = blockHeader.Timestamp;
            blockJson.nonce             = blockHeader.Nonce;
            blockJson.bits              = Utils.EncodeInBase16(blockHeader.Bits);
            blockJson.difficulty        = Utils.BitsToDifficulty(blockHeader.Bits); //TODO Use bitprim API when implemented
            blockJson.chainwork         = (proof * 2).ToString("X64");              //TODO Does not match Blockdozer value; check how bitpay calculates it
            blockJson.confirmations     = currentHeight - blockHeight + 1;
            blockJson.previousblockhash = Binary.ByteArrayToHexString(blockHeader.PreviousBlockHash);
            if (nextBlockHash != null)
            {
                blockJson.nextblockhash = Binary.ByteArrayToHexString(nextBlockHash);
            }
            blockJson.reward      = blockReward;
            blockJson.isMainChain = true; //TODO Check value
            blockJson.poolInfo    = new PoolInfo {
                poolName = poolInfo.Name, url = poolInfo.Url
            };
            return(blockJson);
        }
コード例 #2
0
        private static GetBlockByHashResponse BlockToJSON(IHeader blockHeader, UInt64 blockHeight, INativeList <byte[]> txHashes,
                                                          decimal blockReward, UInt64 currentHeight, byte[] nextBlockHash,
                                                          UInt64 serializedBlockSize, PoolInfo poolInfo, bool includeTransactionIds)
        {
            BigInteger.TryParse(blockHeader.ProofString, out var proof);
            var blockJson = new GetBlockByHashResponse
            {
                hash    = Binary.ByteArrayToHexString(blockHeader.Hash),
                size    = serializedBlockSize,
                height  = blockHeight,
                version = blockHeader.Version,
                // We reverse this field to match the way bitpay-insight displays it
                merkleroot        = Binary.ByteArrayToHexString(blockHeader.Merkle, reverse: true),
                tx                = includeTransactionIds ? BlockTxsToJSON(txHashes) : new string[0],
                txCount           = txHashes.Count,
                time              = blockHeader.Timestamp,
                nonce             = blockHeader.Nonce,
                bits              = blockHeader.Bits,
                difficulty        = Utils.BitsToDifficulty(blockHeader.Bits),
                chainwork         = (proof * 2).ToString("X64"),
                confirmations     = currentHeight - blockHeight + 1,
                previousblockhash = Binary.ByteArrayToHexString(blockHeader.PreviousBlockHash)
            };

            //TODO Use bitprim API when implemented
            //TODO Does not match Blockdozer value; check how bitpay calculates it
            if (nextBlockHash != null)
            {
                blockJson.nextblockhash = Binary.ByteArrayToHexString(nextBlockHash);
            }
            blockJson.reward      = blockReward;
            blockJson.isMainChain = true; //TODO Check value
            blockJson.poolInfo    = new DTOs.PoolInfo {
                poolName = poolInfo.Name, url = poolInfo.Url
            };
            return(blockJson);
        }