-
Notifications
You must be signed in to change notification settings - Fork 6
/
action.rs
160 lines (126 loc) · 4.43 KB
/
action.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
mod req {
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct Balance {
pub target: String,
}
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct KvPut {
pub key: String,
pub value: String,
}
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct KvGet {
pub key: String,
}
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct Transfer {
pub qty: u64,
pub target: String,
}
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct Evolve {
pub value: String,
}
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct ForeignRead {
pub contract_tx_id: String,
}
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct ForeignView {
pub contract_tx_id: String,
pub target: String,
}
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct ForeignWrite {
pub contract_tx_id: String,
pub qty: u64,
pub target: String,
}
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq)]
#[serde(rename_all = "camelCase", tag = "function")]
pub enum Action {
Balance(Balance),
Transfer(Transfer),
Evolve(Evolve),
ForeignView(ForeignView),
ForeignRead(ForeignRead),
ForeignWrite(ForeignWrite),
KvGet(KvGet),
KvPut(KvPut),
}
}
pub use req::*;
mod res {
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use strum_macros::EnumIter;
use crate::{error::PstError, state::PstState};
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct PstBalanceResult {
pub balance: u64,
pub ticker: String,
pub target: String,
}
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct PstKvGetResult {
pub key: String,
pub value: String,
}
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct PstForeignViewResult {
pub balance: u64,
pub ticker: String,
pub target: String,
}
#[derive(JsonSchema, Clone, PartialEq, Debug, Serialize, Deserialize, Hash, Eq, EnumIter)]
#[serde(rename_all = "camelCase", tag = "function")]
pub enum PstViewResponse {
BalanceResult(PstBalanceResult),
KvGetResult(PstKvGetResult),
ForeignViewResult(PstForeignViewResult),
}
pub type PstViewResult =
warp_contracts::handler_result::ViewResult<PstViewResponse, PstError>;
pub type PstWriteResult =
warp_contracts::handler_result::WriteResult<PstState, PstError>;
}
pub use res::*;
mod bindings {
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use strum_macros::EnumIter;
use super::*;
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, EnumIter)]
#[serde(rename_all = "camelCase", tag = "function")]
pub enum View {
Balance(Balance),
BalanceResult(PstBalanceResult),
ForeignView(ForeignView),
ForeignViewResult(PstForeignViewResult),
KvGet(KvGet),
KvGetResult(PstKvGetResult),
}
#[derive(JsonSchema, Clone, Debug, Serialize, Deserialize, Hash, PartialEq, Eq, EnumIter)]
#[serde(rename_all = "camelCase", tag = "function")]
pub enum WriteAction {
Transfer(Transfer),
Evolve(Evolve),
ForeignRead(ForeignRead),
ForeignWrite(ForeignWrite),
KvPut(KvPut),
}
}
pub use bindings::*;