BitSharper.Block.AddCoinbaseTransaction C# (CSharp) Method

AddCoinbaseTransaction() private method

Adds a coinbase transaction to the block. This exists for unit tests.
private AddCoinbaseTransaction ( byte pubKeyTo ) : void
pubKeyTo byte
return void
        internal void AddCoinbaseTransaction(byte[] pubKeyTo)
        {
            Transactions = new List<Transaction>();
            var coinbase = new Transaction(Params);
            // A real coinbase transaction has some stuff in the scriptSig like the extraNonce and difficulty. The
            // transactions are distinguished by every TX output going to a different key.
            //
            // Here we will do things a bit differently so a new address isn't needed every time. We'll put a simple
            // counter in the scriptSig so every transaction has a different hash.
            coinbase.AddInput(new TransactionInput(Params, coinbase, new[] {(byte) _txCounter++}));
            coinbase.AddOutput(new TransactionOutput(Params, coinbase, Script.CreateOutputScript(pubKeyTo)));
            Transactions.Add(coinbase);
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Returns a solved block that builds on top of this one. This exists for unit tests.
        /// </summary>
        internal Block CreateNextBlock(Address to, uint time)
        {
            var b = new Block(Params);

            b.DifficultyTarget = _difficultyTarget;
            b.AddCoinbaseTransaction(_emptyBytes);

            // Add a transaction paying 50 coins to the "to" address.
            var t = new Transaction(Params);

            t.AddOutput(new TransactionOutput(Params, t, Utils.ToNanoCoins(50, 0), to));
            // The input does not really need to be a valid signature, as long as it has the right general form.
            var input = new TransactionInput(Params, t, 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)_txCounter++;
            input.Outpoint.Hash = new Sha256Hash(counter);
            t.AddInput(input);
            b.AddTransaction(t);

            b.PrevBlockHash = Hash;
            b.TimeSeconds   = time;
            b.Solve();
            b.VerifyHeader();
            return(b);
        }
All Usage Examples Of BitSharper.Block::AddCoinbaseTransaction