This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 736
/
cache.rs
223 lines (192 loc) · 9.11 KB
/
cache.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
extern crate libc;
use api::{ErrorCode, CommandHandle, WalletHandle, PoolHandle};
use commands::{Command, CommandExecutor};
use commands::cache::CacheCommand;
use errors::prelude::*;
use utils::ctypes;
use self::libc::c_char;
/// Gets credential definition json data for specified credential definition id.
/// If data is present inside of cache, cached data is returned.
/// Otherwise data is fetched from the ledger and stored inside of cache for future use.
///
/// EXPERIMENTAL
///
/// #Params
/// command_handle: command handle to map callback to caller context.
/// pool_handle: pool handle (created by open_pool_ledger).
/// wallet_handle: wallet handle (created by open_wallet).
/// submitter_did: DID of the submitter stored in secured Wallet.
/// id: identifier of credential definition.
/// options_json:
/// {
/// forceUpdate: (optional, false by default) Force update of record in cache from the ledger,
/// }
/// cb: Callback that takes command result as parameter.
#[no_mangle]
pub extern fn indy_get_cred_def(command_handle: CommandHandle,
pool_handle: PoolHandle,
wallet_handle: WalletHandle,
submitter_did: *const c_char,
id: *const c_char,
options_json: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle,
err: ErrorCode,
cred_def_json: *const c_char)>) -> ErrorCode {
trace!("indy_get_cred_def: >>> pool_handle: {:?}, wallet_handle: {:?}, submitter_did: {:?}, id: {:?}, options_json: {:?}",
pool_handle, wallet_handle, submitter_did, id, options_json);
check_useful_c_str!(submitter_did, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(id, ErrorCode::CommonInvalidParam5);
check_useful_c_str!(options_json, ErrorCode::CommonInvalidParam6);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam7);
trace!("indy_get_cred_def: entities >>> pool_handle: {:?}, wallet_handle: {:?}, submitter_did: {:?}, id: {:?}, options_json: {:?}",
pool_handle, wallet_handle, submitter_did, id, options_json);
let result = CommandExecutor::instance()
.send(Command::Cache(CacheCommand::GetCredDef(
pool_handle,
wallet_handle,
submitter_did,
id,
options_json,
Box::new(move |result| {
let (err, cred_def_json) = prepare_result_1!(result, String::new());
trace!("indy_get_cred_def: cred_def_json: {:?}", cred_def_json);
let cred_def_json = ctypes::string_to_cstring(cred_def_json);
cb(command_handle, err, cred_def_json.as_ptr())
})
)));
let res = prepare_result!(result);
trace!("indy_get_schema: <<< res: {:?}", res);
res
}
/// Gets schema json data for specified schema id.
/// If data is present inside of cache, cached data is returned.
/// Otherwise data is fetched from the ledger and stored inside of cache for future use.
///
/// EXPERIMENTAL
///
/// #Params
/// command_handle: command handle to map callback to caller context.
/// pool_handle: pool handle (created by open_pool_ledger).
/// wallet_handle: wallet handle (created by open_wallet).
/// submitter_did: DID of the submitter stored in secured Wallet.
/// id: identifier of schema.
/// options_json:
/// {
/// noCache: (bool, optional, false by default) Skip usage of cache,
/// noUpdate: (bool, optional, false by default) Use only cached data, do not try to update.
/// noStore: (bool, optional, false by default) Skip storing fresh data if updated,
/// minFresh: (int, optional, -1 by default) Return cached data if not older than this many seconds. -1 means do not check age.
/// }
/// cb: Callback that takes command result as parameter.
#[no_mangle]
pub extern fn indy_get_schema(command_handle: CommandHandle,
pool_handle: PoolHandle,
wallet_handle: WalletHandle,
submitter_did: *const c_char,
id: *const c_char,
options_json: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle,
err: ErrorCode,
schema_json: *const c_char)>) -> ErrorCode {
trace!("indy_get_schema: >>> pool_handle: {:?}, wallet_handle: {:?}, submitter_did: {:?}, id: {:?}, options_json: {:?}",
pool_handle, wallet_handle, submitter_did, id, options_json);
check_useful_c_str!(submitter_did, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(id, ErrorCode::CommonInvalidParam5);
check_useful_c_str!(options_json, ErrorCode::CommonInvalidParam6);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam7);
trace!("indy_get_schema: entities >>> pool_handle: {:?}, wallet_handle: {:?}, submitter_did: {:?}, id: {:?}, options_json: {:?}",
pool_handle, wallet_handle, submitter_did, id, options_json);
let result = CommandExecutor::instance()
.send(Command::Cache(CacheCommand::GetSchema(
pool_handle,
wallet_handle,
submitter_did,
id,
options_json,
Box::new(move |result| {
let (err, schema_json) = prepare_result_1!(result, String::new());
trace!("indy_get_schema: schema_json: {:?}", schema_json);
let schema_json = ctypes::string_to_cstring(schema_json);
cb(command_handle, err, schema_json.as_ptr())
})
)));
let res = prepare_result!(result);
trace!("indy_get_schema: <<< res: {:?}", res);
res
}
/// Purge credential definition cache.
///
/// EXPERIMENTAL
///
/// #Params
/// command_handle: command handle to map callback to caller context.
/// wallet_handle: wallet handle (created by open_wallet).
/// options_json:
/// {
/// minFresh: (int, optional, -1 by default) Purge cached data if older than this many seconds. -1 means purge all.
/// }
/// cb: Callback that takes command result as parameter.
#[no_mangle]
pub extern fn indy_purge_cred_def_cache(command_handle: CommandHandle,
wallet_handle: WalletHandle,
options_json: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle,
err: ErrorCode)>) -> ErrorCode {
trace!("indy_purge_cred_def_cache: >>> wallet_handle: {:?}, options_json: {:?}",
wallet_handle, options_json);
check_useful_c_str!(options_json, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
trace!("indy_purge_cred_def_cache: entities >>> wallet_handle: {:?}, options_json: {:?}",
wallet_handle, options_json);
let result = CommandExecutor::instance()
.send(Command::Cache(CacheCommand::PurgeCredDefCache(
wallet_handle,
options_json,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_purge_cred_def_cache:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_purge_cred_def_cache: <<< res: {:?}", res);
res
}
/// Purge schema cache.
///
/// EXPERIMENTAL
///
/// #Params
/// command_handle: command handle to map callback to caller context.
/// wallet_handle: wallet handle (created by open_wallet).
/// options_json:
/// {
/// maxAge: (int, optional, -1 by default) Purge cached data if older than this many seconds. -1 means purge all.
/// }
/// cb: Callback that takes command result as parameter.
#[no_mangle]
pub extern fn indy_purge_schema_cache(command_handle: CommandHandle,
wallet_handle: WalletHandle,
options_json: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle,
err: ErrorCode)>) -> ErrorCode {
trace!("indy_purge_schema_cache: >>> wallet_handle: {:?}, options_json: {:?}",
wallet_handle, options_json);
check_useful_c_str!(options_json, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
trace!("indy_purge_schema_cache: entities >>> wallet_handle: {:?}, options_json: {:?}",
wallet_handle, options_json);
let result = CommandExecutor::instance()
.send(Command::Cache(CacheCommand::PurgeSchemaCache(
wallet_handle,
options_json,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_purge_schema_cache:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_purge_schema_cache: <<< res: {:?}", res);
res
}