Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: extend get_version RPC call with extra fields #311

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading