Skip to content

Commit fb99fae

Browse files
Added Seqno parameter to several methods (#162)
1 parent 3369b42 commit fb99fae

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

ton-http-api/pyTON/main.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,14 @@ async def get_worker_state():
245245
@json_rpc('getAddressInformation')
246246
@wrap_result
247247
async def get_address_information(
248-
address: str = Query(..., description="Identifier of target TON account in any form.")
248+
address: str = Query(..., description="Identifier of target TON account in any form."),
249+
seqno: Optional[int] = Query(None, description="Seqno of masterchain block at which moment the address information should be loaded")
249250
):
250251
"""
251252
Get basic information about the address: balance, code, data, last_transaction_id.
252253
"""
253254
address = prepare_address(address)
254-
result = await tonlib.raw_get_account_state(address)
255+
result = await tonlib.raw_get_account_state(address, seqno)
255256
result["state"] = address_state(result)
256257
if "balance" in result and int(result["balance"]) < 0:
257258
result["balance"] = 0
@@ -261,26 +262,28 @@ async def get_address_information(
261262
@json_rpc('getExtendedAddressInformation')
262263
@wrap_result
263264
async def get_extended_address_information(
264-
address: str = Query(..., description="Identifier of target TON account in any form.")
265+
address: str = Query(..., description="Identifier of target TON account in any form."),
266+
seqno: Optional[int] = Query(None, description="Seqno of masterchain block at which moment the address information should be loaded")
265267
):
266268
"""
267269
Similar to previous one but tries to parse additional information for known contract types. This method is based on tonlib's function *getAccountState*. For detecting wallets we recommend to use *getWalletInformation*.
268270
"""
269271
address = prepare_address(address)
270-
result = await tonlib.generic_get_account_state(address)
272+
result = await tonlib.generic_get_account_state(address, seqno)
271273
return result
272274

273275
@app.get('/getWalletInformation', response_model=TonResponse, response_model_exclude_none=True, tags=['accounts'])
274276
@json_rpc('getWalletInformation')
275277
@wrap_result
276278
async def get_wallet_information(
277-
address: str = Query(..., description="Identifier of target TON account in any form.")
279+
address: str = Query(..., description="Identifier of target TON account in any form."),
280+
seqno: Optional[int] = Query(None, description="Seqno of masterchain block at which moment the address information should be loaded")
278281
):
279282
"""
280283
Retrieve wallet information. This method parses contract state and currently supports more wallet types than getExtendedAddressInformation: simple wallet, standart wallet, v3 wallet, v4 wallet.
281284
"""
282285
address = prepare_address(address)
283-
result = await tonlib.raw_get_account_state(address)
286+
result = await tonlib.raw_get_account_state(address, seqno)
284287
res = {'wallet': False, 'balance': 0, 'extra_currencies': [], 'account_state': None, 'wallet_type': None, 'seqno': None}
285288
res["account_state"] = address_state(result)
286289
res["balance"] = result["balance"] if (result["balance"] and int(result["balance"]) > 0) else 0
@@ -316,13 +319,14 @@ async def get_transactions(
316319
@json_rpc('getAddressBalance')
317320
@wrap_result
318321
async def get_address_balance(
319-
address: str = Query(..., description="Identifier of target TON account in any form.")
322+
address: str = Query(..., description="Identifier of target TON account in any form."),
323+
seqno: Optional[int] = Query(None, description="Seqno of masterchain block at which moment the address information should be loaded")
320324
):
321325
"""
322326
Get balance (in nanotons) of a given address.
323327
"""
324328
address = prepare_address(address)
325-
result = await tonlib.raw_get_account_state(address)
329+
result = await tonlib.raw_get_account_state(address, seqno)
326330
if "balance" in result and int(result["balance"]) < 0:
327331
result["balance"] = 0
328332
return result["balance"]
@@ -331,13 +335,14 @@ async def get_address_balance(
331335
@json_rpc('getAddressState')
332336
@wrap_result
333337
async def get_address(
334-
address: str = Query(..., description="Identifier of target TON account in any form.")
338+
address: str = Query(..., description="Identifier of target TON account in any form."),
339+
seqno: Optional[int] = Query(None, description="Seqno of masterchain block at which moment the address information should be loaded")
335340
):
336341
"""
337342
Get state of a given address. State can be either *unitialized*, *active* or *frozen*.
338343
"""
339344
address = prepare_address(address)
340-
result = await tonlib.raw_get_account_state(address)
345+
result = await tonlib.raw_get_account_state(address, seqno)
341346
return address_state(result)
342347

343348
@app.get('/packAddress', response_model=TonResponse, response_model_exclude_none=True, tags=['accounts'])
@@ -715,13 +720,14 @@ async def estimate_fee_cell(
715720
async def run_get_method(
716721
address: str = Body(..., description='Contract address'),
717722
method: Union[str, int] = Body(..., description='Method name or method id'),
718-
stack: List[List[Any]] = Body(..., description="Array of stack elements: `[['num',3], ['cell', cell_object], ['slice', slice_object]]`")
723+
stack: List[List[Any]] = Body(..., description="Array of stack elements: `[['num',3], ['cell', cell_object], ['slice', slice_object]]`"),
724+
seqno: Optional[int] = Body(None, description="Seqno of masterchain block at which moment the Get Method is to be executed")
719725
):
720726
"""
721727
Run get method on smart contract.
722728
"""
723729
address = prepare_address(address)
724-
return await tonlib.raw_run_method(address, method, stack)
730+
return await tonlib.raw_run_method(address, method, stack, seqno)
725731

726732

727733
if settings.webserver.json_rpc:

ton-http-api/pyTON/manager.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,22 +314,30 @@ async def get_transactions(self, account_address, from_transaction_lt=None, from
314314
else:
315315
return await self.dispatch_request(method, account_address, from_transaction_lt, from_transaction_hash, to_transaction_lt, limit, decode_messages)
316316

317-
async def raw_get_account_state(self, address: str):
317+
async def raw_get_account_state(self, address: str, seqno: int = None):
318318
method = 'raw_get_account_state'
319319
try:
320-
addr = await self.dispatch_request(method, address)
320+
addr = await self.dispatch_request(method, address, seqno)
321321
except TonlibError:
322-
addr = await self.dispatch_archival_request(method, address)
322+
addr = await self.dispatch_archival_request(method, address, seqno)
323323
return addr
324324

325-
async def generic_get_account_state(self, address: str):
326-
return await self.dispatch_request('generic_get_account_state', address)
325+
async def generic_get_account_state(self, address: str, seqno: int = None):
326+
method = 'generic_get_account_state'
327+
try:
328+
addr = await self.dispatch_request(method, address, seqno)
329+
except TonlibError:
330+
addr = await self.dispatch_archival_request(method, address, seqno)
331+
return addr
327332

328333
async def get_token_data(self, address: str):
329334
return await self.dispatch_request('get_token_data', address)
330335

331-
async def raw_run_method(self, address, method, stack_data, output_layout=None):
332-
return await self.dispatch_request('raw_run_method', address, method, stack_data, output_layout)
336+
async def raw_run_method(self, address, method, stack_data, seqno):
337+
try:
338+
return await self.dispatch_request('raw_run_method', address, method, stack_data, seqno)
339+
except TonlibError:
340+
return await self.dispatch_archival_request('raw_run_method', address, method, stack_data, seqno)
333341

334342
async def _send_message(self, serialized_boc, method):
335343
ls_index_list = self.select_worker(count=4)

0 commit comments

Comments
 (0)