public void AddInput(TXInput input) { if ( !TableUInt32.TrySpend(input) && !TableULong64.TrySpend(input) && !TableUInt32Array.TrySpend(input)) { Inputs.Add(input); } }
public bool TrySpend(TXInput tXInput) { TXOutputWallet output = TXOutputsSpendable.Find(o => o.TXIDShort == tXInput.TXIDOutputShort && o.OutputIndex == tXInput.OutputIndex); if (output == null || !output.TXID.IsEqual(tXInput.TXIDOutput)) { return(false); } TXOutputsSpendable.Remove(output); Console.WriteLine( "Spent output {0} in tx {1} with {2} satoshis.", output.OutputIndex, output.TXID.ToHexString(), output.Value); return(true); }
byte[] ParseTX(bool isCoinbase) { try { int tXStartIndex = BufferIndex; BufferIndex += BYTE_LENGTH_VERSION; bool isWitnessFlagPresent = Buffer[BufferIndex] == 0x00; if (isWitnessFlagPresent) { throw new NotImplementedException("Parsing of segwit txs not implemented"); //BufferIndex += 2; } int countInputs = VarInt.GetInt32(Buffer, ref BufferIndex); if (isCoinbase) { new TXInput(Buffer, ref BufferIndex); } else { for (int i = 0; i < countInputs; i += 1) { TXInput input = new TXInput(Buffer, ref BufferIndex); AddInput(input); } } int countTXOutputs = VarInt.GetInt32(Buffer, ref BufferIndex); for (int i = 0; i < countTXOutputs; i += 1) { BufferIndex += BYTE_LENGTH_OUTPUT_VALUE; int lengthLockingScript = VarInt.GetInt32(Buffer, ref BufferIndex); BufferIndex += lengthLockingScript; } //if (isWitnessFlagPresent) //{ //var witnesses = new TXWitness[countInputs]; //for (int i = 0; i < countInputs; i += 1) //{ // witnesses[i] = TXWitness.Parse(Buffer, ref BufferIndex); //} //} BufferIndex += BYTE_LENGTH_LOCK_TIME; int tXLength = BufferIndex - tXStartIndex; byte[] tXHash = SHA256.ComputeHash( SHA256.ComputeHash( Buffer, tXStartIndex, tXLength)); AddOutput( tXHash, countTXOutputs); return(tXHash); } catch (ArgumentOutOfRangeException) { throw new ChainException(); } }