Ejemplo n.º 1
0
 /// <summary>
 /// 反序列化交易中额外的数据
 /// </summary>
 /// <param name="reader">数据来源</param>
 protected override void DeserializeExclusiveData(BinaryReader reader)
 {
     AssetType = (AssetType)reader.ReadByte();
     if (!Enum.IsDefined(typeof(AssetType), AssetType) || AssetType == AssetType.CreditFlag || AssetType == AssetType.DutyFlag)
     {
         throw new FormatException();
     }
     Name   = reader.ReadVarString();
     Amount = reader.ReadSerializable <Fixed8>();
     if (Amount == Fixed8.Zero || Amount < -Fixed8.Satoshi)
     {
         throw new FormatException();
     }
     if (AssetType == AssetType.Share && Amount <= Fixed8.Zero)
     {
         throw new FormatException();
     }
     if (AssetType == AssetType.Invoice && Amount != -Fixed8.Satoshi)
     {
         throw new FormatException();
     }
     Precision = reader.ReadByte();
     if (Precision > 8)
     {
         throw new FormatException();
     }
     Issuer = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     Admin  = reader.ReadSerializable <UInt160>();
 }
Ejemplo n.º 2
0
        public override void Deserialize(BinaryReader reader)
        {
            byte version = reader.ReadByte();

            if (version > StateVersion)
            {
                throw new FormatException();
            }

            Hash         = reader.ReadSerializable <UInt160>();
            Name         = reader.ReadVarString();
            Owner        = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
            Type         = (AppChainType)reader.ReadByte();
            Timestamp    = reader.ReadUInt32();
            LastModified = version >= 1 ? reader.ReadUInt32() : Timestamp;
            SeedList     = new string[reader.ReadVarInt()];
            for (int i = 0; i < SeedList.Length; i++)
            {
                SeedList[i] = reader.ReadVarString();
            }
            StandbyValidators = new ECPoint[reader.ReadVarInt()];
            for (int i = 0; i < StandbyValidators.Length; i++)
            {
                StandbyValidators[i] = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
            }
        }
Ejemplo n.º 3
0
 public override void Deserialize(BinaryReader reader)
 {
     base.Deserialize(reader);
     PublicKey  = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     Registered = reader.ReadBoolean();
     Votes      = reader.ReadSerializable <Fixed8>();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 序列化交易中的额外数据
 /// </summary>
 /// <param name="reader">数据来源</param>
 protected override void DeserializeExclusiveData(BinaryReader reader)
 {
     if (Version != 0)
     {
         throw new FormatException();
     }
     PublicKey = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
 }
Ejemplo n.º 5
0
 void ISerializable.Deserialize(BinaryReader reader)
 {
     if (reader.ReadByte() != StateVersion)
     {
         throw new FormatException();
     }
     PublicKey = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 反序列化交易中额外的数据
 /// </summary>
 /// <param name="reader">数据来源</param>
 protected override void DeserializeExclusiveData(BinaryReader reader)
 {
     AssetType = (AssetType)reader.ReadByte();
     Name      = reader.ReadVarString(1024);
     Amount    = reader.ReadSerializable <Fixed8>();
     Precision = reader.ReadByte();
     Issuer    = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     Admin     = reader.ReadSerializable <UInt160>();
 }
Ejemplo n.º 7
0
 public override void Deserialize(BinaryReader reader)
 {
     this.m          = (int)reader.ReadVarInt();
     this.publicKeys = new ECPoint[reader.ReadVarInt()];
     for (int i = 0; i < publicKeys.Length; i++)
     {
         publicKeys[i] = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     }
     base.RedeemScript  = CreateMultiSigRedeemScript(m, publicKeys);
     base.PublicKeyHash = reader.ReadSerializable <UInt160>();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 反序列化交易中额外的数据
 /// </summary>
 /// <param name="reader">数据来源</param>
 protected override void DeserializeExclusiveData(BinaryReader reader)
 {
     AssetType = (AssetType)reader.ReadByte();
     Name      = reader.ReadVarString(1024);
     Amount    = reader.ReadSerializable <Fixed8>();
     Precision = reader.ReadByte();
     Owner     = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     if (Owner.IsInfinity && AssetType != AssetType.SystemShare && AssetType != AssetType.SystemCoin)
     {
         throw new FormatException();
     }
     Admin = reader.ReadSerializable <UInt160>();
 }
Ejemplo n.º 9
0
        void ISignable.DeserializeUnsigned(BinaryReader reader)
        {
            PrevHash = reader.ReadSerializable <UInt256>();
            Miner    = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
            NoncePieces.Clear();
            int count = (int)reader.ReadVarInt();

            for (int i = 0; i < count; i++)
            {
                ECPoint key   = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
                byte[]  value = reader.ReadBytes((int)reader.ReadVarInt());
                NoncePieces.Add(key, value);
            }
            MerkleRoot = reader.ReadSerializable <UInt256>();
        }
Ejemplo n.º 10
0
        public static AssetRegistration Unserialize(BinaryReader reader)
        {
            var reg = new AssetRegistration();

            reg.type      = (AssetType)reader.ReadByte();
            reg.name      = reader.ReadVarString();
            reg.amount    = reader.ReadFixed();
            reg.precision = reader.ReadByte();
            reg.owner     = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
            if (reg.owner.IsInfinity && reg.type != AssetType.GoverningToken && reg.type != AssetType.UtilityToken)
            {
                throw new FormatException();
            }
            reg.admin = new UInt160(reader.ReadBytes(20));
            return(reg);
        }
Ejemplo n.º 11
0
        public override void Deserialize(BinaryReader reader)
        {
            byte version = reader.ReadByte();

            if (version > StateVersion)
            {
                throw new FormatException();
            }
            AssetId     = reader.ReadSerializable <UInt160>();
            Name        = reader.ReadVarString();
            Symbol      = reader.ReadVarString();
            TotalSupply = reader.ReadSerializable <Fixed8>();
            Decimals    = reader.ReadByte();
            Owner       = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
            Admin       = reader.ReadSerializable <UInt160>();
            BlockIndex  = reader.ReadUInt32();
            IsFrozen    = reader.ReadBoolean();
        }
Ejemplo n.º 12
0
 public override void Deserialize(BinaryReader reader)
 {
     base.Deserialize(reader);
     AssetId   = reader.ReadSerializable <UInt256>();
     AssetType = (AssetType)reader.ReadByte();
     Name      = reader.ReadVarString();
     Amount    = reader.ReadSerializable <Fixed8>();
     Available = reader.ReadSerializable <Fixed8>();
     Precision = reader.ReadByte();
     reader.ReadByte();                               //FeeMode
     Fee        = reader.ReadSerializable <Fixed8>(); //Fee
     FeeAddress = reader.ReadSerializable <UInt160>();
     Owner      = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     Admin      = reader.ReadSerializable <UInt160>();
     Issuer     = reader.ReadSerializable <UInt160>();
     Expiration = reader.ReadUInt32();
     IsFrozen   = reader.ReadBoolean();
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 反序列化交易中额外的数据
 /// </summary>
 /// <param name="reader">数据来源</param>
 protected override void DeserializeExclusiveData(BinaryReader reader)
 {
     TR.Enter();
     if (Version != 0)
     {
         throw new FormatException();
     }
     AssetType = (AssetType)reader.ReadByte();
     Name      = reader.ReadVarString(1024);
     Amount    = reader.ReadSerializable <Fixed8>();
     Precision = reader.ReadByte();
     Owner     = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     if (Owner.IsInfinity && AssetType != AssetType.GoverningToken && AssetType != AssetType.UtilityToken)
     {
         throw new FormatException();
     }
     Admin = reader.ReadSerializable <UInt160>();
     TR.Exit();
 }
Ejemplo n.º 14
0
        public override void Deserialize(BinaryReader reader)
        {
            base.Deserialize(reader);
            ScriptHash = reader.ReadSerializable <UInt160>();
            IsFrozen   = reader.ReadBoolean();
            Votes      = new ECPoint[reader.ReadVarInt()];
            for (int i = 0; i < Votes.Length; i++)
            {
                Votes[i] = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
            }
            int count = (int)reader.ReadVarInt();

            Balances = new Dictionary <UInt256, Fixed8>(count);
            for (int i = 0; i < count; i++)
            {
                UInt256 assetId = reader.ReadSerializable <UInt256>();
                Fixed8  value   = reader.ReadSerializable <Fixed8>();
                Balances.Add(assetId, value);
            }
        }
Ejemplo n.º 15
0
 void ISerializable.Deserialize(BinaryReader reader)
 {
     if (reader.ReadByte() != StateVersion)
     {
         throw new FormatException();
     }
     AssetId   = reader.ReadSerializable <UInt256>();
     AssetType = (AssetType)reader.ReadByte();
     Name      = reader.ReadVarString();
     Amount    = reader.ReadSerializable <Fixed8>();
     Available = reader.ReadSerializable <Fixed8>();
     Precision = reader.ReadByte();
     reader.ReadByte();                               //FeeMode
     Fee        = reader.ReadSerializable <Fixed8>(); //Fee
     FeeAddress = reader.ReadSerializable <UInt160>();
     Owner      = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     Admin      = reader.ReadSerializable <UInt160>();
     Issuer     = reader.ReadSerializable <UInt160>();
     Expiration = reader.ReadUInt32();
     IsFrozen   = reader.ReadBoolean();
 }
Ejemplo n.º 16
0
 public override void Deserialize(BinaryReader reader)
 {
     base.Deserialize(reader);
     Hash      = reader.ReadSerializable <UInt160>();
     Name      = reader.ReadVarString();
     Owner     = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     Timestamp = reader.ReadUInt32();
     TcpPort   = reader.ReadInt32();
     WsPort    = reader.ReadInt32();
     SeedList  = new string[reader.ReadVarInt()];
     for (int i = 0; i < SeedList.Length; i++)
     {
         SeedList[i] = reader.ReadVarString();
     }
     StandbyValidators = new ECPoint[reader.ReadVarInt()];
     for (int i = 0; i < StandbyValidators.Length; i++)
     {
         StandbyValidators[i] = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     }
     int count = (int)reader.ReadVarInt();
 }
Ejemplo n.º 17
0
        void ISignable.DeserializeUnsigned(BinaryReader reader)
        {
            PrevHash = reader.ReadSerializable <UInt256>();
            Miner    = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
            IV       = reader.ReadBytes(16);
            NoncePieces.Clear();
            int count = (int)reader.ReadVarInt();

            for (int i = 0; i < count; i++)
            {
                ECPoint key = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
                if (key == Miner)
                {
                    throw new FormatException();
                }
                byte[] value = reader.ReadBytes((int)reader.ReadVarInt());
                NoncePieces.Add(key, value);
            }
            NonceHash         = reader.ReadSerializable <UInt256>();
            TransactionHashes = reader.ReadSerializableArray <UInt256>();
        }
Ejemplo n.º 18
0
        void ISerializable.Deserialize(BinaryReader reader)
        {
            if (reader.ReadByte() != StateVersion)
            {
                throw new FormatException();
            }
            ScriptHash = reader.ReadSerializable <UInt160>();
            IsFrozen   = reader.ReadBoolean();
            Votes      = new ECPoint[reader.ReadVarInt()];
            for (int i = 0; i < Votes.Length; i++)
            {
                Votes[i] = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
            }
            int count = (int)reader.ReadVarInt();

            Balances = new Dictionary <UInt256, Fixed8>(count);
            for (int i = 0; i < count; i++)
            {
                UInt256 assetId = reader.ReadSerializable <UInt256>();
                Fixed8  value   = reader.ReadSerializable <Fixed8>();
                Balances.Add(assetId, value);
            }
        }
Ejemplo n.º 19
0
 protected override void DeserializeExclusiveData(BinaryReader reader)
 {
     this.AssetType = (AssetType)reader.ReadByte();
     if (!Enum.IsDefined(typeof(AssetType), AssetType))
     {
         throw new FormatException();
     }
     this.Name   = reader.ReadVarString();
     this.Amount = reader.ReadSerializable <Fixed8>();
     if (Amount == Fixed8.Zero || Amount < -Fixed8.Satoshi)
     {
         throw new FormatException();
     }
     if (AssetType == AssetType.Share && Amount <= Fixed8.Zero)
     {
         throw new FormatException();
     }
     if (AssetType == AssetType.Currency && Amount != -Fixed8.Satoshi)
     {
         throw new FormatException();
     }
     this.Issuer = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     this.Admin  = reader.ReadSerializable <UInt160>();
 }
Ejemplo n.º 20
0
 public override void Deserialize(BinaryReader reader)
 {
     this.publicKey     = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
     base.RedeemScript  = CreateSignatureRedeemScript(publicKey);
     base.PublicKeyHash = publicKey.EncodePoint(true).ToScriptHash();
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 序列化交易中的额外数据
 /// </summary>
 /// <param name="reader">数据来源</param>
 protected override void DeserializeExclusiveData(BinaryReader reader)
 {
     PublicKey = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
 }
Ejemplo n.º 22
0
 public override void Deserialize(BinaryReader reader)
 {
     base.Deserialize(reader);
     PublicKey = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
 }