Skip to content

Commit

Permalink
move cert url from attribute to transaction version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Zhang committed Nov 10, 2016
1 parent bca5be5 commit 080ae0e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
27 changes: 26 additions & 1 deletion src/AntShares/Core/RegisterTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,21 @@ public class RegisterTransaction : Transaction
/// 资产管理员的合约散列值
/// </summary>
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;
}
}

/// <summary>
/// 系统费用
Expand Down Expand Up @@ -86,6 +99,10 @@ protected override void DeserializeExclusiveData(BinaryReader reader)
throw new FormatException();
Issuer = ECPoint.DeserializeFrom(reader, ECCurve.Secp256r1);
Admin = reader.ReadSerializable<UInt160>();
if (Version > 0)
{
CertUrl = reader.ReadVarString(252);
}
}

private Dictionary<CultureInfo, string> _names;
Expand Down Expand Up @@ -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);
}
}

/// <summary>
Expand All @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions src/AntShares/Core/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class Transaction : IApiInterface, IInventory
/// <summary>
/// 版本
/// </summary>
public const byte Version = 0;
public byte Version;
/// <summary>
/// 该交易所具备的额外特性
/// </summary>
Expand Down Expand Up @@ -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<TransactionAttribute>();
Expand Down
6 changes: 3 additions & 3 deletions src/AntShares/Core/TransactionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/AntShares/Core/TransactionAttributeUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public enum TransactionAttributeUsage : byte

Vote = 0x30,

CertUrl = 0x80,
DescriptionUrl = 0x81,
Description = 0x90,

Expand Down

0 comments on commit 080ae0e

Please sign in to comment.