Skip to content

Commit

Permalink
RpcServer, RpcClient: strip HF_ prefix from getversion response
Browse files Browse the repository at this point in the history
It's nice to have clear hardfork ame without hardfork prefix so that
the resulting hardfork JSON-ized name can be applicable by both C#
and NeoGo nodes.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed Oct 12, 2023
1 parent 6ead780 commit ef9dff0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/RpcClient/Models/RpcVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public JObject ToJson()
json["initialgasdistribution"] = InitialGasDistribution;
json["hardforks"] = new JArray(Hardforks.Select(s => new JObject()
{
["name"] = s.Key,
// Strip HF_ prefix.
["name"] = s.Key.ToString().Substring(3),
["blockheight"] = s.Value,
}));
return json;
Expand All @@ -63,7 +64,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()))),
Hardforks = new Dictionary<Hardfork, uint>(((JArray)json["hardforks"]).Select(s => new KeyValuePair<Hardfork, uint>(Enum.Parse<Hardfork>($"HF_{s["name"].AsString()}"), (uint)s["blockheight"].AsNumber()))),
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/RpcServer/RpcServer.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ protected virtual JToken GetVersion(JArray _params)
json["protocol"]["hardforks"] = new JArray(system.Settings.Hardforks.Select(hf =>
{
JObject forkJson = new();
forkJson["name"] = hf.Key;
// Strip "HF_" prefix.
forkJson["name"] = hf.Key.ToString().Substring(3);
forkJson["blockheight"] = hf.Value;
return forkJson;
}));
Expand Down

0 comments on commit ef9dff0

Please sign in to comment.