Skip to content

Commit

Permalink
Fix sizes for RpcNep5Tracker (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored and jsolman committed Mar 18, 2019
1 parent 685f448 commit 8137d5c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 3 additions & 1 deletion RpcNep5Tracker/Nep5Balance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ public class Nep5Balance : StateBase, ICloneable<Nep5Balance>
public BigInteger Balance;
public uint LastUpdatedBlock;

public override int Size => base.Size + Balance.ToByteArray().GetVarSize();
public override int Size => base.Size + Balance.ToByteArray().GetVarSize() + sizeof(uint);

public override void Serialize(BinaryWriter writer)
{
base.Serialize(writer);
writer.WriteVarBytes(Balance.ToByteArray());
writer.Write(LastUpdatedBlock);
}

public override void Deserialize(BinaryReader reader)
{
base.Deserialize(reader);
Balance = new BigInteger(reader.ReadVarBytes(512));
LastUpdatedBlock = reader.ReadUInt32();
}

public Nep5Balance Clone()
Expand Down
4 changes: 2 additions & 2 deletions RpcNep5Tracker/Nep5BalanceKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Nep5BalanceKey : IComparable<Nep5BalanceKey>, IEquatable<Nep5Balanc
public readonly UInt160 UserScriptHash;
public readonly UInt160 AssetScriptHash;

public int Size => 20 + 20;

public Nep5BalanceKey() : this(new UInt160(), new UInt160())
{
}
Expand Down Expand Up @@ -63,7 +65,5 @@ public void Deserialize(BinaryReader reader)
((ISerializable) UserScriptHash).Deserialize(reader);
((ISerializable) AssetScriptHash).Deserialize(reader);
}

public int Size { get; } = 20 + 20;
}
}
3 changes: 1 addition & 2 deletions RpcNep5Tracker/Nep5Transfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Numerics;
using Neo.IO;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;

namespace Neo.Plugins
{
Expand All @@ -13,7 +12,7 @@ public class Nep5Transfer : StateBase, ICloneable<Nep5Transfer>
public UInt256 TxHash;
public BigInteger Amount;

public override int Size => base.Size + 20 + Amount.ToByteArray().GetVarSize();
public override int Size => base.Size + 20 + sizeof(uint) + 32 + Amount.ToByteArray().GetVarSize();

public override void Serialize(BinaryWriter writer)
{
Expand Down
8 changes: 4 additions & 4 deletions RpcNep5Tracker/Nep5TransferKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class Nep5TransferKey : IComparable<Nep5TransferKey>, IEquatable<Nep5Tran
public readonly UInt160 AssetScriptHash;
public ushort BlockXferNotificationIndex { get; private set; }

public int Size => 20 + sizeof(uint) + 20 + sizeof(ushort);

public Nep5TransferKey() : this(new UInt160(), 0, new UInt160(), 0)
{
}
Expand Down Expand Up @@ -76,15 +78,13 @@ public void Serialize(BinaryWriter writer)

public void Deserialize(BinaryReader reader)
{
((ISerializable) UserScriptHash).Deserialize(reader);
((ISerializable)UserScriptHash).Deserialize(reader);
byte[] timestampBytes = new byte[sizeof(uint)];
reader.Read(timestampBytes, 0, sizeof(uint));
if (BitConverter.IsLittleEndian) Array.Reverse(timestampBytes);
Timestamp = BitConverter.ToUInt32(timestampBytes, 0);
((ISerializable) AssetScriptHash).Deserialize(reader);
((ISerializable)AssetScriptHash).Deserialize(reader);
BlockXferNotificationIndex = reader.ReadUInt16();
}

public int Size { get; } = 20 + sizeof(byte) + sizeof(uint) + 20 + sizeof(ushort);
}
}

0 comments on commit 8137d5c

Please sign in to comment.