Exemplo n.º 1
0
 /// <summary>
 /// Sets this objects availableToSpend flag to false and the spentBy pointer to the given input.
 /// If the input is null, it means this output was signed over to somebody else rather than one of our own keys.
 /// </summary>
 public void MarkAsSpent(TransactionInput input)
 {
     Debug.Assert(_availableForSpending);
     _availableForSpending = false;
     SpentBy = input;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Adds an input directly, with no checking that it's valid.
 /// </summary>
 public void AddInput(TransactionInput transactionInput)
 {
     _transactionInputs.Add(transactionInput);
 }
Exemplo n.º 3
0
 /// <exception cref="ProtocolException"/>
 protected override void Parse()
 {
     _version = ReadUint32();
     // First come the inputs.
     var numInputs = ReadVarInt();
     _transactionInputs = new List<TransactionInput>((int) numInputs);
     for (var i = 0UL; i < numInputs; i++)
     {
         var input = new TransactionInput(this.NetworkParameters, this, Bytes, Cursor);
         _transactionInputs.Add(input);
         Cursor += input.MessageSize;
     }
     // Now the outputs
     var numOutputs = ReadVarInt();
     _transactionOutputs = new List<TransactionOutput>((int) numOutputs);
     for (var i = 0UL; i < numOutputs; i++)
     {
         var output = new TransactionOutput(this.NetworkParameters, this, Bytes, Cursor);
         _transactionOutputs.Add(output);
         Cursor += output.MessageSize;
     }
     _lockTime = ReadUint32();
 }
Exemplo n.º 4
0
        /// <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;
        }