rust_libindy_wrapper/ledger.rs
1use {ErrorCode, IndyHandle};
2
3use std::ffi::CString;
4use std::time::Duration;
5use std::ptr::null;
6
7use native::ledger;
8use native::{ResponseEmptyCB,
9 ResponseStringCB,
10 ResponseStringStringCB,
11 ResponseStringStringU64CB};
12
13use utils::results::ResultHandler;
14use utils::callbacks::ClosureHandler;
15
16pub struct Ledger {}
17
18impl Ledger {
19 /// Signs and submits request message to validator pool.
20 ///
21 /// Adds submitter information to passed request json, signs it with submitter
22 /// sign key (see Crypto::sign), and sends signed request message
23 /// to validator pool (see Pool::write_request).
24 ///
25 /// # Arguments
26 /// * `pool_handle` - pool handle (created by Pool::open_ledger).
27 /// * `wallet_handle` - wallet handle (created by Wallet::open).
28 /// * `submitter_did` - Id of Identity stored in secured Wallet.
29 /// * `request_json` - Request data json.
30 ///
31 /// # Returns
32 /// Request result as json.
33 pub fn sign_and_submit_request(pool_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, request_json: &str) -> Result<String, ErrorCode> {
34 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
35
36 let err = Ledger::_sign_and_submit_request(command_handle, pool_handle, wallet_handle, submitter_did, request_json, cb);
37
38 ResultHandler::one(err, receiver)
39 }
40
41 /// Signs and submits request message to validator pool.
42 ///
43 /// Adds submitter information to passed request json, signs it with submitter
44 /// sign key (see Crypto::sign), and sends signed request message
45 /// to validator pool (see Pool::write_request).
46 ///
47 /// # Arguments
48 /// * `pool_handle` - pool handle (created by Pool::open_ledger).
49 /// * `wallet_handle` - wallet handle (created by Wallet::open).
50 /// * `submitter_did` - Id of Identity stored in secured Wallet.
51 /// * `request_json` - Request data json.
52 /// * `timeout` - the maximum time this function waits for a response
53 ///
54 /// # Returns
55 /// Request result as json.
56 pub fn sign_and_submit_request_timeout(pool_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, request_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
57 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
58
59 let err = Ledger::_sign_and_submit_request(command_handle, pool_handle, wallet_handle, submitter_did, request_json, cb);
60
61 ResultHandler::one_timeout(err, receiver, timeout)
62 }
63
64 /// Signs and submits request message to validator pool.
65 ///
66 /// Adds submitter information to passed request json, signs it with submitter
67 /// sign key (see Crypto::sign), and sends signed request message
68 /// to validator pool (see Pool::write_request).
69 ///
70 /// # Arguments
71 /// * `pool_handle` - pool handle (created by Pool::open_ledger).
72 /// * `wallet_handle` - wallet handle (created by Wallet::open).
73 /// * `submitter_did` - Id of Identity stored in secured Wallet.
74 /// * `request_json` - Request data json.
75 /// * `closure` - the closure that is called when finished
76 ///
77 /// # Returns
78 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
79 pub fn sign_and_submit_request_async<F: 'static>(pool_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, request_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
80 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
81
82 Ledger::_sign_and_submit_request(command_handle, pool_handle, wallet_handle, submitter_did, request_json, cb)
83 }
84
85 fn _sign_and_submit_request(command_handle: IndyHandle, pool_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, request_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
86 let submitter_did = c_str!(submitter_did);
87 let request_json = c_str!(request_json);
88
89 ErrorCode::from(unsafe {
90 ledger::indy_sign_and_submit_request(command_handle,
91 pool_handle,
92 wallet_handle,
93 submitter_did.as_ptr(),
94 request_json.as_ptr(),
95 cb)
96 })
97 }
98
99 /// Publishes request message to validator pool (no signing, unlike Ledger::sign_and_submit_request).
100 ///
101 /// The request is sent to the validator pool as is. It's assumed that it's already prepared.
102 ///
103 /// # Arguments
104 /// * `pool_handle` - pool handle (created by Pool::open_ledger).
105 /// * `request_json` - Request data json.
106 ///
107 /// # Returns
108 /// Request result as json.
109 pub fn submit_request(pool_handle: IndyHandle, request_json: &str) -> Result<String, ErrorCode> {
110 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
111
112 let err = Ledger::_submit_request(command_handle, pool_handle, request_json, cb);
113
114 ResultHandler::one(err, receiver)
115 }
116
117 /// Publishes request message to validator pool (no signing, unlike Ledger::sign_and_submit_request).
118 ///
119 /// The request is sent to the validator pool as is. It's assumed that it's already prepared.
120 ///
121 /// # Arguments
122 /// * `pool_handle` - pool handle (created by Pool::open_ledger).
123 /// * `request_json` - Request data json.
124 /// * `timeout` - the maximum time this function waits for a response
125 ///
126 /// # Returns
127 /// Request result as json.
128 pub fn submit_request_timeout(pool_handle: IndyHandle, request_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
129 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
130
131 let err = Ledger::_submit_request(command_handle, pool_handle, request_json, cb);
132
133 ResultHandler::one_timeout(err, receiver, timeout)
134 }
135
136 /// Publishes request message to validator pool (no signing, unlike Ledger::sign_and_submit_request).
137 ///
138 /// The request is sent to the validator pool as is. It's assumed that it's already prepared.
139 ///
140 /// # Arguments
141 /// * `pool_handle` - pool handle (created by Pool::open_ledger).
142 /// * `request_json` - Request data json.
143 /// * `closure` - the closure that is called when finished
144 ///
145 /// # Returns
146 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
147 pub fn submit_request_async<F: 'static>(pool_handle: IndyHandle, request_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
148 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
149
150 Ledger::_submit_request(command_handle, pool_handle, request_json, cb)
151 }
152
153 fn _submit_request(command_handle: IndyHandle, pool_handle: IndyHandle, request_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
154 let request_json = c_str!(request_json);
155
156 ErrorCode::from(unsafe { ledger::indy_submit_request(command_handle, pool_handle, request_json.as_ptr(), cb) })
157 }
158
159 pub fn submit_action(pool_handle: IndyHandle, request_json: &str, nodes: &str, wait_timeout: i32) -> Result<String, ErrorCode> {
160 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
161
162 let err = Ledger::_submit_action(command_handle, pool_handle, request_json, nodes, wait_timeout, cb);
163
164 ResultHandler::one(err, receiver)
165 }
166
167 /// * `timeout` - the maximum time this function waits for a response
168 pub fn submit_action_timeout(pool_handle: IndyHandle, request_json: &str, nodes: &str, wait_timeout: i32, timeout: Duration) -> Result<String, ErrorCode> {
169 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
170
171 let err = Ledger::_submit_action(command_handle, pool_handle, request_json, nodes, wait_timeout, cb);
172
173 ResultHandler::one_timeout(err, receiver, timeout)
174 }
175
176 /// * `closure` - the closure that is called when finished
177 ///
178 /// # Returns
179 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
180 pub fn submit_action_async<F: 'static>(pool_handle: IndyHandle, request_json: &str, nodes: &str, wait_timeout: i32, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
181 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
182
183 Ledger::_submit_action(command_handle, pool_handle, request_json, nodes, wait_timeout, cb)
184 }
185
186 fn _submit_action(command_handle: IndyHandle, pool_handle: IndyHandle, request_json: &str, nodes: &str, wait_timeout: i32, cb: Option<ResponseStringCB>) -> ErrorCode {
187 let request_json = c_str!(request_json);
188 let nodes = c_str!(nodes);
189
190 ErrorCode::from(unsafe {
191 ledger::indy_submit_action(command_handle, pool_handle, request_json.as_ptr(), nodes.as_ptr(), wait_timeout, cb)
192 })
193 }
194
195 /// Signs request message.
196 ///
197 /// Adds submitter information to passed request json, signs it with submitter
198 /// sign key (see Crypto::sign).
199 ///
200 /// # Arguments
201 /// * `wallet_handle` - wallet handle (created by Wallet::open).
202 /// * `submitter_did` - Id of Identity stored in secured Wallet.
203 /// * `request_json` - Request data json.
204 ///
205 /// # Returns
206 /// Signed request json.
207 pub fn sign_request(wallet_handle: IndyHandle, submitter_did: &str, request_json: &str) -> Result<String, ErrorCode> {
208 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
209
210 let err = Ledger::_sign_request(command_handle, wallet_handle, submitter_did, request_json, cb);
211
212 ResultHandler::one(err, receiver)
213 }
214
215 /// Signs request message.
216 ///
217 /// Adds submitter information to passed request json, signs it with submitter
218 /// sign key (see Crypto::sign).
219 ///
220 /// # Arguments
221 /// * `wallet_handle` - wallet handle (created by Wallet::open).
222 /// * `submitter_did` - Id of Identity stored in secured Wallet.
223 /// * `request_json` - Request data json.
224 /// * `timeout` - the maximum time this function waits for a response
225 ///
226 /// # Returns
227 /// Signed request json.
228 pub fn sign_request_timeout(wallet_handle: IndyHandle, submitter_did: &str, request_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
229 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
230
231 let err = Ledger::_sign_request(command_handle, wallet_handle, submitter_did, request_json, cb);
232
233 ResultHandler::one_timeout(err, receiver, timeout)
234 }
235
236 /// Signs request message.
237 ///
238 /// Adds submitter information to passed request json, signs it with submitter
239 /// sign key (see Crypto::sign).
240 ///
241 /// # Arguments
242 /// * `wallet_handle` - wallet handle (created by Wallet::open).
243 /// * `submitter_did` - Id of Identity stored in secured Wallet.
244 /// * `request_json` - Request data json.
245 /// * `closure` - the closure that is called when finished
246 ///
247 /// # Returns
248 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
249 pub fn sign_request_async<F: 'static>(wallet_handle: IndyHandle, submitter_did: &str, request_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
250 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
251
252 Ledger::_sign_request(command_handle, wallet_handle, submitter_did, request_json, cb)
253 }
254
255 fn _sign_request(command_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, request_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
256 let submitter_did = c_str!(submitter_did);
257 let request_json = c_str!(request_json);
258
259 ErrorCode::from(unsafe { ledger::indy_sign_request(command_handle, wallet_handle, submitter_did.as_ptr(), request_json.as_ptr(), cb) })
260 }
261
262 /// Multi signs request message.
263 ///
264 /// Adds submitter information to passed request json, signs it with submitter
265 /// sign key (see Crypto::sign).
266 ///
267 /// # Arguments
268 /// * `wallet_handle` - wallet handle (created by Wallet::open).
269 /// * `submitter_did` - Id of Identity stored in secured Wallet.
270 /// * `request_json` - Request data json.
271 ///
272 /// # Returns
273 /// Signed request json.
274 pub fn multi_sign_request(wallet_handle: IndyHandle, submitter_did: &str, request_json: &str) -> Result<String, ErrorCode> {
275 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
276
277 let err = Ledger::_multi_sign_request(command_handle, wallet_handle, submitter_did, request_json, cb);
278
279 ResultHandler::one(err, receiver)
280 }
281
282 /// Multi signs request message.
283 ///
284 /// Adds submitter information to passed request json, signs it with submitter
285 /// sign key (see Crypto::sign).
286 ///
287 /// # Arguments
288 /// * `wallet_handle` - wallet handle (created by Wallet::open).
289 /// * `submitter_did` - Id of Identity stored in secured Wallet.
290 /// * `request_json` - Request data json.
291 /// * `timeout` - the maximum time this function waits for a response
292 ///
293 /// # Returns
294 /// Signed request json.
295 pub fn multi_sign_request_timeout(wallet_handle: IndyHandle, submitter_did: &str, request_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
296 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
297
298 let err = Ledger::_multi_sign_request(command_handle, wallet_handle, submitter_did, request_json, cb);
299
300 ResultHandler::one_timeout(err, receiver, timeout)
301 }
302
303 /// Multi signs request message.
304 ///
305 /// Adds submitter information to passed request json, signs it with submitter
306 /// sign key (see Crypto::sign).
307 ///
308 /// # Arguments
309 /// * `wallet_handle` - wallet handle (created by Wallet::open).
310 /// * `submitter_did` - Id of Identity stored in secured Wallet.
311 /// * `request_json` - Request data json.
312 /// * `closure` - the closure that is called when finished
313 ///
314 /// # Returns
315 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
316 pub fn multi_sign_request_async<F: 'static>(wallet_handle: IndyHandle, submitter_did: &str, request_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
317 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
318
319 Ledger::_multi_sign_request(command_handle, wallet_handle, submitter_did, request_json, cb)
320 }
321
322 fn _multi_sign_request(command_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, request_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
323 let submitter_did = c_str!(submitter_did);
324 let request_json = c_str!(request_json);
325
326 ErrorCode::from(unsafe { ledger::indy_multi_sign_request(command_handle, wallet_handle, submitter_did.as_ptr(), request_json.as_ptr(), cb) })
327 }
328
329 /// Builds a request to get a DDO.
330 ///
331 /// # Arguments
332 /// * `submitter_did` - Id of Identity stored in secured Wallet.
333 /// * `target_did` - Id of Identity stored in secured Wallet.
334 ///
335 /// # Returns
336 /// Request result as json.
337 pub fn build_get_ddo_request(submitter_did: &str, target_did: &str) -> Result<String, ErrorCode> {
338 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
339
340 let err = Ledger::_build_get_ddo_request(command_handle, submitter_did, target_did, cb);
341
342 ResultHandler::one(err, receiver)
343 }
344
345 /// Builds a request to get a DDO.
346 ///
347 /// # Arguments
348 /// * `submitter_did` - Id of Identity stored in secured Wallet.
349 /// * `target_did` - Id of Identity stored in secured Wallet.
350 /// * `timeout` - the maximum time this function waits for a response
351 ///
352 /// # Returns
353 /// Request result as json.
354 pub fn build_get_ddo_request_timeout(submitter_did: &str, target_did: &str, timeout: Duration) -> Result<String, ErrorCode> {
355 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
356
357 let err = Ledger::_build_get_ddo_request(command_handle, submitter_did, target_did, cb);
358
359 ResultHandler::one_timeout(err, receiver, timeout)
360 }
361
362 /// Builds a request to get a DDO.
363 ///
364 /// # Arguments
365 /// * `submitter_did` - Id of Identity stored in secured Wallet.
366 /// * `target_did` - Id of Identity stored in secured Wallet.
367 /// * `closure` - the closure that is called when finished
368 ///
369 /// # Returns
370 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
371 pub fn build_get_ddo_request_async<F: 'static>(submitter_did: &str, target_did: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
372 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
373
374 Ledger::_build_get_ddo_request(command_handle, submitter_did, target_did, cb)
375 }
376
377 fn _build_get_ddo_request(command_handle: IndyHandle, submitter_did: &str, target_did: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
378 let submitter_did = c_str!(submitter_did);
379 let target_did = c_str!(target_did);
380
381 ErrorCode::from(unsafe { ledger::indy_build_get_ddo_request(command_handle, submitter_did.as_ptr(), target_did.as_ptr(), cb) })
382 }
383
384 /// Builds a NYM request. Request to create a new NYM record for a specific user.
385 ///
386 /// # Arguments
387 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
388 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
389 /// * `verkey` - Target identity verification key as base58-encoded string.
390 /// * `data`
391 /// * `role` - Role of a user NYM record:
392 /// null (common USER)
393 /// TRUSTEE
394 /// STEWARD
395 /// TRUST_ANCHOR
396 /// empty string to reset role
397 ///
398 /// # Returns
399 /// Request result as json.
400 pub fn build_nym_request(submitter_did: &str, target_did: &str, verkey: Option<&str>, data: Option<&str>, role: Option<&str>) -> Result<String, ErrorCode> {
401 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
402
403 let err = Ledger::_build_nym_request(command_handle, submitter_did, target_did, verkey, data, role, cb);
404
405 ResultHandler::one(err, receiver)
406 }
407
408 /// Builds a NYM request. Request to create a new NYM record for a specific user.
409 ///
410 /// # Arguments
411 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
412 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
413 /// * `verkey` - Target identity verification key as base58-encoded string.
414 /// * `data`
415 /// * `role` - Role of a user NYM record:
416 /// null (common USER)
417 /// TRUSTEE
418 /// STEWARD
419 /// TRUST_ANCHOR
420 /// empty string to reset role
421 /// * `timeout` - the maximum time this function waits for a response
422 ///
423 /// # Returns
424 /// Request result as json.
425 pub fn build_nym_request_timeout(submitter_did: &str, target_did: &str, verkey: Option<&str>, data: Option<&str>, role: Option<&str>, timeout: Duration) -> Result<String, ErrorCode> {
426 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
427
428 let err = Ledger::_build_nym_request(command_handle, submitter_did, target_did, verkey, data, role, cb);
429
430 ResultHandler::one_timeout(err, receiver, timeout)
431 }
432
433 /// Builds a NYM request. Request to create a new NYM record for a specific user.
434 ///
435 /// # Arguments
436 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
437 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
438 /// * `verkey` - Target identity verification key as base58-encoded string.
439 /// * `data`
440 /// * `role` - Role of a user NYM record:
441 /// null (common USER)
442 /// TRUSTEE
443 /// STEWARD
444 /// TRUST_ANCHOR
445 /// empty string to reset role
446 /// * `closure` - the closure that is called when finished
447 ///
448 /// # Returns
449 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
450 pub fn build_nym_request_async<F: 'static>(submitter_did: &str, target_did: &str, verkey: Option<&str>, data: Option<&str>, role: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
451 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
452
453 Ledger::_build_nym_request(command_handle, submitter_did, target_did, verkey, data, role, cb)
454 }
455
456 fn _build_nym_request(command_handle: IndyHandle,
457 submitter_did: &str,
458 target_did: &str,
459 verkey: Option<&str>,
460 data: Option<&str>,
461 role: Option<&str>,
462 cb: Option<ResponseStringCB>) -> ErrorCode {
463 let submitter_did = c_str!(submitter_did);
464 let target_did = c_str!(target_did);
465
466 let verkey_str = opt_c_str!(verkey);
467 let data_str = opt_c_str!(data);
468 let role_str = opt_c_str!(role);
469
470 ErrorCode::from(unsafe {
471 ledger::indy_build_nym_request(command_handle,
472 submitter_did.as_ptr(),
473 target_did.as_ptr(),
474 opt_c_ptr!(verkey, verkey_str),
475 opt_c_ptr!(data, data_str),
476 opt_c_ptr!(role, role_str),
477 cb)
478 })
479 }
480
481 /// Builds a GET_NYM request. Request to get information about a DID (NYM).
482 ///
483 /// # Arguments
484 /// * `submitter_did` - DID of the read request sender.
485 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
486 ///
487 /// # Returns
488 /// Request result as json.
489 pub fn build_get_nym_request(submitter_did: &str, target_did: &str) -> Result<String, ErrorCode> {
490 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
491
492 let err = Ledger::_build_get_nym_request(command_handle, submitter_did, target_did, cb);
493
494 ResultHandler::one(err, receiver)
495 }
496
497 /// Builds a GET_NYM request. Request to get information about a DID (NYM).
498 ///
499 /// # Arguments
500 /// * `submitter_did` - DID of the read request sender.
501 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
502 /// * `timeout` - the maximum time this function waits for a response
503 ///
504 /// # Returns
505 /// Request result as json.
506 pub fn build_get_nym_request_timeout(submitter_did: &str, target_did: &str, timeout: Duration) -> Result<String, ErrorCode> {
507 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
508
509 let err = Ledger::_build_get_nym_request(command_handle, submitter_did, target_did, cb);
510
511 ResultHandler::one_timeout(err, receiver, timeout)
512 }
513
514 /// Builds a GET_NYM request. Request to get information about a DID (NYM).
515 ///
516 /// # Arguments
517 /// * `submitter_did` - DID of the read request sender.
518 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
519 /// * `closure` - the closure that is called when finished
520 ///
521 /// # Returns
522 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
523 pub fn build_get_nym_request_async<F: 'static>(submitter_did: &str, target_did: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
524 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
525
526 Ledger::_build_get_nym_request(command_handle, submitter_did, target_did, cb)
527 }
528
529 fn _build_get_nym_request(command_handle: IndyHandle, submitter_did: &str, target_did: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
530 let submitter_did = c_str!(submitter_did);
531 let target_did = c_str!(target_did);
532
533 ErrorCode::from(unsafe { ledger::indy_build_get_nym_request(command_handle, submitter_did.as_ptr(), target_did.as_ptr(), cb) })
534 }
535
536 /// Builds a GET_TXN request. Request to get any transaction by its seq_no.
537 ///
538 /// # Arguments
539 /// * `submitter_did` - DID of the request submitter.
540 /// * `ledger_type` - (Optional) type of the ledger the requested transaction belongs to:
541 /// DOMAIN - used default,
542 /// POOL,
543 /// CONFIG
544 /// * `seq_no` - seq_no of transaction in ledger.
545 ///
546 /// # Returns
547 /// Request result as json.
548 pub fn build_get_txn_request(submitter_did: &str, ledger_type: Option<&str>, seq_no: i32) -> Result<String, ErrorCode> {
549 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
550
551 let err = Ledger::_build_get_txn_request(command_handle, submitter_did, ledger_type, seq_no, cb);
552
553 ResultHandler::one(err, receiver)
554 }
555
556 /// Builds a GET_TXN request. Request to get any transaction by its seq_no.
557 ///
558 /// # Arguments
559 /// * `submitter_did` - DID of the request submitter.
560 /// * `seq_no` - seq_no of transaction in ledger.
561 /// * `ledger_type` - (Optional) type of the ledger the requested transaction belongs to:
562 /// DOMAIN - used default,
563 /// POOL,
564 /// CONFIG
565 /// * `timeout` - the maximum time this function waits for a response
566 ///
567 /// # Returns
568 /// Request result as json.
569 pub fn build_get_txn_request_timeout(submitter_did: &str, ledger_type: Option<&str>, seq_no: i32, timeout: Duration) -> Result<String, ErrorCode> {
570 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
571
572 let err = Ledger::_build_get_txn_request(command_handle, submitter_did, ledger_type, seq_no, cb);
573
574 ResultHandler::one_timeout(err, receiver, timeout)
575 }
576
577 /// Builds a GET_TXN request. Request to get any transaction by its seq_no.
578 ///
579 /// # Arguments
580 /// * `submitter_did` - DID of the request submitter.
581 /// * `seq_no` - seq_no of transaction in ledger.
582 /// * `ledger_type` - (Optional) type of the ledger the requested transaction belongs to:
583 /// DOMAIN - used default,
584 /// POOL,
585 /// CONFIG
586 /// * `closure` - the closure that is called when finished
587 ///
588 /// # Returns
589 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
590 pub fn build_get_txn_request_async<F: 'static>(submitter_did: &str, ledger_type: Option<&str>, seq_no: i32, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
591 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
592
593 Ledger::_build_get_txn_request(command_handle, submitter_did, ledger_type, seq_no, cb)
594 }
595
596 fn _build_get_txn_request(command_handle: IndyHandle, submitter_did: &str, ledger_type: Option<&str>, seq_no: i32, cb: Option<ResponseStringCB>) -> ErrorCode {
597 let submitter_did = c_str!(submitter_did);
598 let ledger_type_str = opt_c_str!(ledger_type);
599
600 ErrorCode::from(unsafe { ledger::indy_build_get_txn_request(command_handle, submitter_did.as_ptr(), opt_c_ptr!(ledger_type, ledger_type_str), seq_no, cb) })
601 }
602
603 /// Builds an ATTRIB request. Request to add attribute to a NYM record.
604 ///
605 /// # Arguments
606 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
607 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
608 /// * `hash` - (Optional) Hash of attribute data.
609 /// * `raw` - (Optional) Json, where key is attribute name and value is attribute value.
610 /// * `enc` - (Optional) Encrypted value attribute data.
611 ///
612 /// # Returns
613 /// Request result as json.
614 pub fn build_attrib_request(submitter_did: &str, target_did: &str, hash: Option<&str>, raw: Option<&str>, enc: Option<&str>) -> Result<String, ErrorCode> {
615 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
616
617 let err = Ledger::_build_attrib_request(command_handle, submitter_did, target_did, hash, raw, enc, cb);
618
619 ResultHandler::one(err, receiver)
620 }
621
622 /// Builds an ATTRIB request. Request to add attribute to a NYM record.
623 ///
624 /// # Arguments
625 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
626 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
627 /// * `hash` - (Optional) Hash of attribute data.
628 /// * `raw` - (Optional) Json, where key is attribute name and value is attribute value.
629 /// * `enc` - (Optional) Encrypted value attribute data.
630 /// * `timeout` - the maximum time this function waits for a response
631 ///
632 /// # Returns
633 /// Request result as json.
634 pub fn build_attrib_request_timeout(submitter_did: &str, target_did: &str, hash: Option<&str>, raw: Option<&str>, enc: Option<&str>, timeout: Duration) -> Result<String, ErrorCode> {
635 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
636
637 let err = Ledger::_build_attrib_request(command_handle, submitter_did, target_did, hash, raw, enc, cb);
638
639 ResultHandler::one_timeout(err, receiver, timeout)
640 }
641
642 /// Builds an ATTRIB request. Request to add attribute to a NYM record.
643 ///
644 /// # Arguments
645 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
646 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
647 /// * `hash` - (Optional) Hash of attribute data.
648 /// * `raw` - (Optional) Json, where key is attribute name and value is attribute value.
649 /// * `enc` - (Optional) Encrypted value attribute data.
650 /// * `closure` - the closure that is called when finished
651 ///
652 /// # Returns
653 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
654 pub fn build_attrib_request_async<F: 'static>(submitter_did: &str, target_did: &str, hash: Option<&str>, raw: Option<&str>, enc: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
655 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
656
657 Ledger::_build_attrib_request(command_handle, submitter_did, target_did, hash, raw, enc, cb)
658 }
659
660 fn _build_attrib_request(command_handle: IndyHandle, submitter_did: &str, target_did: &str, hash: Option<&str>, raw: Option<&str>, enc: Option<&str>, cb: Option<ResponseStringCB>) -> ErrorCode {
661 let submitter_did = c_str!(submitter_did);
662 let target_did = c_str!(target_did);
663
664 let hash_str = opt_c_str!(hash);
665 let raw_str = opt_c_str!(raw);
666 let enc_str = opt_c_str!(enc);
667
668 ErrorCode::from(unsafe {
669 ledger::indy_build_attrib_request(command_handle,
670 submitter_did.as_ptr(),
671 target_did.as_ptr(),
672 opt_c_ptr!(hash, hash_str),
673 opt_c_ptr!(raw, raw_str),
674 opt_c_ptr!(enc, enc_str),
675 cb)
676 })
677 }
678
679 /// Builds a GET_ATTRIB request. Request to get information about an Attribute for the specified DID.
680 ///
681 /// # Arguments
682 /// * `submitter_did` - DID of the read request sender.
683 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
684 /// * `raw` - (Optional) Requested attribute name.
685 /// * `hash` - (Optional) Requested attribute hash.
686 /// * `enc` - (Optional) Requested attribute encrypted value.
687 ///
688 /// # Returns
689 /// Request result as json.
690 pub fn build_get_attrib_request(submitter_did: &str, target_did: &str, raw: Option<&str>, hash: Option<&str>, enc: Option<&str>) -> Result<String, ErrorCode> {
691 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
692
693 let err = Ledger::_build_get_attrib_request(command_handle, submitter_did, target_did, raw, hash, enc, cb);
694
695 ResultHandler::one(err, receiver)
696 }
697
698 /// Builds a GET_ATTRIB request. Request to get information about an Attribute for the specified DID.
699 ///
700 /// # Arguments
701 /// * `submitter_did` - DID of the read request sender.
702 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
703 /// * `raw` - (Optional) Requested attribute name.
704 /// * `hash` - (Optional) Requested attribute hash.
705 /// * `enc` - (Optional) Requested attribute encrypted value.
706 /// * `timeout` - the maximum time this function waits for a response
707 ///
708 /// # Returns
709 /// Request result as json.
710 pub fn build_get_attrib_request_timeout(submitter_did: &str, target_did: &str, raw: Option<&str>, hash: Option<&str>, enc: Option<&str>, timeout: Duration) -> Result<String, ErrorCode> {
711 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
712
713 let err = Ledger::_build_get_attrib_request(command_handle, submitter_did, target_did, raw, hash, enc, cb);
714
715 ResultHandler::one_timeout(err, receiver, timeout)
716 }
717
718 /// Builds a GET_ATTRIB request. Request to get information about an Attribute for the specified DID.
719 ///
720 /// # Arguments
721 /// * `submitter_did` - DID of the read request sender.
722 /// * `target_did` - Target DID as base58-encoded string for 16 or 32 bit DID value.
723 /// * `raw` - (Optional) Requested attribute name.
724 /// * `hash` - (Optional) Requested attribute hash.
725 /// * `enc` - (Optional) Requested attribute encrypted value.
726 /// * `closure` - the closure that is called when finished
727 ///
728 /// # Returns
729 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
730 pub fn build_get_attrib_request_async<F: 'static>(submitter_did: &str, target_did: &str, raw: Option<&str>, hash: Option<&str>, enc: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
731 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
732
733 Ledger::_build_get_attrib_request(command_handle, submitter_did, target_did, raw, hash, enc, cb)
734 }
735
736 fn _build_get_attrib_request(command_handle: IndyHandle, submitter_did: &str, target_did: &str, raw: Option<&str>, hash: Option<&str>, enc: Option<&str>, cb: Option<ResponseStringCB>) -> ErrorCode {
737 let submitter_did = c_str!(submitter_did);
738 let target_did = c_str!(target_did);
739
740 let raw_str = opt_c_str!(raw);
741 let hash_str = opt_c_str!(hash);
742 let enc_str = opt_c_str!(enc);
743
744 ErrorCode::from(unsafe {
745 ledger::indy_build_get_attrib_request(command_handle,
746 submitter_did.as_ptr(),
747 target_did.as_ptr(),
748 opt_c_ptr!(raw, raw_str),
749 opt_c_ptr!(hash, hash_str),
750 opt_c_ptr!(enc, enc_str),
751 cb)
752 })
753 }
754
755 /// Builds a SCHEMA request. Request to add Credential's schema.
756 ///
757 /// # Arguments
758 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
759 /// * `data` - Credential schema.
760 /// {
761 /// id: identifier of schema
762 /// attrNames: array of attribute name strings
763 /// name: Schema's name string
764 /// version: Schema's version string,
765 /// ver: Version of the Schema json
766 /// }
767 ///
768 /// # Returns
769 /// Request result as json.
770 pub fn build_schema_request(submitter_did: &str, data: &str) -> Result<String, ErrorCode> {
771 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
772
773 let err = Ledger::_build_schema_request(command_handle, submitter_did, data, cb);
774
775 ResultHandler::one(err, receiver)
776 }
777
778 /// Builds a SCHEMA request. Request to add Credential's schema.
779 ///
780 /// # Arguments
781 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
782 /// * `data` - Credential schema.
783 /// {
784 /// id: identifier of schema
785 /// attrNames: array of attribute name strings
786 /// name: Schema's name string
787 /// version: Schema's version string,
788 /// ver: Version of the Schema json
789 /// }
790 /// * `timeout` - the maximum time this function waits for a response
791 ///
792 /// # Returns
793 /// Request result as json.
794 pub fn build_schema_request_timeout(submitter_did: &str, data: &str, timeout: Duration) -> Result<String, ErrorCode> {
795 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
796
797 let err = Ledger::_build_schema_request(command_handle, submitter_did, data, cb);
798
799 ResultHandler::one_timeout(err, receiver, timeout)
800 }
801
802 /// Builds a SCHEMA request. Request to add Credential's schema.
803 ///
804 /// # Arguments
805 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
806 /// * `data` - Credential schema.
807 /// {
808 /// id: identifier of schema
809 /// attrNames: array of attribute name strings
810 /// name: Schema's name string
811 /// version: Schema's version string,
812 /// ver: Version of the Schema json
813 /// }
814 /// * `closure` - the closure that is called when finished
815 ///
816 /// # Returns
817 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
818 pub fn build_schema_request_async<F: 'static>(submitter_did: &str, data: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
819 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
820
821 Ledger::_build_schema_request(command_handle, submitter_did, data, cb)
822 }
823
824 fn _build_schema_request(command_handle: IndyHandle, submitter_did: &str, data: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
825 let submitter_did = c_str!(submitter_did);
826 let data = c_str!(data);
827
828 ErrorCode::from(unsafe { ledger::indy_build_schema_request(command_handle, submitter_did.as_ptr(), data.as_ptr(), cb) })
829 }
830
831 /// Builds a GET_SCHEMA request. Request to get Credential's Schema.
832 ///
833 /// # Arguments
834 /// * `submitter_did` - DID of the read request sender.
835 /// * `id` - Schema ID in ledger
836 ///
837 /// # Returns
838 /// Request result as json.
839 pub fn build_get_schema_request(submitter_did: &str, id: &str) -> Result<String, ErrorCode> {
840 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
841
842 let err = Ledger::_build_get_schema_request(command_handle, submitter_did, id, cb);
843
844 ResultHandler::one(err, receiver)
845 }
846
847 /// Builds a GET_SCHEMA request. Request to get Credential's Schema.
848 ///
849 /// # Arguments
850 /// * `submitter_did` - DID of the read request sender.
851 /// * `id` - Schema ID in ledger
852 /// * `timeout` - the maximum time this function waits for a response
853 ///
854 /// # Returns
855 /// Request result as json.
856 pub fn build_get_schema_request_timeout(submitter_did: &str, id: &str, timeout: Duration) -> Result<String, ErrorCode> {
857 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
858
859 let err = Ledger::_build_get_schema_request(command_handle, submitter_did, id, cb);
860
861 ResultHandler::one_timeout(err, receiver, timeout)
862 }
863
864 /// Builds a GET_SCHEMA request. Request to get Credential's Schema.
865 ///
866 /// # Arguments
867 /// * `submitter_did` - DID of the read request sender.
868 /// * `id` - Schema ID in ledger
869 /// * `closure` - the closure that is called when finished
870 ///
871 /// # Returns
872 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
873 pub fn build_get_schema_request_async<F: 'static>(submitter_did: &str, id: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
874 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
875
876 Ledger::_build_get_schema_request(command_handle, submitter_did, id, cb)
877 }
878
879 fn _build_get_schema_request(command_handle: IndyHandle, submitter_did: &str, id: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
880 let submitter_did = c_str!(submitter_did);
881 let id = c_str!(id);
882
883 ErrorCode::from(unsafe { ledger::indy_build_get_schema_request(command_handle, submitter_did.as_ptr(), id.as_ptr(), cb) })
884 }
885
886 /// Parse a GET_SCHEMA response to get Schema in the format compatible with Anoncreds API.
887 ///
888 /// # Arguments
889 /// * `get_schema_response` - response of GET_SCHEMA request.
890 ///
891 /// # Returns
892 /// Schema Id and Schema json.
893 /// {
894 /// id: identifier of schema
895 /// attrNames: array of attribute name strings
896 /// name: Schema's name string
897 /// version: Schema's version string
898 /// ver: Version of the Schema json
899 /// }
900 pub fn parse_get_schema_response(get_schema_response: &str) -> Result<(String, String), ErrorCode> {
901 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
902
903 let err = Ledger::_parse_get_schema_response(command_handle, get_schema_response, cb);
904
905 ResultHandler::two(err, receiver)
906 }
907
908 /// Parse a GET_SCHEMA response to get Schema in the format compatible with Anoncreds API.
909 ///
910 /// # Arguments
911 /// * `get_schema_response` - response of GET_SCHEMA request.
912 /// * `timeout` - the maximum time this function waits for a response
913 ///
914 /// # Returns
915 /// Schema Id and Schema json.
916 /// {
917 /// id: identifier of schema
918 /// attrNames: array of attribute name strings
919 /// name: Schema's name string
920 /// version: Schema's version string
921 /// ver: Version of the Schema json
922 /// }
923 pub fn parse_get_schema_response_timeout(get_schema_response: &str, timeout: Duration) -> Result<(String, String), ErrorCode> {
924 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
925
926 let err = Ledger::_parse_get_schema_response(command_handle, get_schema_response, cb);
927
928 ResultHandler::two_timeout(err, receiver, timeout)
929 }
930
931 /// Parse a GET_SCHEMA response to get Schema in the format compatible with Anoncreds API.
932 ///
933 /// # Arguments
934 /// * `get_schema_response` - response of GET_SCHEMA request.
935 /// * `closure` - the closure that is called when finished
936 ///
937 /// # Returns
938 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
939 pub fn parse_get_schema_response_async<F: 'static>(get_schema_response: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
940 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));
941
942 Ledger::_parse_get_schema_response(command_handle, get_schema_response, cb)
943 }
944
945 fn _parse_get_schema_response(command_handle: IndyHandle, get_schema_response: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
946 let get_schema_response = c_str!(get_schema_response);
947
948 ErrorCode::from(unsafe { ledger::indy_parse_get_schema_response(command_handle, get_schema_response.as_ptr(), cb) })
949 }
950
951 /// Builds an CRED_DEF request. Request to add a Credential Definition (in particular, public key),
952 /// that Issuer creates for a particular Credential Schema.
953 ///
954 /// # Arguments
955 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
956 /// * `data` - credential definition json
957 /// {
958 /// id: string - identifier of credential definition
959 /// schemaId: string - identifier of stored in ledger schema
960 /// type: string - type of the credential definition. CL is the only supported type now.
961 /// tag: string - allows to distinct between credential definitions for the same issuer and schema
962 /// value: Dictionary with Credential Definition's data: {
963 /// primary: primary credential public key,
964 /// Optional<revocation>: revocation credential public key
965 /// },
966 /// ver: Version of the CredDef json
967 /// }
968 ///
969 /// # Returns
970 /// Request result as json.
971 pub fn build_cred_def_request(submitter_did: &str, data: &str) -> Result<String, ErrorCode> {
972 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
973
974 let err = Ledger::_build_cred_def_request(command_handle, submitter_did, data, cb);
975
976 ResultHandler::one(err, receiver)
977 }
978
979 /// Builds an CRED_DEF request. Request to add a Credential Definition (in particular, public key),
980 /// that Issuer creates for a particular Credential Schema.
981 ///
982 /// # Arguments
983 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
984 /// * `data` - credential definition json
985 /// {
986 /// id: string - identifier of credential definition
987 /// schemaId: string - identifier of stored in ledger schema
988 /// type: string - type of the credential definition. CL is the only supported type now.
989 /// tag: string - allows to distinct between credential definitions for the same issuer and schema
990 /// value: Dictionary with Credential Definition's data: {
991 /// primary: primary credential public key,
992 /// Optional<revocation>: revocation credential public key
993 /// },
994 /// ver: Version of the CredDef json
995 /// }
996 /// * `timeout` - the maximum time this function waits for a response
997 ///
998 /// # Returns
999 /// Request result as json.
1000 pub fn build_cred_def_request_timeout(submitter_did: &str, data: &str, timeout: Duration) -> Result<String, ErrorCode> {
1001 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1002
1003 let err = Ledger::_build_cred_def_request(command_handle, submitter_did, data, cb);
1004
1005 ResultHandler::one_timeout(err, receiver, timeout)
1006 }
1007
1008 /// Builds an CRED_DEF request. Request to add a Credential Definition (in particular, public key),
1009 /// that Issuer creates for a particular Credential Schema.
1010 ///
1011 /// # Arguments
1012 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1013 /// * `data` - credential definition json
1014 /// {
1015 /// id: string - identifier of credential definition
1016 /// schemaId: string - identifier of stored in ledger schema
1017 /// type: string - type of the credential definition. CL is the only supported type now.
1018 /// tag: string - allows to distinct between credential definitions for the same issuer and schema
1019 /// value: Dictionary with Credential Definition's data: {
1020 /// primary: primary credential public key,
1021 /// Optional<revocation>: revocation credential public key
1022 /// },
1023 /// ver: Version of the CredDef json
1024 /// }
1025 /// * `closure` - the closure that is called when finished
1026 ///
1027 /// # Returns
1028 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1029 pub fn build_cred_def_request_async<F: 'static>(submitter_did: &str, data: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1030 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1031
1032 Ledger::_build_cred_def_request(command_handle, submitter_did, data, cb)
1033 }
1034
1035 fn _build_cred_def_request(command_handle: IndyHandle, submitter_did: &str, data: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1036 let submitter_did = c_str!(submitter_did);
1037 let data = c_str!(data);
1038
1039 ErrorCode::from(unsafe { ledger::indy_build_cred_def_request(command_handle, submitter_did.as_ptr(), data.as_ptr(), cb) })
1040 }
1041
1042 /// Builds a GET_CRED_DEF request. Request to get a Credential Definition (in particular, public key),
1043 /// that Issuer creates for a particular Credential Schema.
1044 ///
1045 /// # Arguments
1046 /// * `submitter_did` - DID of the read request sender.
1047 /// * `id` - Credential Definition ID in ledger.
1048 ///
1049 /// # Returns
1050 /// Request result as json.
1051 pub fn build_get_cred_def_request(submitter_did: &str, id: &str) -> Result<String, ErrorCode> {
1052 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1053
1054 let err = Ledger::_build_get_cred_def_request(command_handle, submitter_did, id, cb);
1055
1056 ResultHandler::one(err, receiver)
1057 }
1058
1059 /// Builds a GET_CRED_DEF request. Request to get a Credential Definition (in particular, public key),
1060 /// that Issuer creates for a particular Credential Schema.
1061 ///
1062 /// # Arguments
1063 /// * `submitter_did` - DID of the read request sender.
1064 /// * `id` - Credential Definition ID in ledger.
1065 /// * `timeout` - the maximum time this function waits for a response
1066 ///
1067 /// # Returns
1068 /// Request result as json.
1069 pub fn build_get_cred_def_request_timeout(submitter_did: &str, id: &str, timeout: Duration) -> Result<String, ErrorCode> {
1070 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1071
1072 let err = Ledger::_build_get_cred_def_request(command_handle, submitter_did, id, cb);
1073
1074 ResultHandler::one_timeout(err, receiver, timeout)
1075 }
1076
1077 /// Builds a GET_CRED_DEF request. Request to get a Credential Definition (in particular, public key),
1078 /// that Issuer creates for a particular Credential Schema.
1079 ///
1080 /// # Arguments
1081 /// * `submitter_did` - DID of the read request sender.
1082 /// * `id` - Credential Definition ID in ledger.
1083 /// * `closure` - the closure that is called when finished
1084 ///
1085 /// # Returns
1086 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1087 pub fn build_get_cred_def_request_async<F: 'static>(submitter_did: &str, id: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1088 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1089
1090 Ledger::_build_get_cred_def_request(command_handle, submitter_did, id, cb)
1091 }
1092
1093 fn _build_get_cred_def_request(command_handle: IndyHandle, submitter_did: &str, id: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1094 let submitter_did = c_str!(submitter_did);
1095 let id = c_str!(id);
1096
1097 ErrorCode::from(unsafe { ledger::indy_build_get_cred_def_request(command_handle, submitter_did.as_ptr(), id.as_ptr(), cb) })
1098 }
1099
1100 /// Parse a GET_CRED_DEF response to get Credential Definition in the format compatible with Anoncreds API.
1101 ///
1102 /// # Arguments
1103 /// * `get_cred_def_response` - response of GET_CRED_DEF request.
1104 ///
1105 /// # Returns
1106 /// Credential Definition Id and Credential Definition json.
1107 /// {
1108 /// id: string - identifier of credential definition
1109 /// schemaId: string - identifier of stored in ledger schema
1110 /// type: string - type of the credential definition. CL is the only supported type now.
1111 /// tag: string - allows to distinct between credential definitions for the same issuer and schema
1112 /// value: Dictionary with Credential Definition's data: {
1113 /// primary: primary credential public key,
1114 /// Optional<revocation>: revocation credential public key
1115 /// },
1116 /// ver: Version of the Credential Definition json
1117 /// }
1118 pub fn parse_get_cred_def_response(get_cred_def_response: &str) -> Result<(String, String), ErrorCode> {
1119 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
1120
1121 let err = Ledger::_parse_get_cred_def_response(command_handle, get_cred_def_response, cb);
1122
1123 ResultHandler::two(err, receiver)
1124 }
1125
1126 /// Parse a GET_CRED_DEF response to get Credential Definition in the format compatible with Anoncreds API.
1127 ///
1128 /// # Arguments
1129 /// * `get_cred_def_response` - response of GET_CRED_DEF request.
1130 /// * `timeout` - the maximum time this function waits for a response
1131 ///
1132 /// # Returns
1133 /// Credential Definition Id and Credential Definition json.
1134 /// {
1135 /// id: string - identifier of credential definition
1136 /// schemaId: string - identifier of stored in ledger schema
1137 /// type: string - type of the credential definition. CL is the only supported type now.
1138 /// tag: string - allows to distinct between credential definitions for the same issuer and schema
1139 /// value: Dictionary with Credential Definition's data: {
1140 /// primary: primary credential public key,
1141 /// Optional<revocation>: revocation credential public key
1142 /// },
1143 /// ver: Version of the Credential Definition json
1144 /// }
1145 pub fn parse_get_cred_def_response_timeout(get_cred_def_response: &str, timeout: Duration) -> Result<(String, String), ErrorCode> {
1146 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
1147
1148 let err = Ledger::_parse_get_cred_def_response(command_handle, get_cred_def_response, cb);
1149
1150 ResultHandler::two_timeout(err, receiver, timeout)
1151 }
1152
1153 /// Parse a GET_CRED_DEF response to get Credential Definition in the format compatible with Anoncreds API.
1154 ///
1155 /// # Arguments
1156 /// * `get_cred_def_response` - response of GET_CRED_DEF request.
1157 /// * `closure` - the closure that is called when finished
1158 ///
1159 /// # Returns
1160 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1161 pub fn parse_get_cred_def_response_async<F: 'static>(get_cred_def_response: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
1162 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));
1163
1164 Ledger::_parse_get_cred_def_response(command_handle, get_cred_def_response, cb)
1165 }
1166
1167 fn _parse_get_cred_def_response(command_handle: IndyHandle, get_cred_def_response: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
1168 let get_cred_def_response = c_str!(get_cred_def_response);
1169
1170 ErrorCode::from(unsafe { ledger::indy_parse_get_cred_def_response(command_handle, get_cred_def_response.as_ptr(), cb) })
1171 }
1172
1173 /// Builds a NODE request. Request to add a new node to the pool, or updates existing in the pool.
1174 ///
1175 /// # Arguments
1176 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1177 /// * `target_did` - Target Node's DID. It differs from submitter_did field.
1178 /// * `data` - Data associated with the Node: {
1179 /// alias: string - Node's alias
1180 /// blskey: string - (Optional) BLS multi-signature key as base58-encoded string.
1181 /// client_ip: string - (Optional) Node's client listener IP address.
1182 /// client_port: string - (Optional) Node's client listener port.
1183 /// node_ip: string - (Optional) The IP address other Nodes use to communicate with this Node.
1184 /// node_port: string - (Optional) The port other Nodes use to communicate with this Node.
1185 /// services: array<string> - (Optional) The service of the Node. VALIDATOR is the only supported one now.
1186 /// }
1187 ///
1188 /// # Returns
1189 /// Request result as json.
1190 pub fn build_node_request(submitter_did: &str, target_did: &str, data: &str) -> Result<String, ErrorCode> {
1191 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1192
1193 let err = Ledger::_build_node_request(command_handle, submitter_did, target_did, data, cb);
1194
1195 ResultHandler::one(err, receiver)
1196 }
1197
1198 /// Builds a NODE request. Request to add a new node to the pool, or updates existing in the pool.
1199 ///
1200 /// # Arguments
1201 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1202 /// * `target_did` - Target Node's DID. It differs from submitter_did field.
1203 /// * `data` - Data associated with the Node: {
1204 /// alias: string - Node's alias
1205 /// blskey: string - (Optional) BLS multi-signature key as base58-encoded string.
1206 /// client_ip: string - (Optional) Node's client listener IP address.
1207 /// client_port: string - (Optional) Node's client listener port.
1208 /// node_ip: string - (Optional) The IP address other Nodes use to communicate with this Node.
1209 /// node_port: string - (Optional) The port other Nodes use to communicate with this Node.
1210 /// services: array<string> - (Optional) The service of the Node. VALIDATOR is the only supported one now.
1211 /// }
1212 /// * `timeout` - the maximum time this function waits for a response
1213 ///
1214 /// # Returns
1215 /// Request result as json.
1216 pub fn build_node_request_timeout(submitter_did: &str, target_did: &str, data: &str, timeout: Duration) -> Result<String, ErrorCode> {
1217 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1218
1219 let err = Ledger::_build_node_request(command_handle, submitter_did, target_did, data, cb);
1220
1221 ResultHandler::one_timeout(err, receiver, timeout)
1222 }
1223
1224 /// Builds a NODE request. Request to add a new node to the pool, or updates existing in the pool.
1225 ///
1226 /// # Arguments
1227 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1228 /// * `target_did` - Target Node's DID. It differs from submitter_did field.
1229 /// * `data` - Data associated with the Node: {
1230 /// alias: string - Node's alias
1231 /// blskey: string - (Optional) BLS multi-signature key as base58-encoded string.
1232 /// client_ip: string - (Optional) Node's client listener IP address.
1233 /// client_port: string - (Optional) Node's client listener port.
1234 /// node_ip: string - (Optional) The IP address other Nodes use to communicate with this Node.
1235 /// node_port: string - (Optional) The port other Nodes use to communicate with this Node.
1236 /// services: array<string> - (Optional) The service of the Node. VALIDATOR is the only supported one now.
1237 /// }
1238 /// * `closure` - the closure that is called when finished
1239 ///
1240 /// # Returns
1241 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1242 pub fn build_node_request_async<F: 'static>(submitter_did: &str, target_did: &str, data: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1243 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1244
1245 Ledger::_build_node_request(command_handle, submitter_did, target_did, data, cb)
1246 }
1247
1248 fn _build_node_request(command_handle: IndyHandle, submitter_did: &str, target_did: &str, data: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1249 let submitter_did = c_str!(submitter_did);
1250 let target_did = c_str!(target_did);
1251 let data = c_str!(data);
1252
1253 ErrorCode::from(unsafe { ledger::indy_build_node_request(command_handle, submitter_did.as_ptr(), target_did.as_ptr(), data.as_ptr(), cb) })
1254 }
1255
1256 /// Builds a GET_VALIDATOR_INFO request.
1257 ///
1258 /// # Arguments
1259 /// * `submitter_did` - Id of Identity stored in secured Wallet.
1260 ///
1261 /// # Returns
1262 /// Request result as json.
1263 pub fn build_get_validator_info_request(submitter_did: &str) -> Result<String, ErrorCode> {
1264 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1265
1266 let err = Ledger::_build_get_validator_info_request(command_handle, submitter_did, cb);
1267
1268 ResultHandler::one(err, receiver)
1269 }
1270
1271 /// Builds a GET_VALIDATOR_INFO request.
1272 ///
1273 /// # Arguments
1274 /// * `submitter_did` - Id of Identity stored in secured Wallet.
1275 /// * `timeout` - the maximum time this function waits for a response
1276 ///
1277 /// # Returns
1278 /// Request result as json.
1279 pub fn build_get_validator_info_request_timeout(submitter_did: &str, timeout: Duration) -> Result<String, ErrorCode> {
1280 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1281
1282 let err = Ledger::_build_get_validator_info_request(command_handle, submitter_did, cb);
1283
1284 ResultHandler::one_timeout(err, receiver, timeout)
1285 }
1286
1287 /// Builds a GET_VALIDATOR_INFO request.
1288 ///
1289 /// # Arguments
1290 /// * `submitter_did` - Id of Identity stored in secured Wallet.
1291 /// * `closure` - the closure that is called when finished
1292 ///
1293 /// # Returns
1294 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1295 pub fn build_get_validator_info_request_async<F: 'static>(submitter_did: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1296 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1297
1298 Ledger::_build_get_validator_info_request(command_handle, submitter_did, cb)
1299 }
1300
1301 fn _build_get_validator_info_request(command_handle: IndyHandle, submitter_did: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1302 let submitter_did = c_str!(submitter_did);
1303
1304 ErrorCode::from(unsafe {
1305 ledger::indy_build_get_validator_info_request(command_handle, submitter_did.as_ptr(), cb)
1306 })
1307 }
1308
1309 /// Builds a POOL_CONFIG request. Request to change Pool's configuration.
1310 ///
1311 /// # Arguments
1312 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1313 /// * `writes` - Whether any write requests can be processed by the pool
1314 /// (if false, then pool goes to read-only state). True by default.
1315 /// * `force` - Whether we should apply transaction (for example, move pool to read-only state)
1316 /// without waiting for consensus of this transaction.
1317 ///
1318 /// # Returns
1319 /// Request result as json.
1320 pub fn build_pool_config_request(submitter_did: &str, writes: bool, force: bool) -> Result<String, ErrorCode> {
1321 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1322
1323 let err = Ledger::_build_pool_config_request(command_handle, submitter_did, writes, force, cb);
1324
1325 ResultHandler::one(err, receiver)
1326 }
1327
1328 /// Builds a POOL_CONFIG request. Request to change Pool's configuration.
1329 ///
1330 /// # Arguments
1331 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1332 /// * `writes` - Whether any write requests can be processed by the pool
1333 /// (if false, then pool goes to read-only state). True by default.
1334 /// * `force` - Whether we should apply transaction (for example, move pool to read-only state)
1335 /// without waiting for consensus of this transaction.
1336 /// * `timeout` - the maximum time this function waits for a response
1337 ///
1338 /// # Returns
1339 /// Request result as json.
1340 pub fn build_pool_config_request_timeout(submitter_did: &str, writes: bool, force: bool, timeout: Duration) -> Result<String, ErrorCode> {
1341 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1342
1343 let err = Ledger::_build_pool_config_request(command_handle, submitter_did, writes, force, cb);
1344
1345 ResultHandler::one_timeout(err, receiver, timeout)
1346 }
1347
1348 /// Builds a POOL_CONFIG request. Request to change Pool's configuration.
1349 ///
1350 /// # Arguments
1351 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1352 /// * `writes` - Whether any write requests can be processed by the pool
1353 /// (if false, then pool goes to read-only state). True by default.
1354 /// * `force` - Whether we should apply transaction (for example, move pool to read-only state)
1355 /// without waiting for consensus of this transaction.
1356 /// * `closure` - the closure that is called when finished
1357 ///
1358 /// # Returns
1359 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1360 pub fn build_pool_config_request_async<F: 'static>(submitter_did: &str, writes: bool, force: bool, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1361 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1362
1363 Ledger::_build_pool_config_request(command_handle, submitter_did, writes, force, cb)
1364 }
1365
1366 fn _build_pool_config_request(command_handle: IndyHandle, submitter_did: &str, writes: bool, force: bool, cb: Option<ResponseStringCB>) -> ErrorCode {
1367 let submitter_did = c_str!(submitter_did);
1368
1369 ErrorCode::from(unsafe { ledger::indy_build_pool_config_request(command_handle, submitter_did.as_ptr(), writes, force, cb) })
1370 }
1371
1372 /// Builds a POOL_RESTART request.
1373 ///
1374 /// # Arguments
1375 /// * `submitter_did` - Id of Identity stored in secured Wallet.
1376 /// * `action`-
1377 /// * `datetime`-
1378 ///
1379 /// # Returns
1380 /// Request result as json.
1381 pub fn build_pool_restart_request(submitter_did: &str, action: &str, datetime: Option<&str>) -> Result<String, ErrorCode> {
1382 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1383
1384 let err = Ledger::_build_pool_restart_request(command_handle, submitter_did, action, datetime, cb);
1385
1386 ResultHandler::one(err, receiver)
1387 }
1388
1389 /// Builds a POOL_RESTART request.
1390 ///
1391 /// # Arguments
1392 /// * `submitter_did` - Id of Identity stored in secured Wallet.
1393 /// * `action`-
1394 /// * `datetime`-
1395 /// * `timeout` - the maximum time this function waits for a response
1396 ///
1397 /// # Returns
1398 /// Request result as json.
1399 pub fn build_pool_restart_request_timeout(submitter_did: &str, action: &str, datetime: Option<&str>, timeout: Duration) -> Result<String, ErrorCode> {
1400 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1401
1402 let err = Ledger::_build_pool_restart_request(command_handle, submitter_did, action, datetime, cb);
1403
1404 ResultHandler::one_timeout(err, receiver, timeout)
1405 }
1406
1407 /// Builds a POOL_RESTART request.
1408 ///
1409 /// # Arguments
1410 /// * `submitter_did` - Id of Identity stored in secured Wallet.
1411 /// * `action`-
1412 /// * `datetime`-
1413 /// * `closure` - the closure that is called when finished
1414 ///
1415 /// # Returns
1416 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1417 pub fn build_pool_restart_request_async<F: 'static>(submitter_did: &str, action: &str, datetime: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1418 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1419
1420 Ledger::_build_pool_restart_request(command_handle, submitter_did, action, datetime, cb)
1421 }
1422
1423 fn _build_pool_restart_request(command_handle: IndyHandle, submitter_did: &str, action: &str, datetime: Option<&str>, cb: Option<ResponseStringCB>) -> ErrorCode {
1424 let submitter_did = c_str!(submitter_did);
1425 let action = c_str!(action);
1426 let datetime = opt_c_str!(datetime);
1427
1428 ErrorCode::from(unsafe {
1429 ledger::indy_build_pool_restart_request(command_handle,
1430 submitter_did.as_ptr(),
1431 action.as_ptr(),
1432 datetime.as_ptr(),
1433 cb)
1434 })
1435 }
1436
1437 /// Builds a POOL_UPGRADE request. Request to upgrade the Pool (sent by Trustee).
1438 /// It upgrades the specified Nodes (either all nodes in the Pool, or some specific ones).
1439 ///
1440 /// # Arguments
1441 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1442 /// * `name` - Human-readable name for the upgrade.
1443 /// * `version` - The version of indy-node package we perform upgrade to.
1444 /// Must be greater than existing one (or equal if reinstall flag is True).
1445 /// * `action` - Either start or cancel.
1446 /// * `sha256` - sha256 hash of the package.
1447 /// * `upgrade_timeout` - (Optional) Limits upgrade time on each Node.
1448 /// * `schedule` - (Optional) Schedule of when to perform upgrade on each node. Map Node DIDs to upgrade time.
1449 /// * `justification` - (Optional) justification string for this particular Upgrade.
1450 /// * `reinstall` - Whether it's allowed to re-install the same version. False by default.
1451 /// * `force` - Whether we should apply transaction (schedule Upgrade) without waiting
1452 /// for consensus of this transaction.
1453 ///
1454 /// # Returns
1455 /// Request result as json.
1456 pub fn build_pool_upgrade_request(submitter_did: &str,
1457 name: &str,
1458 version: &str,
1459 action: &str,
1460 sha256: &str,
1461 upgrade_timeout: Option<u32>,
1462 schedule: Option<&str>,
1463 justification: Option<&str>,
1464 reinstall: bool,
1465 force: bool,
1466 package: Option<&str>) -> Result<String, ErrorCode> {
1467 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1468
1469 let err = Ledger::_build_pool_upgrade_request(command_handle, submitter_did, name, version, action, sha256, upgrade_timeout, schedule, justification, reinstall, force, package, cb);
1470
1471 ResultHandler::one(err, receiver)
1472 }
1473
1474 /// Builds a POOL_UPGRADE request. Request to upgrade the Pool (sent by Trustee).
1475 /// It upgrades the specified Nodes (either all nodes in the Pool, or some specific ones).
1476 ///
1477 /// # Arguments
1478 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1479 /// * `name` - Human-readable name for the upgrade.
1480 /// * `version` - The version of indy-node package we perform upgrade to.
1481 /// Must be greater than existing one (or equal if reinstall flag is True).
1482 /// * `action` - Either start or cancel.
1483 /// * `sha256` - sha256 hash of the package.
1484 /// * `upgrade_timeout` - (Optional) Limits upgrade time on each Node.
1485 /// * `schedule` - (Optional) Schedule of when to perform upgrade on each node. Map Node DIDs to upgrade time.
1486 /// * `justification` - (Optional) justification string for this particular Upgrade.
1487 /// * `reinstall` - Whether it's allowed to re-install the same version. False by default.
1488 /// * `force` - Whether we should apply transaction (schedule Upgrade) without waiting
1489 /// for consensus of this transaction.
1490 /// * `timeout` - the maximum time this function waits for a response
1491 ///
1492 /// # Returns
1493 /// Request result as json.
1494 pub fn build_pool_upgrade_request_timeout(submitter_did: &str,
1495 name: &str,
1496 version: &str,
1497 action: &str,
1498 sha256: &str,
1499 upgrade_timeout: Option<u32>,
1500 schedule: Option<&str>,
1501 justification: Option<&str>,
1502 reinstall: bool,
1503 force: bool,
1504 package: Option<&str>,
1505 timeout: Duration) -> Result<String, ErrorCode> {
1506 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1507
1508 let err = Ledger::_build_pool_upgrade_request(command_handle, submitter_did, name, version, action, sha256, upgrade_timeout, schedule, justification, reinstall, force, package, cb);
1509
1510 ResultHandler::one_timeout(err, receiver, timeout)
1511 }
1512
1513 /// Builds a POOL_UPGRADE request. Request to upgrade the Pool (sent by Trustee).
1514 /// It upgrades the specified Nodes (either all nodes in the Pool, or some specific ones).
1515 ///
1516 /// # Arguments
1517 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1518 /// * `name` - Human-readable name for the upgrade.
1519 /// * `version` - The version of indy-node package we perform upgrade to.
1520 /// Must be greater than existing one (or equal if reinstall flag is True).
1521 /// * `action` - Either start or cancel.
1522 /// * `sha256` - sha256 hash of the package.
1523 /// * `upgrade_timeout` - (Optional) Limits upgrade time on each Node.
1524 /// * `schedule` - (Optional) Schedule of when to perform upgrade on each node. Map Node DIDs to upgrade time.
1525 /// * `justification` - (Optional) justification string for this particular Upgrade.
1526 /// * `reinstall` - Whether it's allowed to re-install the same version. False by default.
1527 /// * `force` - Whether we should apply transaction (schedule Upgrade) without waiting
1528 /// for consensus of this transaction.
1529 /// * `closure` - the closure that is called when finished
1530 ///
1531 /// # Returns
1532 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1533 pub fn build_pool_upgrade_request_async<F: 'static>(submitter_did: &str,
1534 name: &str,
1535 version: &str,
1536 action: &str,
1537 sha256: &str,
1538 upgrade_timeout: Option<u32>,
1539 schedule: Option<&str>,
1540 justification: Option<&str>,
1541 reinstall: bool,
1542 force: bool,
1543 package: Option<&str>,
1544 closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1545 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1546
1547 Ledger::_build_pool_upgrade_request(command_handle, submitter_did, name, version, action, sha256, upgrade_timeout, schedule, justification, reinstall, force, package, cb)
1548 }
1549
1550 fn _build_pool_upgrade_request(command_handle: IndyHandle,
1551 submitter_did: &str,
1552 name: &str,
1553 version: &str,
1554 action: &str,
1555 sha256: &str,
1556 upgrade_timeout: Option<u32>,
1557 schedule: Option<&str>,
1558 justification: Option<&str>,
1559 reinstall: bool,
1560 force: bool,
1561 package: Option<&str>,
1562 cb: Option<ResponseStringCB>) -> ErrorCode {
1563 let submitter_did = c_str!(submitter_did);
1564 let name = c_str!(name);
1565 let version = c_str!(version);
1566 let action = c_str!(action);
1567 let sha256 = c_str!(sha256);
1568 let upgrade_timeout = upgrade_timeout.map(|t| t as i32).unwrap_or(-1);
1569
1570 let schedule_str = opt_c_str!(schedule);
1571 let justification_str = opt_c_str!(justification);
1572 let package_str = opt_c_str!(package);
1573
1574 ErrorCode::from(unsafe {
1575 ledger::indy_build_pool_upgrade_request(command_handle,
1576 submitter_did.as_ptr(),
1577 name.as_ptr(),
1578 version.as_ptr(),
1579 action.as_ptr(),
1580 sha256.as_ptr(),
1581 upgrade_timeout,
1582 opt_c_ptr!(schedule, schedule_str),
1583 opt_c_ptr!(justification, justification_str),
1584 reinstall,
1585 force,
1586 opt_c_ptr!(package, package_str),
1587 cb)
1588 })
1589 }
1590
1591 /// Builds a REVOC_REG_DEF request. Request to add the definition of revocation registry
1592 /// to an exists credential definition.
1593 ///
1594 /// # Arguments
1595 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1596 /// * `data` - Revocation Registry data:
1597 /// {
1598 /// "id": string - ID of the Revocation Registry,
1599 /// "revocDefType": string - Revocation Registry type (only CL_ACCUM is supported for now),
1600 /// "tag": string - Unique descriptive ID of the Registry,
1601 /// "credDefId": string - ID of the corresponding CredentialDefinition,
1602 /// "value": Registry-specific data {
1603 /// "issuanceType": string - Type of Issuance(ISSUANCE_BY_DEFAULT or ISSUANCE_ON_DEMAND),
1604 /// "maxCredNum": number - Maximum number of credentials the Registry can serve.
1605 /// "tailsHash": string - Hash of tails.
1606 /// "tailsLocation": string - Location of tails file.
1607 /// "publicKeys": <public_keys> - Registry's public key.
1608 /// },
1609 /// "ver": string - version of revocation registry definition json.
1610 /// }
1611 ///
1612 /// # Returns
1613 /// Request result as json.
1614 pub fn build_revoc_reg_def_request(submitter_did: &str, data: &str) -> Result<String, ErrorCode> {
1615 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1616
1617 let err = Ledger::_build_revoc_reg_def_request(command_handle, submitter_did, data, cb);
1618
1619 ResultHandler::one(err, receiver)
1620 }
1621
1622 /// Builds a REVOC_REG_DEF request. Request to add the definition of revocation registry
1623 /// to an exists credential definition.
1624 ///
1625 /// # Arguments
1626 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1627 /// * `data` - Revocation Registry data:
1628 /// {
1629 /// "id": string - ID of the Revocation Registry,
1630 /// "revocDefType": string - Revocation Registry type (only CL_ACCUM is supported for now),
1631 /// "tag": string - Unique descriptive ID of the Registry,
1632 /// "credDefId": string - ID of the corresponding CredentialDefinition,
1633 /// "value": Registry-specific data {
1634 /// "issuanceType": string - Type of Issuance(ISSUANCE_BY_DEFAULT or ISSUANCE_ON_DEMAND),
1635 /// "maxCredNum": number - Maximum number of credentials the Registry can serve.
1636 /// "tailsHash": string - Hash of tails.
1637 /// "tailsLocation": string - Location of tails file.
1638 /// "publicKeys": <public_keys> - Registry's public key.
1639 /// },
1640 /// "ver": string - version of revocation registry definition json.
1641 /// }
1642 /// * `timeout` - the maximum time this function waits for a response
1643 ///
1644 /// # Returns
1645 /// Request result as json.
1646 pub fn build_revoc_reg_def_request_timeout(submitter_did: &str, data: &str, timeout: Duration) -> Result<String, ErrorCode> {
1647 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1648
1649 let err = Ledger::_build_revoc_reg_def_request(command_handle, submitter_did, data, cb);
1650
1651 ResultHandler::one_timeout(err, receiver, timeout)
1652 }
1653
1654 /// Builds a REVOC_REG_DEF request. Request to add the definition of revocation registry
1655 /// to an exists credential definition.
1656 ///
1657 /// # Arguments
1658 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1659 /// * `data` - Revocation Registry data:
1660 /// {
1661 /// "id": string - ID of the Revocation Registry,
1662 /// "revocDefType": string - Revocation Registry type (only CL_ACCUM is supported for now),
1663 /// "tag": string - Unique descriptive ID of the Registry,
1664 /// "credDefId": string - ID of the corresponding CredentialDefinition,
1665 /// "value": Registry-specific data {
1666 /// "issuanceType": string - Type of Issuance(ISSUANCE_BY_DEFAULT or ISSUANCE_ON_DEMAND),
1667 /// "maxCredNum": number - Maximum number of credentials the Registry can serve.
1668 /// "tailsHash": string - Hash of tails.
1669 /// "tailsLocation": string - Location of tails file.
1670 /// "publicKeys": <public_keys> - Registry's public key.
1671 /// },
1672 /// "ver": string - version of revocation registry definition json.
1673 /// }
1674 /// * `closure` - the closure that is called when finished
1675 ///
1676 /// # Returns
1677 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1678 pub fn build_revoc_reg_def_request_async<F: 'static>(submitter_did: &str, data: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1679 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1680
1681 Ledger::_build_revoc_reg_def_request(command_handle, submitter_did, data, cb)
1682 }
1683
1684 fn _build_revoc_reg_def_request(command_handle: IndyHandle, submitter_did: &str, data: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1685 let submitter_did = c_str!(submitter_did);
1686 let data = c_str!(data);
1687
1688 ErrorCode::from(unsafe { ledger::indy_build_revoc_reg_def_request(command_handle, submitter_did.as_ptr(), data.as_ptr(), cb) })
1689 }
1690
1691 /// Builds a GET_REVOC_REG_DEF request. Request to get a revocation registry definition,
1692 /// that Issuer creates for a particular Credential Definition.
1693 ///
1694 /// # Arguments
1695 /// * `submitter_did` - DID of the read request sender.
1696 /// * `id` - ID of Revocation Registry Definition in ledger.
1697 ///
1698 /// # Returns
1699 /// Request result as json.
1700 pub fn build_get_revoc_reg_def_request(submitter_did: &str, id: &str) -> Result<String, ErrorCode> {
1701 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1702
1703 let err = Ledger::_build_get_revoc_reg_def_request(command_handle, submitter_did, id, cb);
1704
1705 ResultHandler::one(err, receiver)
1706 }
1707
1708 /// Builds a GET_REVOC_REG_DEF request. Request to get a revocation registry definition,
1709 /// that Issuer creates for a particular Credential Definition.
1710 ///
1711 /// # Arguments
1712 /// * `submitter_did` - DID of the read request sender.
1713 /// * `id` - ID of Revocation Registry Definition in ledger.
1714 /// * `timeout` - the maximum time this function waits for a response
1715 ///
1716 /// # Returns
1717 /// Request result as json.
1718 pub fn build_get_revoc_reg_def_request_timeout(submitter_did: &str, id: &str, timeout: Duration) -> Result<String, ErrorCode> {
1719 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1720
1721 let err = Ledger::_build_get_revoc_reg_def_request(command_handle, submitter_did, id, cb);
1722
1723 ResultHandler::one_timeout(err, receiver, timeout)
1724 }
1725
1726 /// Builds a GET_REVOC_REG_DEF request. Request to get a revocation registry definition,
1727 /// that Issuer creates for a particular Credential Definition.
1728 ///
1729 /// # Arguments
1730 /// * `submitter_did` - DID of the read request sender.
1731 /// * `id` - ID of Revocation Registry Definition in ledger.
1732 /// * `closure` - the closure that is called when finished
1733 ///
1734 /// # Returns
1735 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1736 pub fn build_get_revoc_reg_def_request_async<F: 'static>(submitter_did: &str, id: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1737 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1738
1739 Ledger::_build_get_revoc_reg_def_request(command_handle, submitter_did, id, cb)
1740 }
1741
1742 fn _build_get_revoc_reg_def_request(command_handle: IndyHandle, submitter_did: &str, id: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1743 let submitter_did = c_str!(submitter_did);
1744 let id = c_str!(id);
1745
1746 ErrorCode::from(unsafe { ledger::indy_build_get_revoc_reg_def_request(command_handle, submitter_did.as_ptr(), id.as_ptr(), cb) })
1747 }
1748
1749 /// Parse a GET_REVOC_REG_DEF response to get Revocation Registry Definition in the format
1750 /// compatible with Anoncreds API.
1751 ///
1752 /// #Params
1753 /// * `get_revoc_reg_def_response` - response of GET_REVOC_REG_DEF request.
1754 ///
1755 /// # Returns
1756 /// Revocation Registry Definition Id and Revocation Registry Definition json.
1757 /// {
1758 /// "id": string - ID of the Revocation Registry,
1759 /// "revocDefType": string - Revocation Registry type (only CL_ACCUM is supported for now),
1760 /// "tag": string - Unique descriptive ID of the Registry,
1761 /// "credDefId": string - ID of the corresponding CredentialDefinition,
1762 /// "value": Registry-specific data {
1763 /// "issuanceType": string - Type of Issuance(ISSUANCE_BY_DEFAULT or ISSUANCE_ON_DEMAND),
1764 /// "maxCredNum": number - Maximum number of credentials the Registry can serve.
1765 /// "tailsHash": string - Hash of tails.
1766 /// "tailsLocation": string - Location of tails file.
1767 /// "publicKeys": <public_keys> - Registry's public key.
1768 /// },
1769 /// "ver": string - version of revocation registry definition json.
1770 /// }
1771 pub fn parse_get_revoc_reg_def_response(get_revoc_reg_def_response: &str) -> Result<(String, String), ErrorCode> {
1772 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
1773
1774 let err = Ledger::_parse_get_revoc_reg_def_response(command_handle, get_revoc_reg_def_response, cb);
1775
1776 ResultHandler::two(err, receiver)
1777 }
1778
1779 /// Parse a GET_REVOC_REG_DEF response to get Revocation Registry Definition in the format
1780 /// compatible with Anoncreds API.
1781 ///
1782 /// #Params
1783 /// * `get_revoc_reg_def_response` - response of GET_REVOC_REG_DEF request.
1784 /// * `timeout` - the maximum time this function waits for a response
1785 ///
1786 /// # Returns
1787 /// Revocation Registry Definition Id and Revocation Registry Definition json.
1788 /// {
1789 /// "id": string - ID of the Revocation Registry,
1790 /// "revocDefType": string - Revocation Registry type (only CL_ACCUM is supported for now),
1791 /// "tag": string - Unique descriptive ID of the Registry,
1792 /// "credDefId": string - ID of the corresponding CredentialDefinition,
1793 /// "value": Registry-specific data {
1794 /// "issuanceType": string - Type of Issuance(ISSUANCE_BY_DEFAULT or ISSUANCE_ON_DEMAND),
1795 /// "maxCredNum": number - Maximum number of credentials the Registry can serve.
1796 /// "tailsHash": string - Hash of tails.
1797 /// "tailsLocation": string - Location of tails file.
1798 /// "publicKeys": <public_keys> - Registry's public key.
1799 /// },
1800 /// "ver": string - version of revocation registry definition json.
1801 /// }
1802 pub fn parse_get_revoc_reg_def_response_timeout(get_revoc_reg_def_response: &str, timeout: Duration) -> Result<(String, String), ErrorCode> {
1803 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
1804
1805 let err = Ledger::_parse_get_revoc_reg_def_response(command_handle, get_revoc_reg_def_response, cb);
1806
1807 ResultHandler::two_timeout(err, receiver, timeout)
1808 }
1809
1810 /// Parse a GET_REVOC_REG_DEF response to get Revocation Registry Definition in the format
1811 /// compatible with Anoncreds API.
1812 ///
1813 /// #Params
1814 /// * `get_revoc_reg_def_response` - response of GET_REVOC_REG_DEF request.
1815 /// * `closure` - the closure that is called when finished
1816 ///
1817 /// # Returns
1818 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1819 pub fn parse_get_revoc_reg_def_response_async<F: 'static>(get_revoc_reg_def_response: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
1820 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));
1821
1822 Ledger::_parse_get_revoc_reg_def_response(command_handle, get_revoc_reg_def_response, cb)
1823 }
1824
1825 fn _parse_get_revoc_reg_def_response(command_handle: IndyHandle, get_revoc_reg_def_response: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
1826 let get_revoc_reg_def_response = c_str!(get_revoc_reg_def_response);
1827
1828 ErrorCode::from(unsafe { ledger::indy_parse_get_revoc_reg_def_response(command_handle, get_revoc_reg_def_response.as_ptr(), cb) })
1829 }
1830
1831 /// Builds a REVOC_REG_ENTRY request. Request to add the RevocReg entry containing
1832 /// the new accumulator value and issued/revoked indices.
1833 /// This is just a delta of indices, not the whole list.
1834 /// So, it can be sent each time a new credential is issued/revoked.
1835 ///
1836 /// # Arguments
1837 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1838 /// * `revoc_reg_def_id` - ID of the corresponding RevocRegDef.
1839 /// * `rev_def_type` - Revocation Registry type (only CL_ACCUM is supported for now).
1840 /// * `value` - Registry-specific data: {
1841 /// value: {
1842 /// prevAccum: string - previous accumulator value.
1843 /// accum: string - current accumulator value.
1844 /// issued: array<number> - an array of issued indices.
1845 /// revoked: array<number> an array of revoked indices.
1846 /// },
1847 /// ver: string - version revocation registry entry json
1848 ///
1849 /// }
1850 ///
1851 /// # Returns
1852 /// Request result as json.
1853 pub fn build_revoc_reg_entry_request(submitter_did: &str, revoc_reg_def_id: &str, rev_def_type: &str, value: &str) -> Result<String, ErrorCode> {
1854 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1855
1856 let err = Ledger::_build_revoc_reg_entry_request(command_handle, submitter_did, revoc_reg_def_id, rev_def_type, value, cb);
1857
1858 ResultHandler::one(err, receiver)
1859 }
1860
1861 /// Builds a REVOC_REG_ENTRY request. Request to add the RevocReg entry containing
1862 /// the new accumulator value and issued/revoked indices.
1863 /// This is just a delta of indices, not the whole list.
1864 /// So, it can be sent each time a new credential is issued/revoked.
1865 ///
1866 /// # Arguments
1867 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1868 /// * `revoc_reg_def_id` - ID of the corresponding RevocRegDef.
1869 /// * `rev_def_type` - Revocation Registry type (only CL_ACCUM is supported for now).
1870 /// * `value` - Registry-specific data: {
1871 /// value: {
1872 /// prevAccum: string - previous accumulator value.
1873 /// accum: string - current accumulator value.
1874 /// issued: array<number> - an array of issued indices.
1875 /// revoked: array<number> an array of revoked indices.
1876 /// },
1877 /// ver: string - version revocation registry entry json
1878 ///
1879 /// }
1880 /// * `timeout` - the maximum time this function waits for a response
1881 ///
1882 /// # Returns
1883 /// Request result as json.
1884 pub fn build_revoc_reg_entry_request_timeout(submitter_did: &str, revoc_reg_def_id: &str, rev_def_type: &str, value: &str, timeout: Duration) -> Result<String, ErrorCode> {
1885 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1886
1887 let err = Ledger::_build_revoc_reg_entry_request(command_handle, submitter_did, revoc_reg_def_id, rev_def_type, value, cb);
1888
1889 ResultHandler::one_timeout(err, receiver, timeout)
1890 }
1891
1892 /// Builds a REVOC_REG_ENTRY request. Request to add the RevocReg entry containing
1893 /// the new accumulator value and issued/revoked indices.
1894 /// This is just a delta of indices, not the whole list.
1895 /// So, it can be sent each time a new credential is issued/revoked.
1896 ///
1897 /// # Arguments
1898 /// * `submitter_did` - DID of the submitter stored in secured Wallet.
1899 /// * `revoc_reg_def_id` - ID of the corresponding RevocRegDef.
1900 /// * `rev_def_type` - Revocation Registry type (only CL_ACCUM is supported for now).
1901 /// * `value` - Registry-specific data: {
1902 /// value: {
1903 /// prevAccum: string - previous accumulator value.
1904 /// accum: string - current accumulator value.
1905 /// issued: array<number> - an array of issued indices.
1906 /// revoked: array<number> an array of revoked indices.
1907 /// },
1908 /// ver: string - version revocation registry entry json
1909 ///
1910 /// }
1911 /// * `closure` - the closure that is called when finished
1912 ///
1913 /// # Returns
1914 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1915 pub fn build_revoc_reg_entry_request_async<F: 'static>(submitter_did: &str, revoc_reg_def_id: &str, rev_def_type: &str, value: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1916 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1917
1918 Ledger::_build_revoc_reg_entry_request(command_handle, submitter_did, revoc_reg_def_id, rev_def_type, value, cb)
1919 }
1920
1921 fn _build_revoc_reg_entry_request(command_handle: IndyHandle, submitter_did: &str, revoc_reg_def_id: &str, rev_def_type: &str, value: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1922 let submitter_did = c_str!(submitter_did);
1923 let revoc_reg_def_id = c_str!(revoc_reg_def_id);
1924 let rev_def_type = c_str!(rev_def_type);
1925 let value = c_str!(value);
1926
1927 ErrorCode::from(unsafe { ledger::indy_build_revoc_reg_entry_request(command_handle, submitter_did.as_ptr(), revoc_reg_def_id.as_ptr(), rev_def_type.as_ptr(), value.as_ptr(), cb) })
1928 }
1929
1930 /// Builds a GET_REVOC_REG request. Request to get the accumulated state of the Revocation Registry
1931 /// by ID. The state is defined by the given timestamp.
1932 ///
1933 /// # Arguments
1934 /// * `submitter_did` - DID of the read request sender.
1935 /// * `revoc_reg_def_id` - ID of the corresponding Revocation Registry Definition in ledger.
1936 /// * `timestamp` - Requested time represented as a total number of seconds from Unix Epoch
1937 ///
1938 /// # Returns
1939 /// Request result as json.
1940 pub fn build_get_revoc_reg_request(submitter_did: &str, revoc_reg_def_id: &str, timestamp: i64) -> Result<String, ErrorCode> {
1941 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1942
1943 let err = Ledger::_build_get_revoc_reg_request(command_handle, submitter_did, revoc_reg_def_id, timestamp, cb);
1944
1945 ResultHandler::one(err, receiver)
1946 }
1947
1948 /// Builds a GET_REVOC_REG request. Request to get the accumulated state of the Revocation Registry
1949 /// by ID. The state is defined by the given timestamp.
1950 ///
1951 /// # Arguments
1952 /// * `submitter_did` - DID of the read request sender.
1953 /// * `revoc_reg_def_id` - ID of the corresponding Revocation Registry Definition in ledger.
1954 /// * `timestamp` - Requested time represented as a total number of seconds from Unix Epoch
1955 /// * `timeout` - the maximum time this function waits for a response
1956 ///
1957 /// # Returns
1958 /// Request result as json.
1959 pub fn build_get_revoc_reg_request_timeout(submitter_did: &str, revoc_reg_def_id: &str, timestamp: i64, timeout: Duration) -> Result<String, ErrorCode> {
1960 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1961
1962 let err = Ledger::_build_get_revoc_reg_request(command_handle, submitter_did, revoc_reg_def_id, timestamp, cb);
1963
1964 ResultHandler::one_timeout(err, receiver, timeout)
1965 }
1966
1967 /// Builds a GET_REVOC_REG request. Request to get the accumulated state of the Revocation Registry
1968 /// by ID. The state is defined by the given timestamp.
1969 ///
1970 /// # Arguments
1971 /// * `submitter_did` - DID of the read request sender.
1972 /// * `revoc_reg_def_id` - ID of the corresponding Revocation Registry Definition in ledger.
1973 /// * `timestamp` - Requested time represented as a total number of seconds from Unix Epoch
1974 /// * `closure` - the closure that is called when finished
1975 ///
1976 /// # Returns
1977 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1978 pub fn build_get_revoc_reg_request_async<F: 'static>(submitter_did: &str, revoc_reg_def_id: &str, timestamp: i64, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1979 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1980
1981 Ledger::_build_get_revoc_reg_request(command_handle, submitter_did, revoc_reg_def_id, timestamp, cb)
1982 }
1983
1984 fn _build_get_revoc_reg_request(command_handle: IndyHandle, submitter_did: &str, revoc_reg_def_id: &str, timestamp: i64, cb: Option<ResponseStringCB>) -> ErrorCode {
1985 let submitter_did = c_str!(submitter_did);
1986 let revoc_reg_def_id = c_str!(revoc_reg_def_id);
1987
1988 ErrorCode::from(unsafe { ledger::indy_build_get_revoc_reg_request(command_handle, submitter_did.as_ptr(), revoc_reg_def_id.as_ptr(), timestamp, cb) })
1989 }
1990
1991 /// Parse a GET_REVOC_REG response to get Revocation Registry in the format compatible with Anoncreds API.
1992 ///
1993 /// # Arguments
1994 /// * `get_revoc_reg_response` - response of GET_REVOC_REG request.
1995 ///
1996 /// # Returns
1997 /// Revocation Registry Definition Id, Revocation Registry json and Timestamp.
1998 /// {
1999 /// "value": Registry-specific data {
2000 /// "accum": string - current accumulator value.
2001 /// },
2002 /// "ver": string - version revocation registry json
2003 /// }
2004 pub fn parse_get_revoc_reg_response(get_revoc_reg_response: &str) -> Result<(String, String, u64), ErrorCode> {
2005 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string_u64();
2006
2007 let err = Ledger::_parse_get_revoc_reg_response(command_handle, get_revoc_reg_response, cb);
2008
2009 ResultHandler::three(err, receiver)
2010 }
2011
2012 /// Parse a GET_REVOC_REG response to get Revocation Registry in the format compatible with Anoncreds API.
2013 ///
2014 /// # Arguments
2015 /// * `get_revoc_reg_response` - response of GET_REVOC_REG request.
2016 /// * `timeout` - the maximum time this function waits for a response
2017 ///
2018 /// # Returns
2019 /// Revocation Registry Definition Id, Revocation Registry json and Timestamp.
2020 /// {
2021 /// "value": Registry-specific data {
2022 /// "accum": string - current accumulator value.
2023 /// },
2024 /// "ver": string - version revocation registry json
2025 /// }
2026 pub fn parse_get_revoc_reg_response_timeout(get_revoc_reg_response: &str, timeout: Duration) -> Result<(String, String, u64), ErrorCode> {
2027 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string_u64();
2028
2029 let err = Ledger::_parse_get_revoc_reg_response(command_handle, get_revoc_reg_response, cb);
2030
2031 ResultHandler::three_timeout(err, receiver, timeout)
2032 }
2033
2034 /// Parse a GET_REVOC_REG response to get Revocation Registry in the format compatible with Anoncreds API.
2035 ///
2036 /// # Arguments
2037 /// * `get_revoc_reg_response` - response of GET_REVOC_REG request.
2038 /// * `closure` - the closure that is called when finished
2039 ///
2040 /// # Returns
2041 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
2042 pub fn parse_get_revoc_reg_response_async<F: 'static>(get_revoc_reg_response: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String, u64) + Send {
2043 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string_u64(Box::new(closure));
2044
2045 Ledger::_parse_get_revoc_reg_response(command_handle, get_revoc_reg_response, cb)
2046 }
2047
2048 fn _parse_get_revoc_reg_response(command_handle: IndyHandle, get_revoc_reg_response: &str, cb: Option<ResponseStringStringU64CB>) -> ErrorCode {
2049 let get_revoc_reg_response = c_str!(get_revoc_reg_response);
2050
2051 ErrorCode::from(unsafe { ledger::indy_parse_get_revoc_reg_response(command_handle,get_revoc_reg_response.as_ptr(), cb) })
2052 }
2053
2054 /// Builds a GET_REVOC_REG_DELTA request. Request to get the delta of the accumulated state of the Revocation Registry.
2055 /// The Delta is defined by from and to timestamp fields.
2056 /// If from is not specified, then the whole state till to will be returned.
2057 ///
2058 /// # Arguments
2059 /// * `submitter_did` - DID of the read request sender.
2060 /// * `revoc_reg_def_id` - ID of the corresponding Revocation Registry Definition in ledger.
2061 /// * `from` - Requested time represented as a total number of seconds from Unix Epoch
2062 /// * `to` - Requested time represented as a total number of seconds from Unix Epoch
2063 ///
2064 /// # Returns
2065 /// Request result as json.
2066 pub fn build_get_revoc_reg_delta_request(submitter_did: &str, revoc_reg_def_id: &str, from: i64, to: i64) -> Result<String, ErrorCode> {
2067 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
2068
2069 let err = Ledger::_build_get_revoc_reg_delta_request(command_handle, submitter_did, revoc_reg_def_id, from, to, cb);
2070
2071 ResultHandler::one(err, receiver)
2072 }
2073
2074 /// Builds a GET_REVOC_REG_DELTA request. Request to get the delta of the accumulated state of the Revocation Registry.
2075 /// The Delta is defined by from and to timestamp fields.
2076 /// If from is not specified, then the whole state till to will be returned.
2077 ///
2078 /// # Arguments
2079 /// * `submitter_did` - DID of the read request sender.
2080 /// * `revoc_reg_def_id` - ID of the corresponding Revocation Registry Definition in ledger.
2081 /// * `from` - Requested time represented as a total number of seconds from Unix Epoch
2082 /// * `to` - Requested time represented as a total number of seconds from Unix Epoch
2083 /// * `timeout` - the maximum time this function waits for a response
2084 ///
2085 /// # Returns
2086 /// Request result as json.
2087 pub fn build_get_revoc_reg_delta_request_timeout(submitter_did: &str, revoc_reg_def_id: &str, from: i64, to: i64, timeout: Duration) -> Result<String, ErrorCode> {
2088 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
2089
2090 let err = Ledger::_build_get_revoc_reg_delta_request(command_handle, submitter_did, revoc_reg_def_id, from, to, cb);
2091
2092 ResultHandler::one_timeout(err, receiver, timeout)
2093 }
2094
2095 /// Builds a GET_REVOC_REG_DELTA request. Request to get the delta of the accumulated state of the Revocation Registry.
2096 /// The Delta is defined by from and to timestamp fields.
2097 /// If from is not specified, then the whole state till to will be returned.
2098 ///
2099 /// # Arguments
2100 /// * `submitter_did` - DID of the read request sender.
2101 /// * `revoc_reg_def_id` - ID of the corresponding Revocation Registry Definition in ledger.
2102 /// * `from` - Requested time represented as a total number of seconds from Unix Epoch
2103 /// * `to` - Requested time represented as a total number of seconds from Unix Epoch
2104 /// * `closure` - the closure that is called when finished
2105 ///
2106 /// # Returns
2107 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
2108 pub fn build_get_revoc_reg_delta_request_async<F: 'static>(submitter_did: &str, revoc_reg_def_id: &str, from: i64, to: i64, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
2109 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
2110
2111 Ledger::_build_get_revoc_reg_delta_request(command_handle, submitter_did, revoc_reg_def_id, from, to, cb)
2112 }
2113
2114 fn _build_get_revoc_reg_delta_request(command_handle: IndyHandle, submitter_did: &str, revoc_reg_def_id: &str, from: i64, to: i64, cb: Option<ResponseStringCB>) -> ErrorCode {
2115 let submitter_did = c_str!(submitter_did);
2116 let revoc_reg_def_id = c_str!(revoc_reg_def_id);
2117
2118 ErrorCode::from(unsafe { ledger::indy_build_get_revoc_reg_delta_request(command_handle, submitter_did.as_ptr(), revoc_reg_def_id.as_ptr(), from, to, cb) })
2119 }
2120
2121 /// Parse a GET_REVOC_REG_DELTA response to get Revocation Registry Delta in the format compatible with Anoncreds API.
2122 ///
2123 /// # Arguments
2124 /// * `get_revoc_reg_response` - response of GET_REVOC_REG_DELTA request.
2125 ///
2126 /// # Returns
2127 /// Revocation Registry Definition Id, Revocation Registry Delta json and Timestamp.
2128 /// {
2129 /// "value": Registry-specific data {
2130 /// prevAccum: string - previous accumulator value.
2131 /// accum: string - current accumulator value.
2132 /// issued: array<number> - an array of issued indices.
2133 /// revoked: array<number> an array of revoked indices.
2134 /// },
2135 /// "ver": string - version revocation registry delta json
2136 /// }
2137 pub fn parse_get_revoc_reg_delta_response(get_revoc_reg_delta_response: &str) -> Result<(String, String, u64), ErrorCode> {
2138 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string_u64();
2139
2140 let err = Ledger::_parse_get_revoc_reg_delta_response(command_handle, get_revoc_reg_delta_response, cb);
2141
2142 ResultHandler::three(err, receiver)
2143 }
2144
2145 /// Parse a GET_REVOC_REG_DELTA response to get Revocation Registry Delta in the format compatible with Anoncreds API.
2146 ///
2147 /// # Arguments
2148 /// * `get_revoc_reg_response` - response of GET_REVOC_REG_DELTA request.
2149 /// * `timeout` - the maximum time this function waits for a response
2150 ///
2151 /// # Returns
2152 /// Revocation Registry Definition Id, Revocation Registry Delta json and Timestamp.
2153 /// {
2154 /// "value": Registry-specific data {
2155 /// prevAccum: string - previous accumulator value.
2156 /// accum: string - current accumulator value.
2157 /// issued: array<number> - an array of issued indices.
2158 /// revoked: array<number> an array of revoked indices.
2159 /// },
2160 /// "ver": string - version revocation registry delta json
2161 /// }
2162 pub fn parse_get_revoc_reg_delta_response_timeout(get_revoc_reg_delta_response: &str, timeout: Duration) -> Result<(String, String, u64), ErrorCode> {
2163 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string_u64();
2164
2165 let err = Ledger::_parse_get_revoc_reg_delta_response(command_handle, get_revoc_reg_delta_response, cb);
2166
2167 ResultHandler::three_timeout(err, receiver, timeout)
2168 }
2169
2170 /// Parse a GET_REVOC_REG_DELTA response to get Revocation Registry Delta in the format compatible with Anoncreds API.
2171 ///
2172 /// # Arguments
2173 /// * `get_revoc_reg_response` - response of GET_REVOC_REG_DELTA request.
2174 /// * `closure` - the closure that is called when finished
2175 ///
2176 /// # Returns
2177 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
2178 pub fn parse_get_revoc_reg_delta_response_async<F: 'static>(get_revoc_reg_delta_response: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String, u64) + Send {
2179 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string_u64(Box::new(closure));
2180
2181 Ledger::_parse_get_revoc_reg_delta_response(command_handle, get_revoc_reg_delta_response, cb)
2182 }
2183
2184 fn _parse_get_revoc_reg_delta_response(command_handle: IndyHandle, get_revoc_reg_delta_response: &str, cb: Option<ResponseStringStringU64CB>) -> ErrorCode {
2185 let get_revoc_reg_delta_response = c_str!(get_revoc_reg_delta_response);
2186
2187 ErrorCode::from(unsafe { ledger::indy_parse_get_revoc_reg_delta_response(command_handle,get_revoc_reg_delta_response.as_ptr(), cb) })
2188 }
2189
2190 /// Register callbacks (see type description for `CustomTransactionParser` and `CustomFree`
2191 ///
2192 /// # Arguments
2193 /// * `txn_type` - type of transaction to apply `parse` callback.
2194 /// * `parse` - required callback to parse reply for state proof.
2195 /// * `free` - required callback to deallocate memory.
2196 ///
2197 /// # Returns
2198 /// Status of callbacks registration.
2199 pub fn register_transaction_parser_for_sp(txn_type: &str, parser: Option<ledger::CustomTransactionParser>, free: Option<ledger::CustomFree>) -> Result<(), ErrorCode> {
2200 let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
2201
2202 let err = Ledger::_register_transaction_parser_for_sp(command_handle, txn_type, parser, free, cb);
2203
2204 ResultHandler::empty(err, receiver)
2205 }
2206
2207 /// Register callbacks (see type description for `CustomTransactionParser` and `CustomFree`
2208 ///
2209 /// # Arguments
2210 /// * `txn_type` - type of transaction to apply `parse` callback.
2211 /// * `parse` - required callback to parse reply for state proof.
2212 /// * `free` - required callback to deallocate memory.
2213 /// * `timeout` - the maximum time this function waits for a response
2214 ///
2215 /// # Returns
2216 /// Status of callbacks registration.
2217 pub fn register_transaction_parser_for_sp_timeout(txn_type: &str, parser: Option<ledger::CustomTransactionParser>, free: Option<ledger::CustomFree>, timeout: Duration) -> Result<(), ErrorCode> {
2218 let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
2219
2220 let err = Ledger::_register_transaction_parser_for_sp(command_handle, txn_type, parser, free, cb);
2221
2222 ResultHandler::empty_timeout(err, receiver, timeout)
2223 }
2224
2225 /// Register callbacks (see type description for `CustomTransactionParser` and `CustomFree`
2226 ///
2227 /// # Arguments
2228 /// * `txn_type` - type of transaction to apply `parse` callback.
2229 /// * `parse` - required callback to parse reply for state proof.
2230 /// * `free` - required callback to deallocate memory.
2231 /// * `closure` - the closure that is called when finished
2232 ///
2233 /// # Returns
2234 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
2235 pub fn register_transaction_parser_for_sp_async<F: 'static>(txn_type: &str, parser: Option<ledger::CustomTransactionParser>, free: Option<ledger::CustomFree>, closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
2236 let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
2237
2238 Ledger::_register_transaction_parser_for_sp(command_handle, txn_type, parser, free, cb)
2239 }
2240
2241 fn _register_transaction_parser_for_sp(command_handle: IndyHandle, txn_type: &str, parser: Option<ledger::CustomTransactionParser>, free: Option<ledger::CustomFree>, cb: Option<ResponseEmptyCB>) -> ErrorCode {
2242 let txn_type = c_str!(txn_type);
2243
2244 ErrorCode::from(unsafe {
2245 ledger::indy_register_transaction_parser_for_sp(command_handle, txn_type.as_ptr(), parser, free, cb)
2246 })
2247 }
2248}
2249
2250