From 421ebf61a9bdfa2930b67e49241fd185eaafccaa Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Mon, 16 Sep 2024 11:41:04 +0200 Subject: [PATCH 1/4] api: extend `get_version` RPC call with extra fields --- neo3/api/noderpc.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/neo3/api/noderpc.py b/neo3/api/noderpc.py index 8b85bcf..66ab87b 100644 --- a/neo3/api/noderpc.py +++ b/neo3/api/noderpc.py @@ -91,6 +91,7 @@ class VersionProtocol: max_valid_until_block_increment: int memorypool_max_transactions: int initial_gas_distribution: int + hardforks: dict[str, int] @dataclass @@ -104,10 +105,17 @@ class GetVersionResponse: nonce: int user_agent: str protocol: VersionProtocol + rpc_session_enabled: bool + rpc_max_iterator_results: int @classmethod def from_json(cls, json: dict): p = json["protocol"] + + hf = {} + for pair in p["hardforks"]: + hf.update({pair["name"]:pair["blockheight"]}) + vp = VersionProtocol( p["addressversion"], p["network"], @@ -118,6 +126,7 @@ def from_json(cls, json: dict): p["maxvaliduntilblockincrement"], p["memorypoolmaxtransactions"], p["initialgasdistribution"], + hf ) wsport = json.get("wsport", None) return cls( @@ -126,6 +135,8 @@ def from_json(cls, json: dict): json["nonce"], json["useragent"], vp, + json["rpc"]["sessionenabled"], + json["rpc"]["maxiteratorresultitems"] ) From 492b575a53ab7acc7c3c30b4880a621b24a84cd5 Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Mon, 16 Sep 2024 11:42:43 +0200 Subject: [PATCH 2/4] lint --- neo3/api/noderpc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/neo3/api/noderpc.py b/neo3/api/noderpc.py index 66ab87b..a8e363d 100644 --- a/neo3/api/noderpc.py +++ b/neo3/api/noderpc.py @@ -114,7 +114,7 @@ def from_json(cls, json: dict): hf = {} for pair in p["hardforks"]: - hf.update({pair["name"]:pair["blockheight"]}) + hf.update({pair["name"]: pair["blockheight"]}) vp = VersionProtocol( p["addressversion"], @@ -126,7 +126,7 @@ def from_json(cls, json: dict): p["maxvaliduntilblockincrement"], p["memorypoolmaxtransactions"], p["initialgasdistribution"], - hf + hf, ) wsport = json.get("wsport", None) return cls( @@ -136,7 +136,7 @@ def from_json(cls, json: dict): json["useragent"], vp, json["rpc"]["sessionenabled"], - json["rpc"]["maxiteratorresultitems"] + json["rpc"]["maxiteratorresultitems"], ) From 61b5ae6e5727a616c50b551e528121e11a52087a Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Mon, 16 Sep 2024 11:46:41 +0200 Subject: [PATCH 3/4] fix test --- tests/api/test_noderpc.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/api/test_noderpc.py b/tests/api/test_noderpc.py index d97173b..2bbc106 100644 --- a/tests/api/test_noderpc.py +++ b/tests/api/test_noderpc.py @@ -558,6 +558,10 @@ async def test_get_version(self): "wsport": 10334, "nonce": 1930156121, "useragent": user_agent, + "rpc": { + "maxiteratorresultitems": 100, + "sessionenabled": True + }, "protocol": { "addressversion": 53, "network": 860833102, @@ -568,6 +572,24 @@ async def test_get_version(self): "maxtransactionsperblock": 512, "memorypoolmaxtransactions": 50000, "initialgasdistribution": 5200000000000000, + "hardforks": [ + { + "name": "Aspidochelone", + "blockheight": 1730000 + }, + { + "name": "Basilisk", + "blockheight": 4120000 + }, + { + "name": "Cockatrice", + "blockheight": 5450000 + }, + { + "name": "Domovoi", + "blockheight": 5570000 + } + ] }, } self.mock_response(captured) From 4a718b58ee002896575f22d77c456e7ee4691292 Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Mon, 16 Sep 2024 11:47:24 +0200 Subject: [PATCH 4/4] fix test --- tests/api/test_noderpc.py | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/tests/api/test_noderpc.py b/tests/api/test_noderpc.py index 2bbc106..101a870 100644 --- a/tests/api/test_noderpc.py +++ b/tests/api/test_noderpc.py @@ -558,10 +558,7 @@ async def test_get_version(self): "wsport": 10334, "nonce": 1930156121, "useragent": user_agent, - "rpc": { - "maxiteratorresultitems": 100, - "sessionenabled": True - }, + "rpc": {"maxiteratorresultitems": 100, "sessionenabled": True}, "protocol": { "addressversion": 53, "network": 860833102, @@ -573,23 +570,11 @@ async def test_get_version(self): "memorypoolmaxtransactions": 50000, "initialgasdistribution": 5200000000000000, "hardforks": [ - { - "name": "Aspidochelone", - "blockheight": 1730000 - }, - { - "name": "Basilisk", - "blockheight": 4120000 - }, - { - "name": "Cockatrice", - "blockheight": 5450000 - }, - { - "name": "Domovoi", - "blockheight": 5570000 - } - ] + {"name": "Aspidochelone", "blockheight": 1730000}, + {"name": "Basilisk", "blockheight": 4120000}, + {"name": "Cockatrice", "blockheight": 5450000}, + {"name": "Domovoi", "blockheight": 5570000}, + ], }, } self.mock_response(captured)