Exemple #1
0
        /// <inheritdoc />
        public override bool Equals(StackItemBase other)
        {
            if (other is ByteArrayStackItemBase b)
            {
                return(b.Value.SequenceEqual(Value));
            }

            return(false);
        }
Exemple #2
0
        /// <inheritdoc />
        public override bool Equals(StackItemBase other)
        {
            if (other is IntegerStackItemBase b)
            {
                return(b.Value.Equals(Value));
            }

            return(false);
        }
        /// <inheritdoc />
        public override bool Equals(StackItemBase other)
        {
            if (other is BooleanStackItemBase b)
            {
                return(b.Value == Value);
            }

            return(false);
        }
Exemple #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="scriptHash">Script hash</param>
 /// <param name="state">State</param>
 public NotifyEventArgs(byte[] scriptHash, StackItemBase state)
 {
     ScriptHash = scriptHash;
     State      = state;
 }
Exemple #5
0
        public void Serialize(StackItemBase stackItem, BinaryWriter writer)
        {
            var serialized   = new List <StackItemBase>();
            var unserialized = new Stack <StackItemBase>();

            unserialized.Push(stackItem);

            while (unserialized.Count > 0)
            {
                stackItem = unserialized.Pop();

                switch (stackItem)
                {
                case ByteArrayStackItemBase _:
                {
                    writer.Write((byte)EStackItemType.ByteArray);
                    writer.WriteVarBytes(stackItem.ToByteArray());
                    break;
                }

                case BooleanStackItemBase b:
                {
                    writer.Write((byte)EStackItemType.Bool);
                    writer.Write(b.Value);
                    break;
                }

                case IntegerStackItemBase _:
                {
                    writer.Write((byte)EStackItemType.Integer);
                    writer.WriteVarBytes(stackItem.ToByteArray());
                    break;
                }

                case ArrayStackItemBase array:
                {
                    if (serialized.Any(p => ReferenceEquals(p, array)))
                    {
                        throw new NotSupportedException();
                    }

                    serialized.Add(array);

                    if (array.IsStruct)
                    {
                        writer.Write((byte)EStackItemType.Struct);
                    }
                    else
                    {
                        writer.Write((byte)EStackItemType.Array);
                    }

                    writer.WriteVarInt(array.Count);

                    for (var i = array.Count - 1; i >= 0; i--)
                    {
                        unserialized.Push(array[i]);
                    }

                    break;
                }

                case MapStackItemBase map:
                {
                    if (serialized.Any(p => ReferenceEquals(p, map)))
                    {
                        throw new NotSupportedException();
                    }

                    serialized.Add(map);
                    writer.Write((byte)EStackItemType.Map);
                    writer.WriteVarInt(map.Count);

                    foreach (var pair in map.Reverse())
                    {
                        unserialized.Push(pair.Value);
                        unserialized.Push(pair.Key);
                    }
                    break;
                }

                default: throw new NotSupportedException();
                }
            }
        }