Skip to content

Commit

Permalink
fix bugs;
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Zhang committed Nov 2, 2016
1 parent 98f9588 commit 89f5e03
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/AntShares/Core/RegisterTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ 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();
Name = reader.ReadVarString(1024);
Amount = reader.ReadSerializable<Fixed8>();
if (Amount == Fixed8.Zero || Amount < -Fixed8.Satoshi) throw new FormatException();
if (AssetType == AssetType.Invoice && Amount != -Fixed8.Satoshi)
Expand Down
28 changes: 14 additions & 14 deletions src/AntShares/IO/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static ISerializable AsSerializable(this byte[] value, Type type)
return serializable;
}

public static int GetVarSize(this int value)
internal static int GetVarSize(this int value)
{
if (value < 0xFD)
return sizeof(byte);
Expand All @@ -40,20 +40,20 @@ public static int GetVarSize(this int value)
return sizeof(byte) + sizeof(uint);
}

public static string ReadFixedString(this BinaryReader reader, int length)
internal static string ReadFixedString(this BinaryReader reader, int length)
{
byte[] data = reader.ReadBytes(length);
return Encoding.UTF8.GetString(data.TakeWhile(p => p != 0).ToArray());
}

public static T ReadSerializable<T>(this BinaryReader reader) where T : ISerializable, new()
internal static T ReadSerializable<T>(this BinaryReader reader) where T : ISerializable, new()
{
T obj = new T();
obj.Deserialize(reader);
return obj;
}

public static T[] ReadSerializableArray<T>(this BinaryReader reader, int max = 0x10000000) where T : ISerializable, new()
internal static T[] ReadSerializableArray<T>(this BinaryReader reader, int max = 0x10000000) where T : ISerializable, new()
{
T[] array = new T[reader.ReadVarInt((ulong)max)];
for (int i = 0; i < array.Length; i++)
Expand All @@ -64,12 +64,12 @@ public static string ReadFixedString(this BinaryReader reader, int length)
return array;
}

public static byte[] ReadVarBytes(this BinaryReader reader, int max = 0X7fffffc7)
internal static byte[] ReadVarBytes(this BinaryReader reader, int max = 0X7fffffc7)
{
return reader.ReadBytes((int)reader.ReadVarInt((ulong)max));
}

public static ulong ReadVarInt(this BinaryReader reader, ulong max = ulong.MaxValue)
internal static ulong ReadVarInt(this BinaryReader reader, ulong max = ulong.MaxValue)
{
byte fb = reader.ReadByte();
ulong value;
Expand All @@ -85,9 +85,9 @@ public static ulong ReadVarInt(this BinaryReader reader, ulong max = ulong.MaxVa
return value;
}

public static string ReadVarString(this BinaryReader reader)
internal static string ReadVarString(this BinaryReader reader, int max = 0X7fffffc7)
{
return Encoding.UTF8.GetString(reader.ReadVarBytes());
return Encoding.UTF8.GetString(reader.ReadVarBytes(max));
}

public static byte[] ToArray(this ISerializable value)
Expand All @@ -101,12 +101,12 @@ public static byte[] ToArray(this ISerializable value)
}
}

public static void Write(this BinaryWriter writer, ISerializable value)
internal static void Write(this BinaryWriter writer, ISerializable value)
{
value.Serialize(writer);
}

public static void Write(this BinaryWriter writer, ISerializable[] value)
internal static void Write(this BinaryWriter writer, ISerializable[] value)
{
writer.WriteVarInt(value.Length);
for (int i = 0; i < value.Length; i++)
Expand All @@ -115,7 +115,7 @@ public static void Write(this BinaryWriter writer, ISerializable[] value)
}
}

public static void WriteFixedString(this BinaryWriter writer, string value, int length)
internal static void WriteFixedString(this BinaryWriter writer, string value, int length)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
Expand All @@ -129,13 +129,13 @@ public static void WriteFixedString(this BinaryWriter writer, string value, int
writer.Write(new byte[length - bytes.Length]);
}

public static void WriteVarBytes(this BinaryWriter writer, byte[] value)
internal static void WriteVarBytes(this BinaryWriter writer, byte[] value)
{
writer.WriteVarInt(value.Length);
writer.Write(value);
}

public static void WriteVarInt(this BinaryWriter writer, long value)
internal static void WriteVarInt(this BinaryWriter writer, long value)
{
if (value < 0)
throw new ArgumentOutOfRangeException();
Expand All @@ -160,7 +160,7 @@ public static void WriteVarInt(this BinaryWriter writer, long value)
}
}

public static void WriteVarString(this BinaryWriter writer, string value)
internal static void WriteVarString(this BinaryWriter writer, string value)
{
writer.WriteVarBytes(Encoding.UTF8.GetBytes(value));
}
Expand Down
2 changes: 1 addition & 1 deletion src/AntShares/Network/Payloads/VersionPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void ISerializable.Deserialize(BinaryReader reader)
Timestamp = reader.ReadUInt32();
Port = reader.ReadUInt16();
Nonce = reader.ReadUInt32();
UserAgent = reader.ReadVarString();
UserAgent = reader.ReadVarString(1024);
StartHeight = reader.ReadUInt32();
Relay = reader.ReadBoolean();
}
Expand Down

0 comments on commit 89f5e03

Please sign in to comment.