Exemplo n.º 1
0
 public override Coins AccessCoins(uint256 txId)
 {
     if (_CurrentPrefetch == null)
     {
         return(_Inner.AccessCoins(txId));
     }
     return(_CurrentPrefetch.GetAwaiter().GetResult().AccessCoins(txId));
 }
Exemplo n.º 2
0
        private void CheckIntputs(Transaction tx, CoinView inputs, int nSpendHeight)
        {
            if (!inputs.HaveInputs(tx))
            {
                ConsensusErrors.BadTransactionMissingInput.Throw();
            }
            Money nValueIn = Money.Zero;
            Money nFees    = Money.Zero;

            for (int i = 0; i < tx.Inputs.Count; i++)
            {
                var prevout = tx.Inputs[i].PrevOut;
                var coins   = inputs.AccessCoins(prevout.Hash);

                // If prev is coinbase, check that it's matured
                if (coins.Coinbase)
                {
                    if (nSpendHeight - coins.Height < COINBASE_MATURITY)
                    {
                        ConsensusErrors.BadTransactionPrematureCoinbaseSpending.Throw();
                    }
                }

                // Check for negative or overflow input values
                nValueIn += coins.TryGetOutput(prevout.N).Value;
                if (!MoneyRange(coins.TryGetOutput(prevout.N).Value) || !MoneyRange(nValueIn))
                {
                    ConsensusErrors.BadTransactionInputValueOutOfRange.Throw();
                }
            }

            if (nValueIn < tx.TotalOut)
            {
                ConsensusErrors.BadTransactionInBelowOut.Throw();
            }

            // Tally transaction fees
            Money nTxFee = nValueIn - tx.TotalOut;

            if (nTxFee < 0)
            {
                ConsensusErrors.BadTransactionNegativeFee.Throw();
            }
            nFees += nTxFee;
            if (!MoneyRange(nFees))
            {
                ConsensusErrors.BadTransactionFeeOutOfRange.Throw();
            }
        }
Exemplo n.º 3
0
        public override Coins AccessCoins(uint256 txId)
        {
            if (_NotFound.Contains(txId))
            {
                PerformanceCounter.AddHitCount(1);
                return(null);
            }
            var cached = _Cache.AccessCoins(txId);

            if (cached != null)
            {
                PerformanceCounter.AddHitCount(1);
                return(cached);
            }
            PerformanceCounter.AddMissCount(1);
            var coin = _Inner.AccessCoins(txId);

            if (ReadThrough)
            {
                AddToCache(txId, coin);
            }
            return(coin);
        }