private static Block CreateGenesis(NetworkParameters networkParameters) { var genesisBlock = new Block(networkParameters); var transaction = new Transaction(networkParameters); // A script containing the difficulty bits and the following message: // "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks" var bytes = Hex.Decode("04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73"); transaction.AddInput(new TransactionInput(networkParameters, transaction, bytes)); using (var scriptPubKeyBytes = new MemoryStream()) { Script.WriteBytes(scriptPubKeyBytes,Hex.Decode("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")); scriptPubKeyBytes.Write(Script.OpCheckSig); transaction.AddOutput(new TransactionOutput(networkParameters, transaction, scriptPubKeyBytes.ToArray())); } genesisBlock.AddTransaction(transaction); return genesisBlock; }
/// <summary> /// Returns a solved block that builds on top of this one. This exists for unit tests. /// </summary> internal Block CreateNextBlock(Address toAddress, uint time) { var block = new Block(NetworkParameters) {TargetDifficulty = _targetDifficulty}; block.AddCoinbaseTransaction(EmptyBytes); // Add a transaction paying 50 coins to the "to" address. var transaction = new Transaction(NetworkParameters); transaction.AddOutput(new TransactionOutput(NetworkParameters, transaction, Utils.ToNanoCoins(50, 0), toAddress)); // The input does not really need to be a valid signature, as long as it has the right general form. var input = new TransactionInput(NetworkParameters, transaction, Script.CreateInputScript(EmptyBytes, EmptyBytes)); // Importantly the outpoint hash cannot be zero as that's how we detect a coinbase transaction in isolation // but it must be unique to avoid 'different' transactions looking the same. var counter = new byte[32]; counter[0] = (byte) _transactionCounter++; input.Outpoint.Hash = new Sha256Hash(counter); transaction.AddInput(input); block.AddTransaction(transaction); block.PreviousBlockHash = Hash; block.TimeSeconds = time; block.Solve(); block.VerifyHeader(); return block; }