/
lib.rs
60 lines (54 loc) · 1.62 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#![cfg_attr(not(feature = "std"), no_std, no_main)]
#[ink::contract]
mod runtime_call {
use assets_ink_sdk::{
AssetsCall,
RuntimeCall
};
#[ink(storage)]
#[derive(Default)]
pub struct RuntimeCaller;
#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum RuntimeError {
CallRuntimeFailed,
}
impl RuntimeCaller {
#[ink(constructor)]
pub fn new() -> Self {
Default::default()
}
#[ink(message)]
pub fn transfer_asset(
&mut self,
id: u128,
to: AccountId,
amount: Balance,
) -> Result<(), RuntimeError> {
self.env()
.call_runtime(&RuntimeCall::Assets(AssetsCall::Transfer {
id,
target: to.into(),
amount
}))
.map_err(|_| RuntimeError::CallRuntimeFailed)
}
#[ink(message)]
pub fn transfer_approve_asset(
&mut self,
id: u128,
amount: Balance,
) -> Result<(), RuntimeError> {
let caller = self.env().caller();
let contract = self.env().account_id();
self.env()
.call_runtime(&RuntimeCall::Assets(AssetsCall::TransferApproved {
id,
owner: caller.into(),
destination: contract.into(),
amount,
}))
.map_err(|_| RuntimeError::CallRuntimeFailed)
}
}
}