MystenLabs / sui

Sui, a next-generation smart contract platform with high throughput, low latency, and an asset-oriented programming model powered by the Move programming language
https://sui.io
Apache License 2.0
5.84k stars 11.06k forks source link

cross-contract call #18402

Open web3olalala opened 4 days ago

web3olalala commented 4 days ago

I'm trying a cross-contract call, and I'm asking if there's any functionality in sui move similar to address(this) and msg.sender in solidity, so I can recognize dep_moudle's address in main_moulde.

To give a very common example, I wrote a dep_moudle and deployed it to Sui, and I only want main_moudle to call it, so how should I implement dep_moudle and main_moudle?

damirka commented 1 day ago

Hey @web3olalala! Move does not have dynamic dispatch, and a smart contract cannot call another one directly, but an account can call multiple modules in a single transaction. For me to be able to solve your case, would you mind providing more details? More specifically, do you own both packages / modules? Can you affect the codebase of the callee contract?

web3olalala commented 1 day ago

@damirka Thank you very much, both modules are mine, in fact, the main problem is permissions, I want to make dep_moudle can only be called by main_moulde, or dep_moudle specified module to call, other addresses do not have permission to call it, if you can solve this problem would be great.

web3olalala commented 1 day ago

More specifically, dep_moudle is similar to a registry, and only a registered main_moudle can call dep_moudle. Are there any programmes to solve this problem?

damirka commented 21 hours ago

Okay. Are both modules located in the same package? If so, just use public(package) visibility on the function.

https://move-book.com/move-basics/visibility.html#package-visibility

web3olalala commented 18 hours ago

dep_moudle is deployed in advance, I will always deploy main_moudle, and then register it to allow dep_moudle to support the new main_moudle call

web3olalala commented 18 hours ago

I don't know if there is any way to solve this problem.😭

tnowacki commented 11 hours ago

I will always deploy main_moudle, and then register it to allow dep_moudle to support the new main_moudle call

Why? Why wouldn't you just include both modules in the same package?

Questions aside, you could try something very hacky with type_name::get() and then control the creation of that type carefully. That being said I would just recommend publishing both modules in the same package. I see no reason to split them if you want the dep module to be callable only by the main module