Skip to content

Commit

Permalink
Added hardfork to RpcClient (#825)
Browse files Browse the repository at this point in the history
* Added hardfork to RpcClient

* fixed unit test for getversionasync
  • Loading branch information
cschuchardt88 committed Sep 26, 2023
1 parent 7b4145c commit 6ead780
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/RpcClient/Models/RpcVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
// modifications are permitted.

using Neo.Json;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Neo.Network.RPC.Models
{
Expand All @@ -25,6 +28,7 @@ public class RpcProtocol
public uint MaxTransactionsPerBlock { get; set; }
public int MemoryPoolMaxTransactions { get; set; }
public ulong InitialGasDistribution { get; set; }
public IReadOnlyDictionary<Hardfork, uint> Hardforks { get; set; }

public JObject ToJson()
{
Expand All @@ -38,6 +42,11 @@ public JObject ToJson()
json["maxtransactionsperblock"] = MaxTransactionsPerBlock;
json["memorypoolmaxtransactions"] = MemoryPoolMaxTransactions;
json["initialgasdistribution"] = InitialGasDistribution;
json["hardforks"] = new JArray(Hardforks.Select(s => new JObject()
{
["name"] = s.Key,
["blockheight"] = s.Value,
}));
return json;
}

Expand All @@ -54,6 +63,7 @@ public static RpcProtocol FromJson(JObject json)
MaxTransactionsPerBlock = (uint)json["maxtransactionsperblock"].AsNumber(),
MemoryPoolMaxTransactions = (int)json["memorypoolmaxtransactions"].AsNumber(),
InitialGasDistribution = (ulong)json["initialgasdistribution"].AsNumber(),
Hardforks = new Dictionary<Hardfork, uint>(((JArray)json["hardforks"]).Select(s => new KeyValuePair<Hardfork, uint>(Enum.Parse<Hardfork>(s["name"].AsString()), (uint)s["blockheight"].AsNumber()))),
};
}
}
Expand Down
8 changes: 7 additions & 1 deletion tests/Neo.Network.RPC.Tests/RpcTestCases.json
Original file line number Diff line number Diff line change
Expand Up @@ -2491,7 +2491,13 @@
"addressversion": 0,
"maxtransactionsperblock": 0,
"memorypoolmaxtransactions": 0,
"initialgasdistribution": 0
"initialgasdistribution": 0,
"hardforks": [
{
"name": "HF_Aspidochelone",
"blockheight": 0
}
]
}
}
}
Expand Down

0 comments on commit 6ead780

Please sign in to comment.