private static LoadedTx LoadTxInput(ICoreStorage coreStorage, ConcurrentDictionary <TxLookupKey, Lazy <BlockTx> > txCache, LoadingTx loadingTx, int inputIndex)
{
var txIndex = loadingTx.TxIndex;
var transaction = loadingTx.Transaction;
var chainedHeader = loadingTx.ChainedHeader;
// load previous transaction for this input, unless this is a coinbase transaction
if (!loadingTx.IsCoinbase)
{
var prevOutputTxKey = loadingTx.PrevOutputTxKeys[inputIndex];
var input = transaction.Inputs[inputIndex];
var inputPrevTxHash = input.PrevTxOutputKey.TxHash;
var inputPrevTx = txCache.GetOrAdd(prevOutputTxKey, new Lazy <BlockTx>(() =>
{
BlockTx tx;
if (coreStorage.TryGetTransaction(prevOutputTxKey.BlockHash, prevOutputTxKey.TxIndex, out tx))
{
return(tx);
}
else
{
throw new MissingDataException(prevOutputTxKey.BlockHash);
}
})).Value;
if (input.PrevTxOutputKey.TxHash != inputPrevTx.Hash)
{
throw new Exception("TODO");
}
if (loadingTx.InputTxes.TryComplete(inputIndex, inputPrevTx.Decode().DecodedTx))
{
return(loadingTx.ToLoadedTx());
}
else
{
return(null);
}
}
else
{
Debug.Assert(inputIndex == -1);
return(new LoadedTx(transaction, txIndex, ImmutableArray.Create <DecodedTx>()));
}
}