Skip to content

Commit 92120e3

Browse files
committed
getFeePerByte, getBlockByNumber, getBlockByHash, getHeight and schemas
1 parent 78fafae commit 92120e3

16 files changed

+641
-7
lines changed

Connector/xmr/apirpc.py

Lines changed: 201 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,206 @@
66
from logger import logger
77

88

9+
# @rpcutils.rpcMethod
10+
# def getAddressBalance(id, params):
11+
# logger.printInfo(f"Executing RPC method getAddressBalance with id {id} and params {params}")
12+
13+
# requestSchema, responseSchema = utils.getMethodSchemas(GET_ADDRESS_BALANCE)
14+
15+
# err = rpcutils.validateJSONRPCSchema(params, requestSchema)
16+
# if err is not None:
17+
# raise rpcerrorhandler.BadRequestError(err.message)
18+
19+
# blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_INFO, None)
20+
21+
# if blockchainInfo is None:
22+
# logger.printWarning("Could not get blockchain info from node")
23+
# raise rpcerrorhandler.BadRequestError("Could not get blockchain info from node")
24+
25+
# return response
26+
27+
28+
# @rpcutils.rpcMethod
29+
# def getAddressesBalance(id, params):
30+
# logger.printInfo(f"Executing RPC method getAddressesBalance with id {id} and params {params}")
31+
32+
# requestSchema, responseSchema = utils.getMethodSchemas(GET_ADDRESSES_BALANCE)
33+
34+
# err = rpcutils.validateJSONRPCSchema(params, requestSchema)
35+
# if err is not None:
36+
# raise rpcerrorhandler.BadRequestError(err.message)
37+
38+
# blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_INFO, None)
39+
40+
# if blockchainInfo is None:
41+
# logger.printWarning("Could not get blockchain info from node")
42+
# raise rpcerrorhandler.BadRequestError("Could not get blockchain info from node")
43+
44+
# return response
45+
46+
947
@rpcutils.rpcMethod
10-
def syncing(id, params):
48+
def getFeePerByte(id, params):
49+
logger.printInfo(f"Executing RPC method getFeePerByte with id {id} and params {params}")
50+
51+
requestSchema, responseSchema = utils.getMethodSchemas(GET_FEE_PER_BYTE)
52+
53+
err = rpcutils.validateJSONRPCSchema(params, requestSchema)
54+
if err is not None:
55+
raise rpcerrorhandler.BadRequestError(err.message)
56+
57+
fee = RPCConnector.request(RPC_ENDPOINT, id, GET_FEE_ESTIMATE_METHOD, None)
58+
59+
if fee is None:
60+
logger.printWarning("Could not get fee info from node")
61+
raise rpcerrorhandler.BadRequestError("Could not get fee info from node")
62+
63+
response = {
64+
FEE_PER_BYTE: fee[FEE]
65+
}
66+
67+
err = rpcutils.validateJSONRPCSchema(response, responseSchema)
68+
if err is not None:
69+
raise rpcerrorhandler.BadRequestError(err.message)
70+
71+
return response
72+
73+
74+
@rpcutils.rpcMethod
75+
def getBlockByNumber(id, params):
76+
logger.printInfo(f"Executing RPC method getBlockByNumber with id {id} and params {params}")
77+
78+
requestSchema, responseSchema = utils.getMethodSchemas(GET_BLOCK_BY_NUMBER)
79+
80+
err = rpcutils.validateJSONRPCSchema(params, requestSchema)
81+
if err is not None:
82+
raise rpcerrorhandler.BadRequestError(err.message)
83+
84+
try:
85+
blockNumber = int(params[BLOCK_NUMBER], base=10)
86+
except Exception as err:
87+
raise rpcerrorhandler.BadRequestError(str(err))
88+
89+
block = RPCConnector.request(RPC_ENDPOINT, id, GET_BLOCK_METHOD, [blockNumber])
90+
91+
if block is None:
92+
logger.printWarning("Could not get block info from node")
93+
raise rpcerrorhandler.BadRequestError("Could not get block info from node")
94+
95+
err = rpcutils.validateJSONRPCSchema(block, responseSchema)
96+
if err is not None:
97+
raise rpcerrorhandler.BadRequestError(err.message)
98+
99+
return block
100+
101+
102+
@rpcutils.rpcMethod
103+
def getBlockByHash(id, params):
104+
logger.printInfo(f"Executing RPC method getBlockByHash with id {id} and params {params}")
105+
106+
requestSchema, responseSchema = utils.getMethodSchemas(GET_BLOCK_BY_HASH)
107+
108+
err = rpcutils.validateJSONRPCSchema(params, requestSchema)
109+
if err is not None:
110+
raise rpcerrorhandler.BadRequestError(err.message)
111+
112+
block = RPCConnector.request(RPC_ENDPOINT, id, GET_BLOCK_METHOD, [params[BLOCK_HASH]])
113+
114+
if block is None:
115+
logger.printWarning("Could not get block info from node")
116+
raise rpcerrorhandler.BadRequestError("Could not get block info from node")
117+
118+
err = rpcutils.validateJSONRPCSchema(block, responseSchema)
119+
if err is not None:
120+
raise rpcerrorhandler.BadRequestError(err.message)
121+
122+
return block
123+
124+
125+
# @rpcutils.rpcMethod
126+
# def getTransaction(id, params):
127+
# logger.printInfo(f"Executing RPC method getTransaction with id {id} and params {params}")
128+
129+
# requestSchema, responseSchema = utils.getMethodSchemas(GET_TRANSACTION)
130+
131+
# err = rpcutils.validateJSONRPCSchema(params, requestSchema)
132+
# if err is not None:
133+
# raise rpcerrorhandler.BadRequestError(err.message)
134+
135+
# blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_INFO_METHOD, None)
136+
137+
# if blockchainInfo is None:
138+
# logger.printWarning("Could not get blockchain info from node")
139+
# raise rpcerrorhandler.BadRequestError("Could not get blockchain info from node")
140+
141+
# return response
142+
143+
144+
@rpcutils.rpcMethod
145+
def getHeight(id, params):
146+
logger.printInfo(f"Executing RPC method getHeight with id {id} and params {params}")
147+
148+
requestSchema, responseSchema = utils.getMethodSchemas(GET_HEIGHT)
149+
150+
err = rpcutils.validateJSONRPCSchema(params, requestSchema)
151+
if err is not None:
152+
raise rpcerrorhandler.BadRequestError(err.message)
153+
154+
blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_INFO_METHOD, None)
155+
156+
if blockchainInfo is None:
157+
logger.printWarning("Could not get latest blockchain info from node")
158+
raise rpcerrorhandler.BadRequestError("Could not get latest blockchain info from node")
159+
160+
response = {
161+
LATEST_BLOCK_INDEX: blockchainInfo[HEIGHT],
162+
LATEST_BLOCK_HASH: blockchainInfo[TOP_BLOCK_HASH]
163+
}
164+
165+
err = rpcutils.validateJSONRPCSchema(response, responseSchema)
166+
if err is not None:
167+
raise rpcerrorhandler.BadRequestError(err.message)
168+
169+
return response
170+
171+
172+
# @rpcutils.rpcMethod
173+
# def checkTxProof(id, params):
174+
# logger.printInfo(f"Executing RPC method checkTxProof with id {id} and params {params}")
175+
176+
# requestSchema, responseSchema = utils.getMethodSchemas(CHECK_TX_PROOF)
177+
178+
# err = rpcutils.validateJSONRPCSchema(params, requestSchema)
179+
# if err is not None:
180+
# raise rpcerrorhandler.BadRequestError(err.message)
181+
182+
# blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_INFO_METHOD, None)
11183

184+
# if blockchainInfo is None:
185+
# logger.printWarning("Could not get blockchain info from node")
186+
# raise rpcerrorhandler.BadRequestError("Could not get blockchain info from node")
187+
188+
189+
# return response
190+
191+
192+
# @rpcutils.rpcMethod
193+
# def checkSpendProof(id, params):
194+
# logger.printInfo(f"Executing RPC method checkSpendProof with id {id} and params {params}")
195+
196+
# requestSchema, responseSchema = utils.getMethodSchemas(CHECK_SPEND_PROOF)
197+
198+
# err = rpcutils.validateJSONRPCSchema(params, requestSchema)
199+
# if err is not None:
200+
# raise rpcerrorhandler.BadRequestError(err.message)
201+
202+
# blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_INFO_METHOD, None)
203+
204+
# return response
205+
206+
207+
@rpcutils.rpcMethod
208+
def syncing(id, params):
12209
logger.printInfo(f"Executing RPC method syncing with id {id} and params {params}")
13210

14211
requestSchema, responseSchema = utils.getMethodSchemas(SYNCING)
@@ -17,14 +214,14 @@ def syncing(id, params):
17214
if err is not None:
18215
raise rpcerrorhandler.BadRequestError(err.message)
19216

20-
blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_INFO, None)
217+
blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_INFO_METHOD, None)
21218

22219
if blockchainInfo is None:
23220
logger.printWarning("Could not get blockchain info from node")
24221
raise rpcerrorhandler.BadRequestError("Could not get blockchain info from node")
25222

26223
if not blockchainInfo[SYNCHRONIZED]:
27-
syncInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_SYNC_INFO, None)
224+
syncInfo = RPCConnector.request(RPC_ENDPOINT, id, GET_SYNC_INFO_METHOD, None)
28225

29226
if syncInfo is None:
30227
logger.printWarning("Could not get syncing info from node")
@@ -35,7 +232,7 @@ def syncing(id, params):
35232
SYNC_PERCENTAGE:
36233
f'{str(syncInfo[HEIGHT] / syncInfo[TARGET_HEIGHT] * 100)}%',
37234
CURRENT_BLOCK_INDEX: str(syncInfo[HEIGHT]),
38-
LATEST_BLOCK_INDEX: str(syncInfo[TARGET_HEIGHT]),
235+
LATEST_BLOCK: str(syncInfo[TARGET_HEIGHT]),
39236
}
40237
else:
41238
response = {SYNCING: False}

Connector/xmr/constants.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
SYNCING = "syncing"
2+
GET_ADDRESS_BALANCE = "getaddressbalance"
3+
GET_ADDRESSES_BALANCE = "getaddressesbalance"
4+
GET_BLOCK_BY_HASH = "getblockbyhash"
5+
GET_BLOCK_BY_NUMBER = "getblockbynumber"
6+
GET_FEE_PER_BYTE = "getfeeperbyte"
7+
GET_HEIGHT = "getheight"
8+
GET_TRANSACTION = "gettransaction"
9+
CHECK_SPEND_PROOF = "checkSpendProof"
10+
CHECK_TX_PROOF = "checkTxProof"
211

312
RPC_JSON_SCHEMA_FOLDER = "xmr/rpcschemas/"
413
WS_JSON_SCHEMA_FOLDER = "xmr/wsschemas/"
@@ -12,7 +21,19 @@
1221
SYNCHRONIZED = "synchronized"
1322
SYNC_PERCENTAGE = "syncPercentage"
1423
CURRENT_BLOCK_INDEX = "currentBlock"
15-
LATEST_BLOCK_INDEX = "latestBlock"
24+
LATEST_BLOCK_INDEX = "latestBlockIndex"
25+
LATEST_BLOCK_HASH = "latestBlockHash"
26+
LATEST_BLOCK = "latestBlock"
27+
FEE = "fee"
28+
FEE_PER_BYTE = "feePerByte"
29+
HASH = "hash"
30+
BLOCK_HEADER = "block_header"
31+
BLOCK_NUMBER = "blockNumber"
32+
BLOCK_HASH = "blockHash"
33+
TOP_BLOCK_HASH = "top_block_hash"
1634

17-
GET_SYNC_INFO = "sync_info"
18-
GET_INFO = "get_info"
35+
GET_SYNC_INFO_METHOD = "sync_info"
36+
GET_INFO_METHOD = "get_info"
37+
GET_FEE_ESTIMATE_METHOD = "get_fee_estimate"
38+
GET_BLOCK_METHOD = "get_block"
39+
GET_LAST_BLOCK_HEADER_METHOD = "get_last_block_header"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema",
3+
"title": "",
4+
"description": "",
5+
"type": "object",
6+
"properties": {
7+
"address": {
8+
"type": "string"
9+
}
10+
},
11+
"required": [
12+
"address"
13+
]
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema",
3+
"title": "",
4+
"description": "",
5+
"type": "object",
6+
"properties": {
7+
"confirmed": {
8+
"type": "string"
9+
},
10+
"unconfirmed": {
11+
"type": "string"
12+
}
13+
},
14+
"required": [
15+
"confirmed",
16+
"unconfirmed"
17+
]
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema",
3+
"title": "",
4+
"description": "",
5+
"type": "object",
6+
"properties": {
7+
"addresses": {
8+
"type": "array",
9+
"items": {
10+
"type": "string"
11+
}
12+
}
13+
},
14+
"required": [
15+
"addresses"
16+
]
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema",
3+
"title": "",
4+
"description": "",
5+
"type": "array",
6+
"items": {
7+
"type": "object",
8+
"properties": {
9+
"address": {
10+
"type": "string"
11+
},
12+
"balance": {
13+
"type": "object",
14+
"properties": {
15+
"confirmed": {
16+
"type": "string"
17+
},
18+
"unconfirmed": {
19+
"type": "string"
20+
}
21+
},
22+
"required": [
23+
"confirmed",
24+
"unconfirmed"
25+
]
26+
}
27+
},
28+
"required": [
29+
"address",
30+
"balance"
31+
]
32+
}
33+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema",
3+
"title": "",
4+
"description": "",
5+
"type": "object",
6+
"properties": {
7+
"blockHash" : {
8+
"type": "string"
9+
}
10+
},
11+
"required": [
12+
"blockHash"
13+
]
14+
}

0 commit comments

Comments
 (0)