private void ValidateTransaction(TxWithPrevOutputs loadedTx) { try { var chainedHeader = loadedTx.ChainedHeader; var transaction = loadedTx.Transaction; var txIndex = loadedTx.TxIndex; var prevTxOutputs = loadedTx.PrevTxOutputs; this.rules.ValidateTransaction(chainedHeader, transaction, txIndex, prevTxOutputs); } catch (Exception e) { this.txValidatorExceptions.Add(e); } }
private TxWithPrevOutputs LoadPendingTx(TxWithPrevOutputKeys pendingTx, ConcurrentDictionary <UInt256, Transaction> txCache) { try { var txIndex = pendingTx.TxIndex; var transaction = pendingTx.Transaction; var chainedHeader = pendingTx.ChainedHeader; var spentTxes = pendingTx.PrevOutputTxKeys; var prevTxOutputs = ImmutableArray.CreateBuilder <TxOutput>(transaction.Inputs.Length); // load previous transactions for each input, unless this is a coinbase transaction if (txIndex > 0) { for (var inputIndex = 0; inputIndex < transaction.Inputs.Length; inputIndex++) { var input = transaction.Inputs[inputIndex]; Transaction cachedPrevTx; if (txCache.TryGetValue(input.PreviousTxOutputKey.TxHash, out cachedPrevTx)) { var prevTxOutput = cachedPrevTx.Outputs[input.PreviousTxOutputKey.TxOutputIndex.ToIntChecked()]; prevTxOutputs.Add(prevTxOutput); } else { var spentTx = spentTxes[inputIndex]; Transaction prevTx; if (this.coreStorage.TryGetTransaction(spentTx.BlockHash, spentTx.TxIndex, out prevTx)) { if (input.PreviousTxOutputKey.TxHash != prevTx.Hash) { throw new Exception("TODO"); } txCache.TryAdd(prevTx.Hash, prevTx); var prevTxOutput = prevTx.Outputs[input.PreviousTxOutputKey.TxOutputIndex.ToIntChecked()]; prevTxOutputs.Add(prevTxOutput); } else { throw new Exception("TODO"); } } } Debug.Assert(prevTxOutputs.Count == transaction.Inputs.Length); } var txWithPrevOutputs = new TxWithPrevOutputs(txIndex, transaction, chainedHeader, prevTxOutputs.ToImmutableArray()); return(txWithPrevOutputs); } catch (Exception e) { this.txLoaderExceptions.Add(e); //TODO return(null); } }