Esempio n. 1
0
        public static Block ToBlock(RPCBlock rpcBlock)
        {
            var header = new BlockHeader()
            {
                Time = rpcBlock.time,
                //BlockStake = new BlockStake
                //{
                //	HashProof = uint256.Parse( rpcBlock.proofhash),
                //	Mint = rpcBlock.mint,
                //	StakeModifierV2 = uint256.Parse(rpcBlock.modifierv2)
                //},
                HashMerkleRoot = uint256.Parse(rpcBlock.merkleroot),
                Bits           = new Target(Encoders.Hex.DecodeData(rpcBlock.bits)),
                HashPrevBlock  = uint256.Parse(rpcBlock.previousblockhash),
                Nonce          = rpcBlock.nonce,
                Version        = rpcBlock.version,
            };

            var block = new Block(header);

            if (!string.IsNullOrEmpty(rpcBlock.signature))
            {
                block.BlockSignatur.Signature = Encoders.Hex.DecodeData(rpcBlock.signature);
            }

            // todo: parse transactions
            block.Transactions = rpcBlock.tx.Select(t => new Transaction()).ToList();

            return(block);
        }
        public static Block ToBlock(RPCBlock rpcBlock, ConsensusFactory consensusFactory)
        {
            Block block = consensusFactory.CreateBlock();

            block.Header.Time = rpcBlock.time;
            //BlockStake = new BlockStake
            //{
            //    HashProof = uint256.Parse( rpcBlock.proofhash),
            //    Mint = rpcBlock.mint,
            //    StakeModifierV2 = uint256.Parse(rpcBlock.modifierv2)
            //},
            block.Header.HashMerkleRoot = uint256.Parse(rpcBlock.merkleroot);
            block.Header.Bits           = new Target(Encoders.Hex.DecodeData(rpcBlock.bits));
            block.Header.HashPrevBlock  = uint256.Parse(rpcBlock.previousblockhash);
            block.Header.Nonce          = rpcBlock.nonce;
            block.Header.Version        = rpcBlock.version;

            if (!string.IsNullOrEmpty(rpcBlock.signature))
            {
                var posBlock = block as PosBlock;
                if (posBlock == null)
                {
                    throw new Exception();
                }

                posBlock.BlockSignature.Signature = Encoders.Hex.DecodeData(rpcBlock.signature);
            }

            // todo: parse transactions
            block.Transactions = rpcBlock.tx.Select(t => new Transaction()).ToList();

            return(block);
        }