Skip to content

Commit d4d80ad

Browse files
author
swapper-phoenix
committed
Finish syncing endpoint
1 parent 0047f81 commit d4d80ad

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

Connector/xmr/apirpc.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,28 @@ def syncing(id, params):
1717
if err is not None:
1818
raise rpcerrorhandler.BadRequestError(err.message)
1919

20-
blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id,
21-
GET_SYNC_INFO, None)
20+
blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_INFO, None)
2221

2322
if blockchainInfo is None:
2423
logger.printWarning("Could not get blockchain info from node")
25-
raise rpcerrorhandler.BadRequestError(
26-
"Could not get blockchain info from node")
27-
28-
# if blockchainInfo[BLOCKS] != blockchainInfo[HEADERS]:
29-
# response = {
30-
# SYNCING: True,
31-
# SYNC_PERCENTAGE:
32-
# f'{str(blockchainInfo[VERIFICATION_PROGRESS]*100)}%',
33-
# CURRENT_BLOCK_INDEX: blockchainInfo[BLOCKS],
34-
# LATEST_BLOCK_INDEX: blockchainInfo[HEADERS],
35-
# }
36-
# else:
37-
# response = {SYNCING: False}
38-
39-
response = {SYNCING: blockchainInfo}
24+
raise rpcerrorhandler.BadRequestError("Could not get blockchain info from node")
25+
26+
if not blockchainInfo[SYNCHRONIZED]:
27+
syncInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_SYNC_INFO, None)
28+
29+
if syncInfo is None:
30+
logger.printWarning("Could not get syncing info from node")
31+
raise rpcerrorhandler.BadRequestError("Could not get syncing info from node")
32+
33+
response = {
34+
SYNCING: True,
35+
SYNC_PERCENTAGE:
36+
f'{str(syncInfo[HEIGHT] / syncInfo[TARGET_HEIGHT] * 100)}%',
37+
CURRENT_BLOCK_INDEX: str(syncInfo[HEIGHT]),
38+
LATEST_BLOCK_INDEX: str(syncInfo[TARGET_HEIGHT]),
39+
}
40+
else:
41+
response = {SYNCING: False}
4042

4143
err = rpcutils.validateJSONRPCSchema(response, responseSchema)
4244
if err is not None:

Connector/xmr/constants.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,12 @@
77
RESPONSE = "response"
88
SCHEMA_EXTENSION = ".json"
99

10+
HEIGHT = "height"
11+
TARGET_HEIGHT = "target_height"
12+
SYNCHRONIZED = "synchronized"
13+
SYNC_PERCENTAGE = "syncPercentage"
14+
CURRENT_BLOCK_INDEX = "currentBlock"
15+
LATEST_BLOCK_INDEX = "latestBlock"
16+
1017
GET_SYNC_INFO = "sync_info"
18+
GET_INFO = "get_info"

0 commit comments

Comments
 (0)