我想在我的合约中调用其他模块的函数,但我没有它的源代码,只能看到它是链上的字节码;
sodility 有接口合约,只需要一个 proto(interface) ,就可以调用任何合约,即使没有源码也可以像下面这样:
那么在sui move中该怎么做呢?
pragma solidity ^0.4.0;
contract InfoFeed {
function info() payable returns (uint ret);
}
contract Consumer {
function deposit() payable returns (uint){
return msg.value;
}
function left() constant returns (uint){
return this.balance;
}
function callFeed(address addr) returns (uint) {
return InfoFeed(addr).info.value(1).gas(8000)();
// here i no need to get source code for InfoFeed implements, and can call it with address
}
}
首先,如果您只有模块字节码并且仍然想从中调用函数,则意味着您真正了解该代码的作用。如果是这种情况,那么您还必须了解它需要哪些参数。
根据上述假设,您可以非常轻松地通过更新两个文件来从任何已部署的包中调用任何公共函数:
1。 move.toml在[addresses]下添加定义要调用的函数的包的地址。
[addresses]
package_from_where_you_want_to_call_func = "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a"
2。 src/your_module.move:导入你要使用的函数。
module tutorial::your_module {
use sui::object::{Self, UID};
use sui::transfer;
use sui::tx_context::{Self, TxContext};
use package_from_where_you_want_to_call_func::desired_module as remote_moduel
struct ColorObject has key {
id: UID,
red: u8,
green: u8,
blue: u8,
}
remote_module::function_you_want_to_call(....);
....
}