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
use crate::transaction::Event;
use certified_vars::{Hash, HashTree};
use ic_kit::candid::{CandidType, Deserialize};
use ic_kit::ic;
use ic_kit::Principal;
use serde::Serialize;
pub type TransactionId = u64;
pub type IndexCanisterId = Principal;
pub type RootBucketId = Principal;
pub type BucketId = Principal;
pub type TokenContractId = Principal;
pub type UserId = Principal;
pub type EventHash = Hash;
#[derive(Serialize, Deserialize, CandidType)]
pub struct Witness {
#[serde(with = "serde_bytes")]
certificate: Vec<u8>,
#[serde(with = "serde_bytes")]
tree: Vec<u8>,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct GetTokenContractRootBucketArg {
pub canister: TokenContractId,
pub witness: bool,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct GetTokenContractRootBucketResponse {
pub canister: Option<RootBucketId>,
pub witness: Option<Witness>,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct GetUserRootBucketsArg {
pub user: UserId,
pub witness: bool,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct GetUserRootBucketsResponse {
pub contracts: Vec<RootBucketId>,
pub witness: Option<Witness>,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct WithWitnessArg {
pub witness: bool,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct GetIndexCanistersResponse {
pub canisters: Vec<IndexCanisterId>,
pub witness: Option<Witness>,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct GetNextCanistersResponse {
pub canisters: Vec<IndexCanisterId>,
pub witness: Option<Witness>,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct WithIdArg {
pub id: TransactionId,
pub witness: bool,
}
#[derive(Serialize, Deserialize, CandidType)]
pub enum GetTransactionResponse {
Delegate(BucketId, Option<Witness>),
Found(Option<Event>, Option<Witness>),
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct GetTransactionsArg {
pub page: Option<u32>,
pub witness: bool,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct GetTransactionsResponse {
pub data: Vec<Event>,
pub page: u32,
pub witness: Option<Witness>,
}
#[derive(Serialize, CandidType)]
pub struct GetTransactionsResponseBorrowed<'a> {
pub data: Vec<&'a Event>,
pub page: u32,
pub witness: Option<Witness>,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct GetUserTransactionsArg {
pub user: UserId,
pub page: Option<u32>,
pub witness: bool,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct GetTokenTransactionsArg {
pub token_id: u64,
pub page: Option<u32>,
pub witness: bool,
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct GetBucketResponse {
pub canister: BucketId,
pub witness: Option<Witness>,
}
impl From<HashTree<'_>> for Witness {
fn from(tree: HashTree) -> Self {
Self {
certificate: ic::data_certificate().unwrap(),
tree: serde_cbor::to_vec(&tree).unwrap(),
}
}
}
#[derive(Serialize, Deserialize, CandidType)]
pub struct BucketInitArgs {
pub contract: TokenContractId,
pub offset: u64,
pub next_canisters: Vec<BucketId>,
}