using System; using System.Text; using System.Collections.Generic; namespace Novacoin { /// /// Transaction output. /// public class CTxOut { /// /// Input value. /// private ulong nValue; /// /// Second half of script which contains spending instructions. /// private byte[] scriptPubKey; /// /// Initialize new CTxOut instance as a copy of another instance. /// /// CTxOut instance. public CTxOut(CTxOut o) { nValue = o.nValue; scriptPubKey = o.scriptPubKey; } /// /// Parse input byte sequence and initialize new CTxOut instance. /// /// Byte sequence. public CTxOut(IList bytes) { WrappedList wBytes = new WrappedList(bytes); nValue = Interop.LEBytesToUInt64(wBytes.GetItems(8)); int spkLength = (int)VarInt.ReadVarInt(wBytes); scriptPubKey = wBytes.GetItems(spkLength); } /// /// Get raw bytes representation of our output. /// /// Byte sequence. public IList ToBytes() { List resultBytes = new List(); resultBytes.AddRange(Interop.LEBytes(nValue)); // txout value resultBytes.AddRange(VarInt.EncodeVarInt(scriptPubKey.LongLength)); // scriptPubKey length resultBytes.AddRange(scriptPubKey); // scriptPubKey return resultBytes; } public override string ToString () { StringBuilder sb = new StringBuilder (); sb.AppendFormat ("CTxOut(nValue={0},scriptPubKey={1}", nValue, scriptPubKey.ToString()); return sb.ToString (); } } }