Skip to content

Commit 98aa5c8

Browse files
committed
Update rosetta_handler.py
- Single definition of the network identifier - Slightly improve error displayed if preprocess_transaction fails
1 parent a23735d commit 98aa5c8

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

rosetta_handler.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
def cli():
1212
pass
1313

14+
network_identifier = {
15+
"blockchain": "flow",
16+
"network": "localnet",
17+
}
1418

1519
# Shared function used internally but not standalone from CLI
1620

@@ -24,10 +28,7 @@ def preprocess_transaction(rosetta_host_url, root_originator, operations, metada
2428
endpoint = "/construction/preprocess"
2529
target_url = rosetta_host_url + endpoint
2630
data = {
27-
"network_identifier": {
28-
"blockchain": "flow",
29-
"network": "localnet"
30-
},
31+
"network_identifier": network_identifier,
3132
"operations": operations,
3233
"metadata": {
3334
"payer": root_originator
@@ -36,17 +37,17 @@ def preprocess_transaction(rosetta_host_url, root_originator, operations, metada
3637
if metadata:
3738
for key in metadata:
3839
data["metadata"][key] = metadata[key]
39-
return request_router(target_url, data)
40+
result = request_router(target_url, data)
41+
if "options" not in result:
42+
raise RuntimeError(result)
43+
return result
4044

4145

4246
def metadata_transaction(rosetta_host_url, options):
4347
endpoint = "/construction/metadata"
4448
target_url = rosetta_host_url + endpoint
4549
data = {
46-
"network_identifier": {
47-
"blockchain": "flow",
48-
"network": "localnet"
49-
},
50+
"network_identifier": network_identifier,
5051
"options": options
5152
}
5253
return request_router(target_url, data)
@@ -56,10 +57,7 @@ def payloads_transaction(rosetta_host_url, operations, protobuf):
5657
endpoint = "/construction/payloads"
5758
target_url = rosetta_host_url + endpoint
5859
data = {
59-
"network_identifier": {
60-
"blockchain": "flow",
61-
"network": "localnet"
62-
},
60+
"network_identifier": network_identifier,
6361
"operations": operations,
6462
"metadata": {
6563
"protobuf": protobuf
@@ -72,10 +70,7 @@ def combine_transaction(rosetta_host_url, unsigned_tx, root_originator, hex_byte
7270
endpoint = "/construction/combine"
7371
target_url = rosetta_host_url + endpoint
7472
data = {
75-
"network_identifier": {
76-
"blockchain": "flow",
77-
"network": "localnet"
78-
},
73+
"network_identifier": network_identifier,
7974
"unsigned_transaction": unsigned_tx,
8075
"signatures": [
8176
{
@@ -103,10 +98,7 @@ def submit_transaction(rosetta_host_url, signed_tx):
10398
endpoint = "/construction/submit"
10499
target_url = rosetta_host_url + endpoint
105100
data = {
106-
"network_identifier": {
107-
"blockchain": "flow",
108-
"network": "localnet"
109-
},
101+
"network_identifier": network_identifier,
110102
"signed_transaction": signed_tx
111103
}
112104
return request_router(target_url, data)

0 commit comments

Comments
 (0)