public override IEnumerable <byte> Serialize() { // https://bitcoin.org/en/developer-reference#raw-transaction-format var result = new List <byte>(); result.AddRange(BitConverter.GetBytes(Version)); result.Add((byte)TransactionCategories.Monetary); result.Add((byte)TransactionType); var inputCompactSize = new CompactSize(); inputCompactSize.Size = (ulong)TransactionIn.Count(); result.AddRange(inputCompactSize.Serialize()); foreach (var input in TransactionIn) { result.AddRange(input.Serialize()); } var outputCompactSize = new CompactSize(); outputCompactSize.Size = (ulong)TransactionOut.Count(); result.AddRange(outputCompactSize.Serialize()); foreach (var output in TransactionOut) { result.AddRange(output.Serialize()); } result.AddRange(BitConverter.GetBytes(LockTime)); return(result); }
public IEnumerable <TransactionOut> GetReferencedTransactionOut(NoneCoinbaseTransaction transaction) { if (transaction == null) { throw new ArgumentNullException(nameof(transaction)); } var trIns = transaction.TransactionIn.Select(ti => ti as TransactionInNoneCoinbase); var result = new List <TransactionOut>(); foreach (var trIn in trIns) { if (!GetTxId().SequenceEqual(trIn.Outpoint.Hash)) { continue; } if (trIn.Outpoint.Index >= TransactionOut.Count()) { continue; } result.Add(TransactionOut.ElementAt((int)trIn.Outpoint.Index)); } return(result); }
public TransactionOut GetTransactionOut(WalletAggregateAddress walletAddr) { if (walletAddr == null) { throw new ArgumentNullException(nameof(walletAddr)); } if (walletAddr.Key == null) { throw new ArgumentNullException(nameof(walletAddr.Key)); } if (TransactionOut == null || !TransactionOut.Any()) { return(null); } var interpreter = new ScriptInterpreter(); var scriptBuilder = new ScriptBuilder(); var secondScript = scriptBuilder.New() .AddToStack(walletAddr.Key.GetSignature()) .AddToStack(walletAddr.Key.GetPublicKey()) .Build(); foreach (var transactionOut in TransactionOut) { if (interpreter.Check(transactionOut.Script, secondScript)) { return(transactionOut); } } return(null); }