I want to build a delegator contract to an deployed callee contract without knowing the source code details of the callee contract.
Related part of my delegator contract is as below:
#[ink(message)]
pub fn call_to_contracts(&self, callee_account: AccountId, msg: ink_prelude::string::String) -> ink_prelude::string::String{
let my_return_value: ink_prelude::string::String = ink_env::call::build_call::<ink_env::DefaultEnvironment>()
.call_type(
ink_env::call::Call::new()
.callee(callee_account)
.gas_limit(0)
.transferred_value(0))
.exec_input(
ink_env::call::ExecutionInput::new(ink_env::call::Selector::new([0xa9, 0x45, 0xce, 0xc7]))
.push_arg(msg.into_bytes())
)
.returns::<ink_prelude::string::String>()
.fire()
.unwrap();
my_return_value
}
Related part of my callee contract is as below:
#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))]
pub struct MessageDetail{
name: ink_prelude::string::String,
age: u32,
phones: ink_prelude::vec::Vec<ink_prelude::string::String>,
}
/// test cross contract call
#[ink(message)]
pub fn encode_user_defined_struct(&self, msg: MessageDetail) -> ink_prelude::string::String{
ink_prelude::format!("{:?}", msg)
}
First, I use ContractUI to make a test. I have tried the following input of the parameter msg
when calling call_to_contracts
:
{{\"name\":\"nika\",\"age\":18,\"phones\":[\"hello\",\"nika\"]}}
{\"name\":\"nika\",\"age\":18,\"phones\":[\"hello\",\"nika\"]}
{"name":"nika","age":18,"phones":["hello","nika"]}
Besides, I have tried to replace the .push_arg(msg.into_bytes())
with .push_arg(msg)
.
But it's not working, I cannot see any error messages through ContractUI.
I'm sure if I defined the same MessageDetail
in delegator contract, and change the parameter msg
from String
to MessageDetail
, everything's OK.
But my purpose is to build a general delegator contract without knowing the source code details of the callee, is there any way I can try in ink!
?
delegator example
is suitable for 'static' scenarios. But anyway, I have solved the problem. Thank you all the same.