From 080ae0eca0fded3a8f4b03ee2ed42815935283f3 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Thu, 10 Nov 2016 22:58:29 +0800 Subject: [PATCH] move cert url from attribute to transaction version 1 --- src/AntShares/Core/RegisterTransaction.cs | 27 ++++++++++++++++++- src/AntShares/Core/Transaction.cs | 5 ++-- src/AntShares/Core/TransactionAttribute.cs | 6 ++--- .../Core/TransactionAttributeUsage.cs | 1 - 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/AntShares/Core/RegisterTransaction.cs b/src/AntShares/Core/RegisterTransaction.cs index 6e3d32b3ff..c82d74062e 100644 --- a/src/AntShares/Core/RegisterTransaction.cs +++ b/src/AntShares/Core/RegisterTransaction.cs @@ -39,8 +39,21 @@ public class RegisterTransaction : Transaction /// 资产管理员的合约散列值 /// public UInt160 Admin; + public string CertUrl; - public override int Size => base.Size + sizeof(AssetType) + Encoding.UTF8.GetByteCount(Name).GetVarSize() + Encoding.UTF8.GetByteCount(Name) + Amount.Size + sizeof(byte) + Issuer.Size + Admin.Size; + public override int Size + { + get + { + int size = base.Size; + size += sizeof(AssetType) + Encoding.UTF8.GetByteCount(Name).GetVarSize() + Encoding.UTF8.GetByteCount(Name) + Amount.Size + sizeof(byte) + Issuer.Size + Admin.Size; + if (Version > 0) + { + size += sizeof(byte) + Encoding.UTF8.GetByteCount(CertUrl); + } + return size; + } + } /// /// 系统费用 @@ -86,6 +99,10 @@ protected override void DeserializeExclusiveData(BinaryReader reader) throw new FormatException(); Issuer = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1); Admin = reader.ReadSerializable(); + if (Version > 0) + { + CertUrl = reader.ReadVarString(252); + } } private Dictionary _names; @@ -158,6 +175,10 @@ protected override void SerializeExclusiveData(BinaryWriter writer) writer.Write(Precision); writer.Write(Issuer); writer.Write(Admin); + if (Version > 0) + { + writer.WriteVarString(CertUrl); + } } /// @@ -183,6 +204,10 @@ public override JObject ToJson() json["asset"]["low"] = Amount.GetData() & 0xffffffff; json["asset"]["issuer"] = Issuer.ToString(); json["asset"]["admin"] = Wallet.ToAddress(Admin); + if (Version > 0) + { + json["asset"]["cert"] = CertUrl; + } return json; } diff --git a/src/AntShares/Core/Transaction.cs b/src/AntShares/Core/Transaction.cs index 2e4c628884..20205ea00d 100644 --- a/src/AntShares/Core/Transaction.cs +++ b/src/AntShares/Core/Transaction.cs @@ -25,7 +25,7 @@ public abstract class Transaction : IApiInterface, IInventory /// /// 版本 /// - public const byte Version = 0; + public byte Version; /// /// 该交易所具备的额外特性 /// @@ -167,7 +167,8 @@ void ISignable.DeserializeUnsigned(BinaryReader reader) private void DeserializeUnsignedWithoutType(BinaryReader reader) { - if (reader.ReadByte() != Version) + Version = reader.ReadByte(); + if (Version != 0) throw new FormatException(); DeserializeExclusiveData(reader); Attributes = reader.ReadSerializableArray(); diff --git a/src/AntShares/Core/TransactionAttribute.cs b/src/AntShares/Core/TransactionAttribute.cs index 217825e999..a7ebcbd141 100644 --- a/src/AntShares/Core/TransactionAttribute.cs +++ b/src/AntShares/Core/TransactionAttribute.cs @@ -29,7 +29,7 @@ public int Size return sizeof(TransactionAttributeUsage) + 32; else if (Usage == TransactionAttributeUsage.Script) return sizeof(TransactionAttributeUsage) + 20; - else if (Usage == TransactionAttributeUsage.CertUrl || Usage == TransactionAttributeUsage.DescriptionUrl) + else if (Usage == TransactionAttributeUsage.DescriptionUrl) return sizeof(TransactionAttributeUsage) + sizeof(byte) + Data.Length; else return sizeof(TransactionAttributeUsage) + Data.Length.GetVarSize() + Data.Length; @@ -45,7 +45,7 @@ void ISerializable.Deserialize(BinaryReader reader) Data = new[] { (byte)Usage }.Concat(reader.ReadBytes(32)).ToArray(); else if (Usage == TransactionAttributeUsage.Script) Data = reader.ReadBytes(20); - else if (Usage == TransactionAttributeUsage.CertUrl || Usage == TransactionAttributeUsage.DescriptionUrl) + else if (Usage == TransactionAttributeUsage.DescriptionUrl) Data = reader.ReadBytes(reader.ReadByte()); else if (Usage == TransactionAttributeUsage.Description || Usage >= TransactionAttributeUsage.Remark) Data = reader.ReadVarBytes(ushort.MaxValue); @@ -56,7 +56,7 @@ void ISerializable.Deserialize(BinaryReader reader) void ISerializable.Serialize(BinaryWriter writer) { writer.Write((byte)Usage); - if (Usage == TransactionAttributeUsage.CertUrl || Usage == TransactionAttributeUsage.DescriptionUrl) + if (Usage == TransactionAttributeUsage.DescriptionUrl) writer.Write((byte)Data.Length); else if (Usage == TransactionAttributeUsage.Description || Usage >= TransactionAttributeUsage.Remark) writer.WriteVarInt(Data.Length); diff --git a/src/AntShares/Core/TransactionAttributeUsage.cs b/src/AntShares/Core/TransactionAttributeUsage.cs index 3ed1238782..79785a9594 100644 --- a/src/AntShares/Core/TransactionAttributeUsage.cs +++ b/src/AntShares/Core/TransactionAttributeUsage.cs @@ -26,7 +26,6 @@ public enum TransactionAttributeUsage : byte Vote = 0x30, - CertUrl = 0x80, DescriptionUrl = 0x81, Description = 0x90,