/** * Used only in creation of the genesis block. */ TransactionInput(NetworkParameters params, Transaction parentTransaction, byte[] scriptBytes) { super(params); this.scriptBytes = scriptBytes; this.outpoint = new TransactionOutPoint(params, NO_SEQUENCE, (Transaction)null); this.sequence = NO_SEQUENCE; this.parentTransaction = parentTransaction; length = 40 + (scriptBytes == null ? 1 : VarInt.SizeInBytesOf(scriptBytes.Length) + scriptBytes.length); }
/** * Creates an UNSIGNED input that links to the given output */ TransactionInput(NetworkParameters params, Transaction parentTransaction, TransactionOutput output) { super(params); long outputIndex = output.getIndex(); outpoint = new TransactionOutPoint(params, outputIndex, output.parentTransaction); scriptBytes = EMPTY_ARRAY; sequence = NO_SEQUENCE; this.parentTransaction = parentTransaction; length = 41; }
public TransactionInput(NetworkParameters params, Transaction parentTransaction, byte[] scriptBytes, TransactionOutPoint outpoint) { super(params); this.scriptBytes = scriptBytes; this.outpoint = outpoint; this.sequence = NO_SEQUENCE; this.parentTransaction = parentTransaction; length = 40 + (scriptBytes == null ? 1 : VarInt.sizeOf(scriptBytes.length) + scriptBytes.length); }
public TransactionOutPoint(NetworkParameters params, long index, Transaction fromTx) { super(params); this.index = index; if (fromTx != null) { this.hash = fromTx.getHash(); this.fromTx = fromTx; } else { // This happens when constructing the genesis block. hash = Sha256Hash.ZERO_HASH; } length = MESSAGE_LENGTH; }
/// <summary> /// <exception cref="ProtocolException"/> /// </summary> private void parseTransactions() { if(transactionsParsed) { return; } Cursor=Offset+HeaderSize; optimalEncodingMessageSize=HeaderSize; if(Bytes.Length==Cursor) { // This message is just a header, it has no transactions. transactionsParsed=true; transactionBytesValid=false; return; } ulong numTransactions=ReadVarInt().Value; optimalEncodingMessageSize+=VarInt.SizeInBytesOf(numTransactions); Transactions=new List<Transaction>((int)numTransactions); for(ulong i=0;i<numTransactions;i++) { Transaction tx=new Transaction(Parameters,Bytes,Cursor,this,ParseLazy,ParseRetain,UnknownLength); Transactions.Add(tx); Cursor+=tx.MessageSize; optimalEncodingMessageSize+=tx.OptimalEncodingMessageSize; } // No need to set length here. If length was not provided then it should be set at the end of parseLight(). // If this is a genuine lazy parse then length must have been provided to the constructor. transactionsParsed=true; transactionBytesValid=ParseRetain; }
/// <summary> /// Adds a transaction to this block, with or without checking the sanity of doing so. /// <exception cref="VerificationException"></exception> /// </summary> /// <param name="transaction"></param> /// <param name="runSanityChecks"></param> public void addTransaction(Transaction transaction,bool runSanityChecks) { if(Transactions==null) { Transactions=new List<Transaction>(); } transaction.SetParent(this); if(runSanityChecks) { if(Transactions.Count==0 && !transaction.IsCoinBase) { throw new VerificationException("Attempted to add a non-coinbase transaction as the first transaction: "+t); } if(Transactions.Count>0 && transaction.IsCoinBase) { throw new VerificationException("Attempted to add a coinbase transaction when there already is one: "+t); } } Transactions.Add(transaction); AdjustLength(Transactions.Count,transaction.Length); // Force a recalculation next time the values are needed. MerkleRoot=null; hash=null; }
/// <summary> /// Adds a transaction to this block. The nonce and merkle root are invalid after this. /// </summary> /// <param name="transaction"></param> public void addTransaction(Transaction transaction) { addTransaction(transaction,false); }
public TransactionConfidence(Transaction transaction) { // Assume a default number of peers for our set. broadcastBy = new CopyOnWriteArrayList<PeerAddress>(); transaction = tx; }