xssnick / tonutils-go

TON SDK Library in pure Golang for interacting with The Open Network ecosystem using native protocols, such as ADNL, RLDP and etc.
Apache License 2.0
464 stars 95 forks source link

Support for the Finalized W5 (V5R1) Contract #210

Closed Totemancer closed 1 month ago

Totemancer commented 1 month ago

(WIP - Do not merge yet)

Hello tonutils community and @xssnick!

We have refactored V5R1 to V5Beta. The Ton Core recommends calling it beta to prevent the premature spread of the Beta contract. Additionally, we have prepared support for the V5 Final contract (latest revision).

We can now wait for finalized contracts and update to the new naming and contract once it’s ready to go.

I’m submitting this pull request here so the community can test their software before the big day.

Have fun, and feel free to comment or make adjustments.

Totemancer commented 1 month ago

The V5 repo was just updated with the finalized contract. https://github.com/tonkeeper/w5

Happy testing, everyone! Now this can be merged to the dev branch and adjusted further to be ready for the official wallet V5 release.


Eventually, we can implement similar message.ActionType to the struct for full V5 implementation. Currently, it only supports send_msg [0x0ec3c86d].

Similarly, the v5_final.go (packV5FinalActions) can be updated in the near future, but that requires a more in-depth rewrite of the codebase.

                case "add_ext":
            msg = cell.BeginCell().MustStoreUInt(0x02, 32). // action_add_ext prefix
                MustStoreRef(outMsg)                        // message reference
        case "delete_ext":
            msg = cell.BeginCell().MustStoreUInt(0x03, 32). // action_delete_ext prefix
                MustStoreRef(outMsg)                        // message reference
        case "set_signature_auth_allowed":
            msg = cell.BeginCell().MustStoreUInt(0x04, 32). // action_set_signature_auth_allowed prefix
                MustStoreUInt(uint64(message.Mode), 1)       // allowed
xssnick commented 1 month ago

Hi, thank you! But let’s leave the names for backward compatibility and flexibility, Beta = V5R1, Final = V5R2, there is no guarantee that in future it will be a new revision :)

But we can add a comments for constants where mention what is final and what is beta, so it will be easier to understand.

Totemancer commented 1 month ago

Hi, thank you! But let’s leave the names for backward compatibility and flexibility, Beta = V5R1, Final = V5R2, there is no guarantee that in future it will be a new revision :)

But we can add a comments for constants where mention what is final and what is beta, so it will be easier to understand.

Made the requested changes.

The only thing left is to wait for Tonkeeper and other wallets to integrate it. Hopefully, we will generate the same wallets as the other wallets. In theory, this should be due to the network ID and subwallet IDs matching.

https://github.com/Totemancer/tonutils-go/blob/v5final/ton/wallet/address.go#L117

Let us know if you need any other updates.

Totemancer commented 1 month ago

Seems will be called V5R1 and previous one is V5Beta

https://github.com/tonkeeper/tonkeeper-ton/commit/c4ca40117450baaa0b013ec5a3b64f6dea2a67d1

Totemancer commented 1 month ago

Using the official naming and reviewing the tonkeeper-ton repo, I assembled another test branch for review.

It seems they are building addresses differently. Both methods result in a working script deployment. Maybe we can stick to this one as expected by Tonkeeper and other wallets.

I think it’s better to keep V5R1 and rename it to V5Beta as a recommendation. We just need to communicate that anyone who built a script on the V5 Beta contract will need to adjust that one line of code in their codebase. It will create more confusion in the community if we choose to go with V5R2 now.

https://github.com/Totemancer/tonutils-go/commit/a1fa67f840671d52bb41e747b23a5b413cce4c87#diff-690fe05c81bdf07d34a3afd3b777e8f0c10c3b6bc2ec9487b11f989898770a51R46

go get -u github.com/Totemancer/tonutils-go@e041724db2d3cb52d2c82340a9268afdb3d8a539

Totemancer commented 1 month ago

It will be easier to decide and adjust the code after reviewing tongo new commits.

Official V5R1 Implementation: https://github.com/tonkeeper/tongo/commit/6ec6aa61a7cfc3b43643d2f421aaf338a0c80d05

Totemancer commented 1 month ago

Actually, there’s no need to overcomplicate things. We can hardcode the new wallet IDs according to this scheme:

https://github.com/tonkeeper/tonkeeper-ton/commit/d9aec6adfdb853eb37e0bba7453d83ae52e2a170#diff-c8ee60dec2f4e3ee55ad5e40f56fd9a104f21df78086a114d33d62e4fa0ffee6R149

Totemancer commented 1 month ago

Finished the integration according to the Tonkeeper integration.

Kept the name as V5R1 as that will be the name of this contract. We do not want to confuse future users with V5R2, as it might be a different revision down the line.

To test from the master branch: go get -u github.com/Totemancer/tonutils-go@f14e3612e7e5748f3afd28daa7d37a44dbbf494d

We can wait a few days until it appears in wallets to compare addresses, then merge. But it should be good to go now.​

Totemancer commented 1 month ago

Compared results with the tonkeeper-ton TypeScript library.

let wallet = WalletContractV5R1.create({ publicKey: keyPair.publicKey });

Good news! The wallet address matches! The integration is good. We can wait a couple of days to make sure Wallet V5 is finalized. There are a couple of open pull requests https://github.com/ton-blockchain/wallet-contract-v5/pulls about proposed changes (minor). These will be finalized in a few days max.

Let me know your decision on the wallet naming discussed above.

Totemancer commented 1 month ago

Now, explorers on this contract are reporting v5r1. Arriving early next week, we can have this ready for release day.

Official naming as follows: https://github.com/tonkeeper/tonkeeper-web/commit/2b26520c7aaae14cb09b3627f0ca2285b3841dbd#diff-a566641f3f297280b5460b335bf1cb1aabfdb583b75957c3c9132e1d372289beR15

xssnick commented 1 month ago

Thank you, merged, I did small naming refactoring, because if we make V5R1 with new code, users who used V5R1 previously could get a problems after upgrade (wallet address will be changed silently), so I renamed both of them, to V5R1Beta and V5R1Final

Totemancer commented 1 month ago

Thank you, merged, I did small naming refactoring, because if we make V5R1 with new code, users who used V5R1 previously could get a problems after upgrade (wallet address will be changed silently), so I renamed both of them, to V5R1Beta and V5R1Final

Yes, it makes sense. Agreed. Not a problem - people can change that one line of code in their libraries to continue using Beta or switch to Final.

Using the merged V5R1 codes for 2 weeks now and it has been rock solid so far. Thank you for merging. Hopefully, we can contribute to the library in the future too!

Thank you for your work.