Commit ec5edf89 authored by Andrew Jones's avatar Andrew Jones Committed by Hero Bird

[core] extract call method (#172)

parent 54c03e55
Pipeline #52913 failed with stages
......@@ -114,6 +114,32 @@ macro_rules! impl_getters_for_srml_env {
}
}
impl<T> SrmlEnv<T>
where
T: EnvTypes,
{
fn call(
callee: <Self as EnvTypes>::AccountId,
gas: u64,
value: <Self as EnvTypes>::Balance,
input_data: &[u8],
) -> u32 {
let callee = callee.encode();
let value = value.encode();
unsafe {
sys::ext_call(
callee.as_ptr() as u32,
callee.len() as u32,
gas,
value.as_ptr() as u32,
value.len() as u32,
input_data.as_ptr() as u32,
input_data.len() as u32,
)
}
}
}
impl<T> Env for SrmlEnv<T>
where
T: EnvTypes,
......@@ -171,19 +197,7 @@ where
value: <Self as EnvTypes>::Balance,
input_data: &[u8],
) -> Result<(), CallError> {
let callee = callee.encode();
let value = value.encode();
let result = unsafe {
sys::ext_call(
callee.as_ptr() as u32,
callee.len() as u32,
gas,
value.as_ptr() as u32,
value.len() as u32,
input_data.as_ptr() as u32,
input_data.len() as u32,
)
};
let result = Self::call(callee, gas, value, input_data);
if result != 0 {
return Err(CallError)
}
......@@ -196,19 +210,7 @@ where
value: <Self as EnvTypes>::Balance,
input_data: &[u8],
) -> Result<U, CallError> {
let callee = callee.encode();
let value = value.encode();
let result = unsafe {
sys::ext_call(
callee.as_ptr() as u32,
callee.len() as u32,
gas,
value.as_ptr() as u32,
value.len() as u32,
input_data.as_ptr() as u32,
input_data.len() as u32,
)
};
let result = Self::call(callee, gas, value, input_data);
if result != 0 {
return Err(CallError)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment