Beispiel #1
0
 /// <summary>
 /// If scriptpubkey is already present, just add the value.
 /// </summary>
 public static void AddRangeWithOptimize(this TxOutList me, IEnumerable <TxOut> collection)
 {
     foreach (var txout in collection)
     {
         me.AddWithOptimize(txout);
     }
 }
Beispiel #2
0
        /// <summary>
        /// If scriptpubkey is already present, just add the value.
        /// </summary>
        public static void AddWithOptimize(this TxOutList me, Money money, Script scriptPubKey)
        {
            TxOut found = me.FirstOrDefault(x => x.ScriptPubKey == scriptPubKey);

            if (found != null)
            {
                found.Value += money;
            }
            else
            {
                me.Add(money, scriptPubKey);
            }
        }
        public static int GetIndex(this TxOutList me, Script script)
        {
            var index = -1;

            for (int i = 0; i < me.Count; i++)
            {
                var output = me[i];
                if (output.ScriptPubKey == script)
                {
                    index = i;
                }
            }

            if (index == -1)
            {
                throw new InvalidOperationException("Script not found.");
            }
            return(index);
        }
        public void ReadWrite(ref TxOutList list)
        {
            int listLen = 0;

            if (Serializing)
            {
                var len = list == null ? 0 : (ulong)list.Count;
                if (len > (uint)MaxArraySize)
                {
                    throw new ArgumentOutOfRangeException("Array size too big");
                }
                VarInt.StaticWrite(this, len);
                if (len == 0)
                {
                    return;
                }
                listLen = (int)len;
                foreach (var obj in list)
                {
                    ReadWrite(obj);
                }
            }
            else
            {
                var len = VarInt.StaticRead(this);
                if (len > (uint)MaxArraySize)
                {
                    throw new ArgumentOutOfRangeException("Array size too big");
                }
                listLen = (int)len;
                list    = new TxOutList(listLen);
                for (int i = 0; i < listLen; i++)
                {
                    TxOut obj = default;
                    ReadWrite(ref obj);
                    list.Add(obj);
                }
            }
        }
Beispiel #5
0
 public static IEnumerable <Coin> GetCoins(this TxOutList me, Script script)
 {
     return(me.AsCoins().Where(c => c.ScriptPubKey == script));
 }
Beispiel #6
0
 public Transaction()
 {
     vin  = new TxInList(this);
     vout = new TxOutList(this);
 }
Beispiel #7
0
 /// <summary>
 /// If scriptpubkey is already present, just add the value.
 /// </summary>
 public static void AddWithOptimize(this TxOutList me, TxOut txOut)
 {
     me.AddWithOptimize(txOut.Value, txOut.ScriptPubKey);
 }
Beispiel #8
0
 /// <summary>
 /// If scriptpubkey is already present, just add the value.
 /// </summary>
 public static void AddWithOptimize(this TxOutList me, Money money, IDestination destination)
 {
     me.AddWithOptimize(money, destination.ScriptPubKey);
 }
Beispiel #9
0
 private void Init()
 {
     vin  = new TxInList(this);
     vout = new TxOutList(this);
 }