void ISerializable.Deserialize(BinaryReader reader)
 {
     Usage = (TransactionAttributeUsage)reader.ReadByte();
     if (Usage == TransactionAttributeUsage.ContractHash ||
         Usage == TransactionAttributeUsage.Vote ||
         (Usage >= TransactionAttributeUsage.Hash1 && Usage <= TransactionAttributeUsage.Hash15))
     {
         Data = reader.ReadBytes(32);
     }
     else if (Usage == TransactionAttributeUsage.ECDH02 || Usage == TransactionAttributeUsage.ECDH03)
     {
         Data = new[] { (byte)Usage }.Concat(reader.ReadBytes(32)).ToArray();
     }
     else if (Usage == TransactionAttributeUsage.Script)
     {
         Data = reader.ReadBytes(20);
     }
     else if (Usage == TransactionAttributeUsage.DescriptionUrl)
     {
         Data = reader.ReadBytes(reader.ReadByte());
     }
     else if (Usage == TransactionAttributeUsage.Description || Usage >= TransactionAttributeUsage.Remark)
     {
         Data = reader.ReadVarBytes(ushort.MaxValue);
     }
     else
     {
         throw new FormatException();
     }
 }
示例#2
0
 public bool IsValidAttributeType(TransactionAttributeUsage usage)
 {
     return(usage == TransactionAttributeUsage.Nonce ||
            usage == TransactionAttributeUsage.Script ||
            usage == TransactionAttributeUsage.Description ||
            usage == TransactionAttributeUsage.DescriptionUrl);
 }
示例#3
0
 void ISerializable.Deserialize(BinaryReader reader)
 {
     this.Usage = (TransactionAttributeUsage)reader.ReadByte();
     if (!Enum.IsDefined(typeof(TransactionAttributeUsage), Usage))
         throw new FormatException();
     int length;
     switch (Usage)
     {
         case TransactionAttributeUsage.ContractHash:
         case TransactionAttributeUsage.ECDH02:
         case TransactionAttributeUsage.ECDH03:
             length = 32;
             break;
         case TransactionAttributeUsage.LockAfter:
         case TransactionAttributeUsage.LockBefore:
             length = 4;
             break;
         default:
             if (Usage >= TransactionAttributeUsage.Remark)
                 length = reader.ReadByte();
             else
                 throw new FormatException();
             break;
     }
     this.Data = reader.ReadBytes(length);
 }
示例#4
0
        void ISerializable.Deserialize(BinaryReader reader)
        {
            this.Usage = (TransactionAttributeUsage)reader.ReadByte();
            if (!Enum.IsDefined(typeof(TransactionAttributeUsage), Usage))
            {
                throw new FormatException();
            }
            int length;

            switch (Usage)
            {
            case TransactionAttributeUsage.ContractHash:
            case TransactionAttributeUsage.ECDH02:
            case TransactionAttributeUsage.ECDH03:
                length = 32;
                break;

            case TransactionAttributeUsage.LockAfter:
            case TransactionAttributeUsage.LockBefore:
                length = 4;
                break;

            default:
                if (Usage >= TransactionAttributeUsage.Remark)
                {
                    length = reader.ReadByte();
                }
                else
                {
                    throw new FormatException();
                }
                break;
            }
            this.Data = reader.ReadBytes(length);
        }
示例#5
0
 public void Size_Get_Hash()
 {
     for (TransactionAttributeUsage i = TransactionAttributeUsage.Hash1; i <= TransactionAttributeUsage.Hash15; i++)
     {
         uut.Usage = i;
         uut.Size.Should().Be(33); // 1 + 32
     }
 }
示例#6
0
 void ISerializable.Deserialize(BinaryReader reader)
 {
     Usage = (TransactionAttributeUsage)reader.ReadByte();
     if (!Enum.IsDefined(typeof(TransactionAttributeUsage), Usage))
     {
         throw new FormatException();
     }
     Data = reader.ReadVarBytes(252);
 }
示例#7
0
        private byte[] GetAttributeByUsage(TransactionState tx, TransactionAttributeUsage u)
        {
            var v = tx.Transaction.Attributes.Where(x => x.Usage == u).FirstOrDefault();

            if (v == null)
            {
                return(null);
            }
            return(v.Data);
        }
示例#8
0
 void ISerializable.Deserialize(BinaryReader reader)
 {
     Usage = (TransactionAttributeUsage)reader.ReadByte();
     if (Usage == TransactionAttributeUsage.ContractHash || Usage == TransactionAttributeUsage.Vote || (Usage >= TransactionAttributeUsage.Hash1 && Usage <= TransactionAttributeUsage.Hash15))
     {
         Data = reader.ReadBytes(32);
     }
     else if (Usage == TransactionAttributeUsage.ECDH02 || Usage == TransactionAttributeUsage.ECDH03)
     {
         Data = new[] { (byte)Usage }
     }
示例#9
0
 public static bool IsContainAttributeUsage(this Transaction tx, TransactionAttributeUsage usage)
 {
     if (tx.Attributes == default || tx.Attributes.Length == 0)
     {
         return(false);
     }
     foreach (var attr in tx.Attributes)
     {
         if (attr.Usage == usage)
         {
             return(true);
         }
     }
     return(false);
 }
示例#10
0
 void ISerializable.Deserialize(BinaryReader reader)
 {
     Usage = (TransactionAttributeUsage)reader.ReadByte();
     if (Usage == TransactionAttributeUsage.Cosigner)
     {
         Data = reader.ReadBytes(20);
     }
     else if (Usage == TransactionAttributeUsage.Url)
     {
         Data = reader.ReadVarBytes(252);
     }
     else
     {
         throw new FormatException();
     }
 }
示例#11
0
        void ISerializable.Deserialize(BinaryReader reader)
        {
            Usage = (TransactionAttributeUsage)reader.ReadByte();
            int length;

            switch (Usage)
            {
            case TransactionAttributeUsage.ContractHash:
            case TransactionAttributeUsage.ECDH02:
            case TransactionAttributeUsage.ECDH03:
                length = 32;
                break;

            case TransactionAttributeUsage.Remark:
            case TransactionAttributeUsage.Script:
                length = reader.ReadByte();
                break;

            default:
                throw new FormatException();
            }
            Data = reader.ReadBytes(length);
        }
示例#12
0
 public TransactionAttribute(TransactionAttributeUsage usage, byte[] data)
 {
     Usage = usage;
     Data  = data;
 }