-
Notifications
You must be signed in to change notification settings - Fork 148
/
types.rs
243 lines (212 loc) · 5.52 KB
/
types.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
use serde::{Serialize, Deserialize, de::DeserializeOwned};
use codec::{Encode, Decode};
use sp_finality_grandpa::{AuthorityList, SetId};
use sp_runtime::{
generic::SignedBlock,
Justification,
OpaqueExtrinsic
};
use std::vec::Vec;
// Nod Runtime
use crate::runtimes::PhalaNodeRuntime;
pub type Runtime = PhalaNodeRuntime;
pub type Header = <Runtime as subxt::system::System>::Header;
pub type Hash = <Runtime as subxt::system::System>::Hash;
pub type OpaqueBlock = sp_runtime::generic::Block<Header, OpaqueExtrinsic>;
pub type OpaqueSignedBlock = SignedBlock<OpaqueBlock>;
pub type StorageProof = Vec<Vec<u8>>;
// pRuntime APIs
pub trait Resp {
type Resp: DeserializeOwned;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SignedResp {
pub payload: String,
pub status: String,
pub signature: String
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Nonce {
value: u32,
}
impl Nonce {
pub fn new() -> Nonce {
Nonce { value: rand::random::<u32>() }
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct RuntimeReq<T: Serialize> {
pub input: T,
pub nonce: Nonce,
}
impl<T: Serialize> RuntimeReq<T> {
pub fn new(input: T) -> Self {
Self { input: input, nonce: Nonce::new() }
}
}
// API: get_info
#[derive(Serialize, Deserialize, Debug)]
pub struct GetInfoReq {}
#[derive(Serialize, Deserialize, Debug)]
pub struct GetInfoResp {
pub headernum: phala_node_runtime::BlockNumber,
pub blocknum: phala_node_runtime::BlockNumber,
pub initialized: bool,
pub public_key: String,
pub ecdh_public_key: String,
}
impl Resp for GetInfoReq {
type Resp = GetInfoResp;
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum Payload {
Plain(String),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Query {
pub contract_id: u32,
pub nonce: u32,
pub request: ReqData,
}
#[derive(Serialize, Deserialize, Debug)]
pub enum ReqData {
PendingChainTransfer {sequence: u32}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct QueryReq {
pub query_payload: String,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct QueryResp {
pub plain: String,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct PendingChainTransfer {
pub pending_chain_transfer: TransferQueue,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct TransferQueue {
pub transfer_queue_b64: String,
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Encode, Decode)]
pub struct Transfer {
pub dest: [u8; 32],
pub amount: u128,
pub sequence: u32,
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Encode, Decode)]
pub struct TransferData {
pub data: Transfer,
pub signature: Vec<u8>,
}
impl Resp for QueryReq {
type Resp = QueryResp;
}
// API: init_runtime
#[derive(Serialize, Deserialize, Debug)]
pub struct InitRuntimeReq {
pub skip_ra: bool,
pub bridge_genesis_info_b64: String,
pub debug_set_key: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct InitRuntimeResp {
pub encoded_runtime_info: Vec<u8>,
pub public_key: String,
pub ecdh_public_key: String,
pub attestation: Option<InitRespAttestation>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct InitRespAttestation {
pub version: i32,
pub provider: String,
pub payload: AttestationReport,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct AttestationReport {
pub report: String,
pub signature: String,
pub signing_cert: String,
}
impl Resp for InitRuntimeReq {
type Resp = InitRuntimeResp;
}
#[derive(Encode, Decode)]
pub struct GenesisInfo {
pub header: Header,
pub validators: AuthorityList,
pub proof: StorageProof,
}
// API: sync_header
#[derive(Serialize, Deserialize, Debug)]
pub struct SyncHeaderReq {
pub headers_b64: Vec<String>,
pub authority_set_change_b64: Option<String>
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SyncHeaderResp {
pub synced_to: phala_node_runtime::BlockNumber
}
impl Resp for SyncHeaderReq {
type Resp = SyncHeaderResp;
}
#[derive(Encode, Decode, Clone, Debug)]
pub struct BlockWithEvents {
pub block: phala_node_runtime::SignedBlock,
pub events: Option<Vec<u8>>,
pub proof: Option<StorageProof>,
pub key: Option<Vec<u8>>,
}
#[derive(Encode, Decode, Clone, Debug)]
pub struct HeaderToSync {
pub header: phala_node_runtime::Header,
pub justification: Option<Justification>,
}
#[derive(Encode, Decode, Clone, PartialEq, Debug)]
pub struct AuthoritySet {
pub authority_set: AuthorityList,
pub set_id: SetId,
}
#[derive(Encode, Decode, Clone, PartialEq)]
pub struct AuthoritySetChange {
pub authority_set: AuthoritySet,
pub authority_proof: StorageProof,
}
// API: ping
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Encode, Decode)]
pub struct Heartbeat {
pub block_num: u32,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Encode, Decode)]
pub struct HeartbeatData {
pub data: Heartbeat,
pub signature: Vec<u8>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct PingReq {}
#[derive(Serialize, Deserialize, Debug)]
pub struct PingResp {
pub status: String,
pub encoded_data: String
}
impl Resp for PingReq {
type Resp = PingResp;
}
// API: dispatch_block
#[derive(Serialize, Deserialize, Debug)]
pub struct DispatchBlockReq {
pub blocks_b64: Vec<String>
}
#[derive(Serialize, Deserialize, Debug)]
pub struct DispatchBlockResp {
pub dispatched_to: phala_node_runtime::BlockNumber
}
impl Resp for DispatchBlockReq {
type Resp = DispatchBlockResp;
}