Skip to content

Commit 54c03e5

Browse files
committed
[core] add call_invoke and call_evaluate to api.rs
1 parent fbd27ac commit 54c03e5

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

core/src/env/api.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use super::ContractEnvStorage;
1818
use crate::{
1919
env::{
20+
CallError,
2021
traits::{
2122
Env,
2223
EnvTypes,
@@ -26,7 +27,7 @@ use crate::{
2627
memory::vec::Vec,
2728
storage::Key,
2829
};
29-
use scale::Encode;
30+
use scale::{Encode, Decode};
3031

3132
/// Stores the given value under the specified key in the contract storage.
3233
///
@@ -84,3 +85,36 @@ where
8485
{
8586
T::dispatch_raw_call(&call.into().encode()[..])
8687
}
88+
89+
/// Invokes a remote smart contract.
90+
///
91+
/// Does not expect to receive return data back.
92+
/// Use this whenever you call a remote smart contract that returns nothing back.
93+
pub fn call_invoke<T>(
94+
callee: T::AccountId,
95+
gas: u64,
96+
value: T::Balance,
97+
input_data: &[u8],
98+
) -> Result<(), CallError>
99+
where
100+
T: Env,
101+
{
102+
T::call_invoke(callee, gas, value, input_data)
103+
}
104+
105+
/// Evaluates a remote smart contract.
106+
///
107+
/// Expects to receive return data back.
108+
/// Use this whenever calling a remote smart contract that returns a value.
109+
pub fn call_evaluate<T, R>(
110+
callee: T::AccountId,
111+
gas: u64,
112+
value: T::Balance,
113+
input_data: &[u8],
114+
) -> Result<R, CallError>
115+
where
116+
T: Env,
117+
R: Decode,
118+
{
119+
T::call_evaluate(callee, gas, value, input_data)
120+
}

0 commit comments

Comments
 (0)