66from 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 }
0 commit comments