public static UnspentOutput Create(StoredBlock block, Tx transaction, int outputNumber)
        {
            TxOut output = transaction.Outputs[outputNumber];

            return new UnspentOutput(
                block.Height,
                CryptoUtils.DoubleSha256(BitcoinStreamWriter.GetBytes(transaction.Write)),
                outputNumber,
                output.Value,
                output.PubkeyScript);
        }
 private static bool IsValidCoinbaseTransaction(Tx transaction)
 {
     if (transaction.Inputs.Length != 1)
     {
         return false;
     }
     TxIn input = transaction.Inputs[0];
     if (input.PreviousOutput.Hash.Any(b => b != 0) || input.PreviousOutput.Index != -1)
     {
         return false;
     }
     if (input.SignatureScript == null)
     {
         return false;
     }
     //todo: use network settings?
     return input.SignatureScript.Length >= 2 && input.SignatureScript.Length <= 100;
 }
        /// <summary>
        /// Calculates hash of Merkle tree root for a given array of transactions.
        /// </summary>
        /// <param name="transactions">The array of transactions.</param>
        /// <exception cref="ArgumentException">If the array of transactions is null or empty.</exception>
        public static byte[] GetTreeRoot(Tx[] transactions)
        {
            if (transactions == null || transactions.Length == 0)
            {
                throw new ArgumentException($"{nameof(transactions)} array is null or empty.");
            }

            if (transactions == null || transactions.Length == 0)
            {
                throw new ArgumentException($"{nameof(transactions)} array is null or empty.");
            }

            List<byte[]> hashes = new List<byte[]>(transactions.Length);
            foreach (Tx transaction in transactions)
            {
                hashes.Add(CryptoUtils.DoubleSha256(BitcoinStreamWriter.GetBytes(transaction.Write)));
            }

            return GetTreeRoot(hashes);
        }
 public BlockMessage(BlockHeader blockHeader, Tx[] transactions)
 {
     this.blockHeader = blockHeader;
     this.transactions = transactions;
 }
 public void Reset()
 {
     dataStack.Clear();
     altDataStack.Clear();
     controlStack.Clear();
     valid = true;
     transaction = default(Tx);
     transactionInputNumber = 0;
     lastCodeSeparator = -1;
 }
Esempio n. 6
0
 public TxMessage(Tx transaction)
 {
     this.transaction = transaction;
 }