コード例 #1
0
		/**
		 * 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);
		}
コード例 #2
0
		/**
		 * 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;
		}
コード例 #3
0
		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);
		}
コード例 #4
0
		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;
		}
コード例 #5
0
ファイル: Block.cs プロジェクト: knocte/BitcoinDotNet
        /// <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;
        }
コード例 #6
0
ファイル: Block.cs プロジェクト: knocte/BitcoinDotNet
        /// <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;
        }
コード例 #7
0
ファイル: Block.cs プロジェクト: knocte/BitcoinDotNet
 /// <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);
 }
コード例 #8
0
		public TransactionConfidence(Transaction transaction)
		{
			// Assume a default number of peers for our set.
			broadcastBy = new CopyOnWriteArrayList<PeerAddress>();
			transaction = tx;
		}