OCamlPro / freeton_wallet

The 'ft' tool is a multi-account terminal wallet for the Free TON blockchain. It is based on the freeton_ocaml_sdk.
https://ocamlpro.github.io/freeton_wallet
Other
14 stars 9 forks source link

Allow debots to get data from main net smart contracts without deploying them main net #58

Open NoamDev opened 2 years ago

NoamDev commented 2 years ago

Some DeBots, need to get data from main net smart contracts, however I don't want to pay deployment fees each time I change something in the debot code. I think there's a need to allow running a debot that will interact with main net without deploying it to main net.

NoamDev commented 2 years ago

I have three ideas of how to implement this. A) Run the debot without deploying at all. Requires generating contract data and hacking the debot browser to run the debot without downloading it. B) Create a dapp proxy that will pass requests regarding this debot address to tonos se while redirecting all other requests to main.ton.dev. C) Downloading the required contracts from main net in advance and deploy them to tonos se.

lefessan commented 2 years ago

ft is currently not able to run debots. The reason is that, to run a debot, it would require to call OCaml from Rust (for example, to give access to wallet keys in the debot), and we haven't tested that with the current OCaml-Rust binding. Yet, the proposed feature would be a "must-have" feature when we start implementing debots.

lefessan commented 2 years ago

I finally decided to give it a try. Here is what I have:

NoamDev commented 2 years ago

Hey @lefessan, I was finally able to test the hack thoroughly, it has a problem. since you simply always return DEBOT_BOC whenever load_state is called, you are also preventing any getters on other smart contracts from being run locally. I think checking if the address requested is the address of the running debot would solve this problem. It's a good start though:)

lefessan commented 2 years ago

Indeed. I have uploaded a new version (should just need to call cargo update before cargo build in tonos-cli same branch). This time, the BOC of the debot is extracted from env variable DEBOT_XXX for address 0:XXX. DEBOT_BOC_PRINT=1 should display the name of that variable.

lefessan commented 2 years ago

And another version:

lefessan commented 2 years ago

Latest version of ft automatically supports this behavior (since commit https://github.com/OCamlPro/freeton_wallet/pull/72/commits/b117b280ec4425f8555f6531ae17b5501fa7678b), using ft debot fetch --boc-from NETWORK ADDR (where ADDR is the debot address on NETWORK). It will automatically download the BOC, save it in $DEBOT_LOAD_DIR and set the env var before calling tonos-cli. However, you need to have the patched version of tonos-cli in $HOME/.ft/bin/.