Exemple #1
0
        public static Block Load(byte[] hex, ConsensusFactory consensusFactory)
        {
            if (hex == null)
            {
                throw new ArgumentNullException(nameof(hex));
            }
            if (consensusFactory == null)
            {
                throw new ArgumentNullException(nameof(consensusFactory));
            }
            var block = consensusFactory.CreateBlock();

            block.ReadWrite(hex, consensusFactory);
            return(block);
        }
Exemple #2
0
        public static Block Parse(string hex, ConsensusFactory consensusFactory)
        {
            if (hex == null)
            {
                throw new ArgumentNullException(nameof(hex));
            }
            if (consensusFactory == null)
            {
                throw new ArgumentNullException(nameof(consensusFactory));
            }
            var block = consensusFactory.CreateBlock();

            block.ReadWrite(Encoders.Hex.DecodeData(hex), consensusFactory);
            return(block);
        }
Exemple #3
0
        public static Block CreateBlock(BlockHeader header, ConsensusFactory consensusFactory)
        {
            var           ms = new MemoryStream(100);
            BitcoinStream bs = new BitcoinStream(ms, true);

            bs.ConsensusFactory = consensusFactory;
            bs.ReadWrite(header);

            var block = consensusFactory.CreateBlock();

            ms.Position = 0;
            bs          = new BitcoinStream(ms, false);
            block.Header.ReadWrite(bs);
            return(block);
        }
Exemple #4
0
        public Block CreateNextBlockWithCoinbase(PubKey pubkey, Money value, DateTimeOffset now, ConsensusFactory consensusFactory)
        {
            Block block = consensusFactory.CreateBlock();

            block.Header.Nonce         = RandomUtils.GetUInt32();
            block.Header.HashPrevBlock = this.GetHash();
            block.Header.BlockTime     = now;
            var tx = block.AddTransaction(consensusFactory.CreateTransaction());

            tx.Inputs.Add(scriptSig: new Script(Op.GetPushOp(RandomUtils.GetBytes(30))));
            tx.Outputs.Add(new TxOut()
            {
                Value        = value,
                ScriptPubKey = PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(pubkey)
            });
            return(block);
        }
Exemple #5
0
 public static Block CreateBlock(ConsensusFactory consensusFactory)
 {
     return(consensusFactory.CreateBlock());
 }