yungwine / pytoniq Goto Github PK
View Code? Open in Web Editor NEWTON Blockchain SDK with native ADNL protocols implementations
Home Page: https://yungwine.gitbook.io/pytoniq-doc/
TON Blockchain SDK with native ADNL protocols implementations
Home Page: https://yungwine.gitbook.io/pytoniq-doc/
Hi all, I have a question about testnet.
When I use get_transactions on testnet, it usually returns -400 code for me. But when I remove the specific node and use different trans_lt to go on, other node also may throws -400. So how to resolve this problem?
Update:
Now im trying set only_archieve
to true and it seems no error returned, so can i think that archieve_peer contains all data? or I have a wrong thinking?
pytoniq/pytoniq/liteclient/balancer.py
Line 234 in a5f1d15
Thanks for everyone's answer.
Hello. Every time I am trying to make transfer I am getting this error. My code:
from dedust import Asset, Factory, PoolType, SwapParams, VaultNative
from pytoniq import WalletV4R2, LiteBalancer
import asyncio
import time
mnemonics = ""
async def main():
provider = LiteBalancer.from_mainnet_config(2)
await provider.start_up()
wallet = await WalletV4R2.from_mnemonic(provider=provider, mnemonics=mnemonics)
SCALE_ADDRESS = "EQBlqsm144Dq6SjbPI4jjZvA1hqTIP3CvHovbIfW_t-SCALE"
TON = Asset.native()
SCALE = Asset.jetton(SCALE_ADDRESS)
pool = await Factory.get_pool(pool_type=PoolType.VOLATILE,
assets=[TON, SCALE],
provider=provider)
swap_params = SwapParams(deadline=int(time.time() + 60 * 5),
recipient_address=wallet.address)
swap_amount = int(float(input("Enter swap amount: ")) * 1e9)
swap = VaultNative.create_swap_payload(amount=swap_amount,
pool_address=pool.address,
swap_params=swap_params)
swap_amount = int(swap_amount + (0.25 * 1e9)) # 0.25 = gas_value
await wallet.transfer(destination="EQDa4VOnTYlLvDJ0gZjNYm5PXfSmmtL6Vs6A_CZEtXCNICq_", # native vault
amount=swap_amount,
body=swap)
asyncio.run(main())
Traceback:
Traceback (most recent call last):
File "/root/sniper-bot/test_requests.py", line 46, in <module>
asyncio.run(main())
File "/root/.pyenv/versions/3.10.14/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/root/.pyenv/versions/3.10.14/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/root/sniper-bot/test_requests.py", line 40, in main
await wallet.transfer(destination="EQDa4VOnTYlLvDJ0gZjNYm5PXfSmmtL6Vs6A_CZEtXCNICq_", # native vault
File "/root/.pyenv/versions/sniper/lib/python3.10/site-packages/pytoniq/contract/wallets/wallet.py", line 143, in transfer
return await self.raw_transfer(msgs=[wallet_message])
File "/root/.pyenv/versions/sniper/lib/python3.10/site-packages/pytoniq/contract/wallets/wallet.py", line 131, in raw_transfer
seqno = await self.get_seqno()
File "/root/.pyenv/versions/sniper/lib/python3.10/site-packages/pytoniq/contract/wallets/wallet.py", line 157, in get_seqno
return (await super().run_get_method('seqno'))[0]
File "/root/.pyenv/versions/sniper/lib/python3.10/site-packages/pytoniq/contract/contract.py", line 111, in run_get_method
return await self.provider.run_get_method(self.address, method, stack)
File "/root/.pyenv/versions/sniper/lib/python3.10/site-packages/pytoniq/liteclient/balancer.py", line 359, in run_get_method
return await self.execute_method('run_get_method', **self._get_args(locals()))
File "/root/.pyenv/versions/sniper/lib/python3.10/site-packages/pytoniq/liteclient/balancer.py", line 267, in execute_method
resp = await peer_meth(*args, **kwargs)
File "/root/.pyenv/versions/sniper/lib/python3.10/site-packages/pytoniq/liteclient/client.py", line 494, in run_get_method
return await self.run_get_method_remote(address, method, stack, block) # will be replaced with run_get_method_local in future
File "/root/.pyenv/versions/sniper/lib/python3.10/site-packages/pytoniq/liteclient/client.py", line 526, in run_get_method_remote
raise RunGetMethodError(address=address, method=method, exit_code=result['exit_code'])
pytoniq.liteclient.client.RunGetMethodError: Get method "seqno" for account Address<EQBqIGPRZfmOuk5o8CiqOOCVnpHIj7vx2_UF-REfLwc3znW-> returned exit code -256
I know that exists two request types for sending message (pytonlib supports both): raw.sendMessage & raw.sendMessageReturnHash.
Please, add ability to get hash after sending message !
It is worth adding to the description that for the library to work, the minimum version of python is 3.10
On older versions of python there is an error:
ERROR: Ignored the following versions that require a different python version: 0.0.5 Requires-Python >=3.10; 0.0.6 Requires-Python >=3.10; 0.0.7 Requires-Python >=3.10
ERROR: Could not find a version that satisfies the requirement pytoniq (from versions: none)
ERROR: No matching distribution found for pytoniq
simple code to create new wallet not working:
from pytoniq import LiteClient
from pytoniq.contract.wallets import WalletV4R2
async def main():
client = LiteClient.from_mainnet_config(trust_level=2)
await client.connect()
mnemo, wallet = await WalletV4R2.create(provider=client)
Error:
File "/opt/bot/lib/python3.10/site-packages/pytoniq/contract/wallets/wallet.py", line 364, in create
return await super().create(provider=provider, wc=wc, wallet_id=wallet_id, version='v4r2')
File "/opt/bot/lib/python3.10/site-packages/pytoniq/contract/wallets/wallet.py", line 98, in create
return mnemo, await cls.from_mnemonic(provider, mnemo, wc, wallet_id, version)
TypeError: WalletV4R2.from_mnemonic() takes from 3 to 5 positional arguments but 6 were given
reproduced on 3 different projects/envs.
btw, WalletV4R2.from_mnemonic()
works correctly.
We've been running block scanner for a few months now and we first time encountered issues with specific blocks. None of the blocks on mainnet from 37719962
to 37719966
are parseable and all fail with following error. Starting with block 37719967
all works again. Any ideas how to fix? Thank you.
$ python blockscanner.py 37719962
Traceback (most recent call last):
File "/Users/user/www/project/ton/blockscanner.py", line 246, in <module>
asyncio.run(main())
File "/Users/user/.pyenv/versions/3.9.9/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/Users/user/.pyenv/versions/3.9.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/Users/user/www/project/ton/blockscanner.py", line 240, in main
await BlockScanner(
File "/Users/user/www/project/ton/blockscanner.py", line 63, in run
await self.block_handler(self.blks_queue.get_nowait(), self)
File "/Users/user/www/project/ton/blockscanner.py", line 198, in handle_block
transactions = await client.raw_get_block_transactions_ext(block)
File "/Users/user/www/project/ton/.venv/lib/python3.9/site-packages/pytoniq/liteclient/client.py", line 756, in raw_get_block_transactions_ext
transactions = parse_transactions(result)
File "/Users/user/www/project/ton/.venv/lib/python3.9/site-packages/pytoniq/liteclient/client.py", line 739, in parse_transactions
transaction = Transaction.deserialize(tr_root.begin_parse())
File "/Users/user/www/project/ton/.venv/lib/python3.9/site-packages/pytoniq_core/tlb/transaction.py", line 119, in deserialize
out_msgs = ref.load_dict(15, value_deserializer=lambda src: MessageAny.deserialize(src.load_ref().begin_parse()))
File "/Users/user/www/project/ton/.venv/lib/python3.9/site-packages/pytoniq_core/boc/slice.py", line 222, in load_dict
return HashMap.parse(self.load_ref().begin_parse(), key_length, key_deserializer, value_deserializer)
File "/Users/user/www/project/ton/.venv/lib/python3.9/site-packages/pytoniq_core/boc/hashmap/hashmap.py", line 123, in parse
result = {key_deserializer(i): value_deserializer(j) for i, j in dict_result.items()}
File "/Users/user/www/project/ton/.venv/lib/python3.9/site-packages/pytoniq_core/boc/hashmap/hashmap.py", line 123, in <dictcomp>
result = {key_deserializer(i): value_deserializer(j) for i, j in dict_result.items()}
File "/Users/user/www/project/ton/.venv/lib/python3.9/site-packages/pytoniq_core/tlb/transaction.py", line 119, in <lambda>
out_msgs = ref.load_dict(15, value_deserializer=lambda src: MessageAny.deserialize(src.load_ref().begin_parse()))
File "/Users/user/www/project/ton/.venv/lib/python3.9/site-packages/pytoniq_core/tlb/transaction.py", line 188, in deserialize
init = StateInit.deserialize(cell_slice)
File "/Users/user/www/project/ton/.venv/lib/python3.9/site-packages/pytoniq_core/tlb/account.py", line 270, in deserialize
code=cell_slice.load_ref() if cell_slice.load_bit() else None,
File "/Users/user/www/project/ton/.venv/lib/python3.9/site-packages/pytoniq_core/boc/slice.py", line 172, in load_ref
ref = self.refs[self.ref_offset]
IndexError: list index out of range
I'm using block scanner example and so far I only have found hash of transaction using transaction.cell.hash.hex()
. But it is different of the hash that sender sees on his wallet under Sent transactions.
For example I have this hash (B circle) a8065b4a8d941e52367965b7bb7dc72af2bbb89d4095bdcc40cc1fa58feaddea
:
https://tonviewer.com/transaction/a8065b4a8d941e52367965b7bb7dc72af2bbb89d4095bdcc40cc1fa58feaddea
But when letter A in the circle is set then URL changes to this hash, which also matches hash that sender sees in his sent transactions archive: 23eff21be48727416de6b71d00bfd50451227ec4972431eb95e4071bc9dafd46
But I couldn't find a way to get that hash. Is it possible?
When I use RPC API /getTransactions
method using the hash I have, then transaction is successfully found however even then field result.transaction_id.hash
hash not same hash I searched with, but the one that sender sees.
PS. Thank you for this useful library.
When getting transactions from toncenter API I get a msg_data field inside the in_msg where I can get the comment of the transaction, how can I get that in pytoniq?
"msg_data": {
"@type": "msg.dataText",
"text": "Y29udGFjdC10cmFuc2Zlcg=="
},
"message": "contact-transfer"
Running a client from the mainnet config throws an error:
client = LiteClient.from_mainnet_config()
await client.connect()
The error:
Exception has occurred: LiteServerError
Liteserver crashed with 651 code. Message: cannot load proof link for (-1,8000000000000000,34835953):5695B27CD38B9BC46AB7A09967D7591AA2513B7372AE51C760DD64D682DB27A8:F28D76297E7806D24CF111110F527DED07B565693AD4B208C97C9D9419E2C4AF : not in db
pytoniq.liteclient.client.LiteServerError: Liteserver crashed with 651 code. Message: cannot load proof link for (-1,8000000000000000,34835953):5695B27CD38B9BC46AB7A09967D7591AA2513B7372AE51C760DD64D682DB27A8:F28D76297E7806D24CF111110F527DED07B565693AD4B208C97C9D9419E2C4AF : not in db
During handling of the above exception, another exception occurred:
File "/home/Documents/Projects/pytonlib-1/new-project/main.py", line 7, in main
await client.connect()
File "/home/Documents/Projects/pytonlib-1/new-project/main.py", line 16, in <module>
asyncio.run(main())
pytoniq.liteclient.client.LiteServerError: Liteserver crashed with 651 code. Message: cannot load proof link for (-1,8000000000000000,34835953):5695B27CD38B9BC46AB7A09967D7591AA2513B7372AE51C760DD64D682DB27A8:F28D76297E7806D24CF111110F527DED07B565693AD4B208C97C9D9419E2C4AF : not in db
I trying to connect to my node, and i get error :
ensure(rc == 0, "Unexpected library error", raising=exc.RuntimeError) File "/home/meqy/Projects/Python/stonfi/.venv/lib/python3.12/site-packages/nacl/exceptions.py", line 88, in ensure raise raising(*args) nacl.exceptions.RuntimeError: Unexpected library error
I have an issue processing some workchain blocks using method raw_get_block: got pytoniq_core.tlb.transaction.TransactionError: MsgEnvelope deserialization error tag: 5
exception.
Env:
Source code for reproduction:
import asyncio
from pytoniq import LiteClient
from pytoniq_core import BlockIdExt
async def run():
client = LiteClient.from_mainnet_config(ls_i=0, trust_level=2)
await client.connect()
# Error block example
block_json = {'workchain': 0, 'shard': 1152921504606846976, 'seqno': 45298633,
'root_hash': 'ff8111a62d7b9e8bf5ec6ca93a9b48a03ae0f451ea72a3b689dd61d61a8f92d9',
'file_hash': 'a92ec504a1850649f4a1f32e19c3d4f08424b1547cd7f28aa587c8b0b549e459'}
# Working block example
# block_json = {'workchain': 0, 'shard': 1152921504606846976, 'seqno': 45298616,
# 'root_hash': '5af5dfb8258088a7e1f5d8ed8f6675376b902895f20c2bb013bc573a7bb50d02', 'file_hash':
# 'de7469ebe4a8624ad34b482665884f4d9abce877e74f42b000c2db39a6f1f145'}
block: BlockIdExt = BlockIdExt.from_dict(block_json)
_ = await client.raw_get_block(block)
print(f'Node block {block} ok')
if __name__ == '__main__':
asyncio.run(run())
Exception:
Traceback (most recent call last):
File "/Users/user/Library/issue.py", line 22, in run
_ = await client.raw_get_block(block)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pytoniq/liteclient/client.py", line 442, in raw_get_block
return Block.deserialize(result_block.begin_parse())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pytoniq_core/tlb/block.py", line 44, in deserialize
extra = BlockExtra.deserialize(cell_slice.load_ref().begin_parse())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pytoniq_core/tlb/block.py", line 840, in deserialize
in_msg_descr = cell_slice.load_ref().begin_parse().load_hashmap_aug_e(256, x_deserializer=InMsg.deserialize, y_deserializer=ImportFees.deserialize)
...
deserialize_hashmap_aug_node(slice, m, ret_dict, extras, prefix.copy(), x_deserializer, y_deserializer)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pytoniq_core/boc/hashmap/parse.py", line 80, in deserialize_hashmap_aug_node
ret_dict[prefix.to01()] = x_deserializer(cs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pytoniq_core/tlb/transaction.py", line 1152, in deserialize
in_msg=MsgEnvelope.deserialize(cell_slice.load_ref().begin_parse()),
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pytoniq_core/tlb/transaction.py", line 1086, in deserialize
raise TransactionError(f'MsgEnvelope deserialization error tag: {tag}')
pytoniq_core.tlb.transaction.TransactionError: MsgEnvelope deserialization error tag: 5
Any ideas how to fix it?
Hello, I'm trying to use the library, and I get an error:
>>> from pytoniq import LiteClient, MessageAny
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytoniq\crypto\ciphers.py", line 9, in <module>
from Cryptodome.Random import get_random_bytes
ModuleNotFoundError: No module named 'Cryptodome'
I solved the problem by installing the dependency:
pip install pycryptodomex
He is in requirements.txt
, but I didn't see it installed when I installed the source library.
I am attaching a screenshot of the installation and error:
I am using the block scanner with the LiteBalancer and getting 651 error when trying to call the raw_get_block_transactions_ext
method for the block.
The code worked a few days ago (without any change) but now it's only returning 651 block is not applied
I think its because of a bad liteserver that is scoring high on the ranking of the LiteBalancer but have corrupted state.
What can I do about it?
Provide examples of using LiteClient for:
Using LiteBalancer with the BlockScanner and getting "no alive peers". The code worked a week ago what could have happened?
I do run lite_balance.start_up() before running the BlockScanner
pytoniq 0.1.39
python 3.11
import asyncio
from pytoniq import LiteClient
async def main():
client = LiteClient.from_mainnet_config( # choose mainnet, testnet or custom config dict
ls_i=0, # index of liteserver from config
trust_level=0, # trust level to liteserver
timeout=15 # timeout not includes key blocks synchronization as it works in pytonlib
)
await client.connect()
if __name__ == '__main__':
asyncio.run(main())
With some probability I get:
Traceback (most recent call last):
File "<rootPath>/pytoniq_test.py", line 44, in <module>
asyncio.run(main())
File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "<rootPath>/pytoniq_test.py", line 13, in main
await client.connect()
File "<rootPath>/.venv/lib/python3.11/site-packages/pytoniq/liteclient/client.py", line 190, in connect
await self.update_last_blocks()
File "<rootPath>/.venv/lib/python3.11/site-packages/pytoniq/liteclient/client.py", line 310, in update_last_blocks
self.last_mc_block = await self.get_trusted_last_mc_block()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<rootPath>/.venv/lib/python3.11/site-packages/pytoniq/liteclient/client.py", line 306, in get_trusted_last_mc_block
await self.get_mc_block_proof(known_block=self.last_key_block, target_block=last_block)
File "<rootPath>/.venv/lib/python3.11/site-packages/pytoniq/liteclient/client.py", line 982, in get_mc_block_proof
while last_proved != target_block:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<rootPath>/.venv/lib/python3.11/site-packages/pytoniq_core/tl/block.py", line 66, in __eq__
if self.seqno != other.seqno or self.workchain != other.workchain or self.shard != other.shard or self.root_hash != other.root_hash or self.file_hash != other.file_hash:
^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'seqno'
Trying to connect to specific peers on start. Tried public ones as well as own full node but connect_to_peer always timeouts.
I double checked the IP, port and the key and they are correct.
Is there any code or action or config needed to be able to connect with other node via adnl.connect_to_peer?
Without this, simple adnl.connect works fine, gets some peers connected automatically on start however after some minutes all peers disconnects. That's my second question: why does it happen and how to make sure the adnl is always connected (for example to my own node)?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.