Skip to content

Commit

Permalink
api: extend get_version RPC call with extra fields (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje authored Sep 16, 2024
1 parent e690aa6 commit 7a71114
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions neo3/api/noderpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"],
Expand All @@ -118,6 +126,7 @@ def from_json(cls, json: dict):
p["maxvaliduntilblockincrement"],
p["memorypoolmaxtransactions"],
p["initialgasdistribution"],
hf,
)
wsport = json.get("wsport", None)
return cls(
Expand All @@ -126,6 +135,8 @@ def from_json(cls, json: dict):
json["nonce"],
json["useragent"],
vp,
json["rpc"]["sessionenabled"],
json["rpc"]["maxiteratorresultitems"],
)


Expand Down
7 changes: 7 additions & 0 deletions tests/api/test_noderpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ async def test_get_version(self):
"wsport": 10334,
"nonce": 1930156121,
"useragent": user_agent,
"rpc": {"maxiteratorresultitems": 100, "sessionenabled": True},
"protocol": {
"addressversion": 53,
"network": 860833102,
Expand All @@ -568,6 +569,12 @@ 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)
Expand Down

0 comments on commit 7a71114

Please sign in to comment.