-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
executable file
·86 lines (70 loc) · 2.89 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#![cfg_attr(not(feature = "std"), no_std)]
use ink_env::Environment;
use ink_lang as ink;
use ink_prelude::vec::Vec;
//use invarch_runtime_primitives::{AccountId, Balance, BlockNumber, Hash};
use invarch_runtime_primitives::{AnyId, CommonId};
#[ink::chain_extension]
pub trait InvarchExtension {
type ErrorCode = ExtensionError;
#[ink(extension = 5000, returns_result = false)]
fn ipf_mint(metadata: Vec<u8>, data: <InvarchEnvironment as Environment>::Hash) -> CommonId;
#[ink(extension = 5001, returns_result = false)]
fn ipf_burn(ipf_id: CommonId);
#[ink(extension = 5100, returns_result = false)]
fn ips_create(metadata: Vec<u8>, data: Vec<CommonId>, allow_replica: bool) -> CommonId;
#[ink(extension = 5102, returns_result = false)]
fn ips_append(
ips_id: CommonId,
assets: Vec<AnyId<CommonId, CommonId>>,
new_metadata: Option<Vec<u8>>,
);
#[ink(extension = 5103, returns_result = false)]
fn ips_remove(
ips_id: CommonId,
assets: Vec<(
AnyId<CommonId, CommonId>,
<InvarchEnvironment as Environment>::AccountId,
)>,
new_metadata: Option<Vec<u8>>,
);
#[ink(extension = 5104, returns_result = false)]
fn ips_allow_replica(ips_id: CommonId);
#[ink(extension = 5105, returns_result = false)]
fn ips_disallow_replica(ips_id: CommonId);
#[ink(extension = 5106, returns_result = false)]
fn ips_create_replica(ips_id: CommonId) -> CommonId;
#[ink(extension = 5201, returns_result = false)]
fn ipt_mint(
target: <InvarchEnvironment as Environment>::AccountId,
ipt_id: CommonId,
amount: <InvarchEnvironment as Environment>::Balance,
);
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum ExtensionError {
FailGetRandomSource,
MaxMetadataExceeded,
}
impl ink_env::chain_extension::FromStatusCode for ExtensionError {
fn from_status_code(status_code: u32) -> Result<(), Self> {
match status_code {
0 => Ok(()),
1 => Err(Self::FailGetRandomSource),
_ => panic!("encountered unknown status code"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum InvarchEnvironment {}
impl Environment for InvarchEnvironment {
const MAX_EVENT_TOPICS: usize = <ink_env::DefaultEnvironment as Environment>::MAX_EVENT_TOPICS;
type AccountId = <ink_env::DefaultEnvironment as Environment>::AccountId;
type Balance = <ink_env::DefaultEnvironment as Environment>::Balance;
type Hash = <ink_env::DefaultEnvironment as Environment>::Hash;
type BlockNumber = <ink_env::DefaultEnvironment as Environment>::BlockNumber;
type Timestamp = <ink_env::DefaultEnvironment as Environment>::Timestamp;
type ChainExtension = InvarchExtension;
}