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); }
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); }
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); }
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); }
public static Block CreateBlock(ConsensusFactory consensusFactory) { return(consensusFactory.CreateBlock()); }