-
Notifications
You must be signed in to change notification settings - Fork 316
/
lib.rs
99 lines (89 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
87
88
89
90
91
92
93
94
95
96
97
98
99
#![cfg_attr(not(feature = "std"), no_std)]
use num_enum::{IntoPrimitive, TryFromPrimitive};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_core::{RuntimeDebug, H160};
use xcm::{latest::Weight, prelude::*};
pub const XCM_EXTENSION_ID: u16 = 04;
#[repr(u16)]
#[derive(TryFromPrimitive, IntoPrimitive)]
pub enum Command {
PrepareExecute = 0,
Execute = 1,
ValidateSend = 2,
Send = 3,
NewQuery = 4,
TakeResponse = 5,
PalletAccountId = 6,
}
/// Type of XCM Response Query
#[derive(RuntimeDebug, Clone, Eq, PartialEq, Encode, Decode, MaxEncodedLen, TypeInfo)]
// #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum QueryType<AccountId> {
// No callback, store the response for manual polling
NoCallback,
// Call Wasm contract's method on recieving response
// It expects the contract method to have following signature
// - (query_id: QueryId, responder: Multilocation, response: Response)
WASMContractCallback {
contract_id: AccountId,
selector: [u8; 4],
},
// Call Evm contract's method on recieving response
// It expects the contract method to have following signature
// - (query_id: QueryId, responder: Multilocation, response: Response)
EVMContractCallback {
contract_id: H160,
selector: [u8; 4],
},
}
/// Query config
#[derive(RuntimeDebug, Clone, Eq, PartialEq, Encode, Decode, MaxEncodedLen, TypeInfo)]
// #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct QueryConfig<AccountId, BlockNumber> {
// query type
pub query_type: QueryType<AccountId>,
// blocknumber after which query will be expire
pub timeout: BlockNumber,
}
#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct ValidateSendInput {
pub dest: VersionedMultiLocation,
pub xcm: VersionedXcm<()>,
}
pub struct PreparedExecution<Call> {
pub xcm: Xcm<Call>,
pub weight: Weight,
}
pub struct ValidatedSend {
pub dest: MultiLocation,
pub xcm: Xcm<()>,
}
#[macro_export]
macro_rules! create_error_enum {
($vis:vis $type_name:ident) => {
#[repr(u32)]
#[derive(
::core::cmp::PartialEq,
::core::cmp::Eq,
::core::marker::Copy,
::core::clone::Clone,
// crate name mismatch, 'parity-scale-codec' is crate name but in ink! contract
// it is usually renamed to `scale`
Encode,
Decode,
::core::fmt::Debug,
::num_enum::IntoPrimitive,
::num_enum::FromPrimitive,
)]
#[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))]
$vis enum $type_name {
Success = 0,
NoResponse = 1,
#[num_enum(default)]
RuntimeError = 2,
}
};
}
create_error_enum!(pub Error);