Esempio n. 1
0
        /// <summary>
        /// Creates a coinbase transaction and adds it the block.
        /// </summary>
        /// <returns>The created coinbase transaction.</returns>
        /// <remarks>
        /// Since coinbase transaction must be the first transaction in a block,
        /// this method will throw an exception if the block already contains more than 0 transactions.
        /// </remarks>
        public Transaction AddCoinbaseTx(string address, long feeInNekoshi)
        {
            if (Transactions.Count > 0)
            {
                throw new System.InvalidOperationException("Coinbase must be the first transaction.");
            }

            long reward = Config.CalculateRewardInNekoshi(Index);
            var  txIn   = new TxIn
            {
                TxId       = HexUtils.HexFromInt(Index),
                TxOutIndex = 0,
                Signature  = "",
            };
            var txOut = new TxOut
            {
                AmountInNekoshi = reward + feeInNekoshi,
                Address         = address,
            };
            var tx = new Transaction();

            tx.Inputs.Add(txIn);
            tx.Outputs.Add(txOut);
            tx.Id = tx.GetId();
            Transactions.Add(tx);
            return(tx);
        }
Esempio n. 2
0
 /// <summary>
 /// Returns true if the given TxI is a valid coinbase TxI of the given block.
 /// </summary>
 public static bool IsValidCoinbaseTxIn(Block block, TxIn txIn)
 {
     return(txIn.TxId == HexUtils.HexFromInt(block.Index) &&
            txIn.TxOutIndex == 0 &&
            txIn.Signature == "");
 }