Example #1
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 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);
                }
            }
        }