using System; using System.Text; using System.Collections.Generic; namespace Novacoin { /// /// Transaction output. /// public class CTxOut { /// /// Input value. /// public ulong nValue; /// /// Second half of script which contains spending instructions. /// public byte[] scriptPubKey; /// /// Initialize new CTxOut instance as a copy of another instance. /// /// CTxOut instance. public CTxOut(CTxOut o) { nValue = o.nValue; scriptPubKey = o.scriptPubKey; } /// /// Initialize an empty instance of CTxOut class /// public CTxOut() { } /// /// Read vout list from byte sequence. /// /// Reference to byte sequence /// Outputs array public static CTxOut[] ReadTxOutList(ref WrappedList wBytes) { int nOutputs = (int)VarInt.ReadVarInt(ref wBytes); CTxOut[] vout =new CTxOut[nOutputs]; for (int nIndex = 0; nIndex < nOutputs; nIndex++) { // Fill outputs array vout[nIndex] = new CTxOut(); vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.GetItems(8), 0); vout[nIndex].scriptPubKey = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)); } return vout; } /// /// Get raw bytes representation of our output. /// /// Byte sequence. public IList Bytes { get { List resultBytes = new List(); resultBytes.AddRange(BitConverter.GetBytes(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, (new CScript(scriptPubKey)).ToString()); return sb.ToString (); } } }