public static TransactionIn Parse(byte[] buffer, ref int index) { var res = new TransactionIn(); res.PreviousOutput = OutPoint.Parse(buffer, ref index); var script_length = Helper.ReadVariableUInt(buffer, ref index); res.Script = SignatureScript.Parse(buffer, ref index, (int)script_length); // see http://bitcoin.stackexchange.com/questions/2025/what-is-txins-sequence // Transaction version as defined by the sender. Intended for "replacement" of transactions when information is updated before inclusion into a block. res.Sequence = ((uint)buffer[index++] << 0) | ((uint)buffer[index++] << 8) | ((uint)buffer[index++] << 16) | ((uint)buffer[index++] << 24); return(res); }
public static Transaction Parse(byte[] buffer, ref int index) { var res = new Transaction(); var start_index = index; res.Version = ((int)buffer[index++] << 0) | ((int)buffer[index++] << 8) | ((int)buffer[index++] << 16) | ((int)buffer[index++] << 24); var transactionCount = Helper.ReadVariableUInt(buffer, ref index); res.Ins = new TransactionIn[transactionCount]; for (ulong i = 0; i < transactionCount; i++) { res.Ins[i] = TransactionIn.Parse(buffer, ref index); } transactionCount = Helper.ReadVariableUInt(buffer, ref index); res.Outs = new TransactionOut[transactionCount]; for (ulong i = 0; i < transactionCount; i++) { res.Outs[i] = TransactionOut.Parse(buffer, ref index); } // the doc makes special mention of this: // "If all TxIn inputs have final (0xffffffff) sequence numbers then lock_time is irrelevant. Otherwise, the transaction may not be added to a block until after lock_time (see NLockTime)." // as such, this might hide data under those context var is_lock_time_irrelevant = res.Ins.All(o => o.Sequence == 0xFFFFFFFF); res.LockTime = LockTime.Parse(buffer, ref index, is_lock_time_irrelevant); res.TransactionHash = Helper.SHA256_2(buffer, start_index, index - start_index); return(res); }