ton-http-api 2.0.58__py3-none-any.whl → 2.0.60__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyTON/main.py CHANGED
@@ -29,6 +29,7 @@ from pyTON.settings import Settings, RedisCacheSettings
29
29
 
30
30
  from pytonlib.utils.address import detect_address as __detect_address, prepare_address as _prepare_address
31
31
  from pytonlib.utils.wallet import wallets as known_wallets, sha256
32
+ from pytonlib.utils.common import hash_to_hex, hex_to_b64str
32
33
  from pytonlib import TonlibException
33
34
 
34
35
  from loguru import logger
@@ -181,6 +182,20 @@ def prepare_address(address):
181
182
  except:
182
183
  raise HTTPException(status_code=416, detail="Incorrect address")
183
184
 
185
+ def prepare_hash(value):
186
+ if value is None:
187
+ return None
188
+ if len(value) == 44:
189
+ value = value.replace('_', '/').replace('-', '+')
190
+ data = codecs.decode(codecs.encode(value, 'utf-8'), 'base64')
191
+ b64 = codecs.encode(data, 'base64').decode('utf-8')
192
+ return b64.strip()
193
+ if len(value) == 64:
194
+ data = codecs.decode(codecs.encode(value, 'utf-8'), 'hex')
195
+ b64 = codecs.encode(data, 'base64').decode('utf-8')
196
+ return b64.strip()
197
+ raise ValueError('Invalid hash')
198
+
184
199
  def address_state(account_info):
185
200
  if isinstance(account_info.get("code", ""), int) or len(account_info.get("code", "")) == 0:
186
201
  if len(account_info.get("frozen_hash", "")) == 0:
@@ -452,6 +467,9 @@ async def get_block_transactions(
452
467
  """
453
468
  Get transactions of the given block.
454
469
  """
470
+ root_hash = prepare_hash(root_hash)
471
+ file_hash = prepare_hash(file_hash)
472
+ after_hash = prepare_hash(after_hash)
455
473
  return await tonlib.getBlockTransactions(workchain, shard, seqno, count, root_hash, file_hash, after_lt, after_hash)
456
474
 
457
475
  @app.get('/getBlockTransactionsExt', response_model=TonResponse, response_model_exclude_none=True, tags=['blocks','transactions'])
@@ -470,6 +488,9 @@ async def get_block_transactions_ext(
470
488
  """
471
489
  Get transactions of the given block.
472
490
  """
491
+ root_hash = prepare_hash(root_hash)
492
+ file_hash = prepare_hash(file_hash)
493
+ after_hash = prepare_hash(after_hash)
473
494
  return await tonlib.getBlockTransactionsExt(workchain, shard, seqno, count, root_hash, file_hash, after_lt, after_hash)
474
495
 
475
496
  @app.get('/getBlockHeader', response_model=TonResponse, response_model_exclude_none=True, tags=['blocks'])
@@ -485,6 +506,8 @@ async def get_block_header(
485
506
  """
486
507
  Get metadata of a given block.
487
508
  """
509
+ root_hash = prepare_hash(root_hash)
510
+ file_hash = prepare_hash(file_hash)
488
511
  return await tonlib.getBlockHeader(workchain, shard, seqno, root_hash, file_hash)
489
512
 
490
513
  @app.get('/getConfigParam', response_model=TonResponse, response_model_exclude_none=True, tags=['get config'])
@@ -499,6 +522,19 @@ async def get_config_param(
499
522
  """
500
523
  return await tonlib.get_config_param(config_id, seqno)
501
524
 
525
+
526
+ @app.get('/getLibraries', response_model=TonResponse, response_model_exclude_none=True, tags=['get config'])
527
+ @json_rpc('getLibraries')
528
+ @wrap_result
529
+ async def get_libraries(
530
+ libraries: List[str] = Query(..., description="List of base64 encoded libraries hashes")
531
+ ):
532
+ """
533
+ Get libraries codes.
534
+ """
535
+ lib_hashes = [hex_to_b64str(hash_to_hex(l)) for l in libraries]
536
+ return await tonlib.getLibraries(lib_hashes)
537
+
502
538
  @app.get('/getTokenData', response_model=TonResponse, response_model_exclude_none=True, tags=['accounts'])
503
539
  @json_rpc('getTokenData')
504
540
  @wrap_result
pyTON/manager.py CHANGED
@@ -82,6 +82,7 @@ class TonlibManager:
82
82
  self.getBlockTransactions = self.cache_manager.cached(expire=600)(self.getBlockTransactions)
83
83
  self.getBlockHeader = self.cache_manager.cached(expire=600)(self.getBlockHeader)
84
84
  self.get_config_param = self.cache_manager.cached(expire=5)(self.get_config_param)
85
+ self.getLibraries = self.cache_manager.cached(expire=600)(self.getLibraries)
85
86
  self.get_token_data = self.cache_manager.cached(expire=15)(self.get_token_data)
86
87
  self.tryLocateTxByOutcomingMessage = self.cache_manager.cached(expire=600, check_error=False)(self.tryLocateTxByOutcomingMessage)
87
88
  self.tryLocateTxByIncomingMessage = self.cache_manager.cached(expire=600, check_error=False)(self.tryLocateTxByIncomingMessage)
@@ -434,6 +435,12 @@ class TonlibManager:
434
435
  else:
435
436
  return await self.dispatch_archival_request(method, config_id, seqno)
436
437
 
438
+ async def getLibraries(self, lib_hashes: list):
439
+ try:
440
+ return await self.dispatch_request('get_libraries', lib_hashes)
441
+ except TonlibError:
442
+ return await self.dispatch_archival_request('get_libraries', lib_hashes)
443
+
437
444
  async def tryLocateTxByOutcomingMessage(self, source, destination, creation_lt):
438
445
  return await self.dispatch_archival_request('try_locate_tx_by_outcoming_message', source, destination, creation_lt)
439
446
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ton-http-api
3
- Version: 2.0.58
3
+ Version: 2.0.60
4
4
  Summary: HTTP API for TON (The Open Network)
5
5
  Home-page: https://github.com/toncenter/ton-http-api
6
6
  Author: K-Dimentional Tree
@@ -1,14 +1,14 @@
1
1
  pyTON/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  pyTON/__main__.py,sha256=s38Hio4NMli_rdk4BMFsvFVjRvjn6-ue8BmrEpVAxHI,3425
3
3
  pyTON/cache.py,sha256=EmOG2sZtbQno4p40ugf9XagdmWfdCopW4eTIGCpsO9Y,1219
4
- pyTON/main.py,sha256=CBqoo3FXK7hJQj-u1jR8SzBHk_UXDD-CTZ1u5aMXxzY,32163
5
- pyTON/manager.py,sha256=PwX7Di2b2tqnKptoOs90WNme45iSAVIbSJDP9SijUNc,22522
4
+ pyTON/main.py,sha256=xETi_Xt41N8H0TyqPrYp-uh31N2fYV7z4qcLfHYokN8,33505
5
+ pyTON/manager.py,sha256=1Trd_DzPs8-iXa2yxzbP529vtcqmNv60BgZWpPp5EZE,22862
6
6
  pyTON/models.py,sha256=y0qc3OLCxKCp4kcnphAQG6ytbWdz_VuqcmbbDfv8Qdk,958
7
7
  pyTON/settings.py,sha256=1_ni1WfiDDFoGLkxyMriuMJiEzSrxi8lDOt06QyeuxE,4217
8
8
  pyTON/worker.py,sha256=R6IK4ANuJowq8NfUmd8oTOxMLmJGoU9SdRu5iMl8wms,7937
9
- ton_http_api-2.0.58.dist-info/METADATA,sha256=pNroX9WQjXkPrwvMxqHS-bd57kBTdrWcKCcX97n7Hs0,7703
10
- ton_http_api-2.0.58.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- ton_http_api-2.0.58.dist-info/entry_points.txt,sha256=SXjqOmzFEXVLM3twuvRooW5-o2F9qxuz_ReR8DR3-Ho,53
12
- ton_http_api-2.0.58.dist-info/top_level.txt,sha256=3YNL3CNQpsgajYJ8rlVECgL2taXsBxUgXSA5rJSF2RQ,6
13
- ton_http_api-2.0.58.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
14
- ton_http_api-2.0.58.dist-info/RECORD,,
9
+ ton_http_api-2.0.60.dist-info/METADATA,sha256=3yGMka8QpeJjEJQrKxUwpobIIqLMqjlK8wR779bc5hM,7703
10
+ ton_http_api-2.0.60.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ ton_http_api-2.0.60.dist-info/entry_points.txt,sha256=SXjqOmzFEXVLM3twuvRooW5-o2F9qxuz_ReR8DR3-Ho,53
12
+ ton_http_api-2.0.60.dist-info/top_level.txt,sha256=3YNL3CNQpsgajYJ8rlVECgL2taXsBxUgXSA5rJSF2RQ,6
13
+ ton_http_api-2.0.60.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
14
+ ton_http_api-2.0.60.dist-info/RECORD,,