rust_libindy_wrapper/payments.rs
1use {ErrorCode, IndyHandle};
2
3use std::ffi::CString;
4use std::time::Duration;
5use std::ptr::null;
6
7use native::payments;
8use native::{ResponseEmptyCB,
9 ResponseStringCB,
10 ResponseStringStringCB};
11
12use utils::callbacks::ClosureHandler;
13use utils::results::ResultHandler;
14
15pub struct Payment {}
16
17impl Payment {
18 pub fn register_method(payment_method: &str,
19 create_payment_address: Option<payments::CreatePaymentAddressCB>,
20 add_request_fees: Option<payments::AddRequestFeesCB>,
21 parse_response_with_fees: Option<payments::ParseResponseWithFeesCB>,
22 build_get_payment_sources_request: Option<payments::BuildGetPaymentSourcesRequestCB>,
23 parse_get_payment_sources_response: Option<payments::ParseGetPaymentSourcesResponseCB>,
24 build_payment_req: Option<payments::BuildPaymentReqCB>,
25 parse_payment_response: Option<payments::ParsePaymentResponseCB>,
26 build_mint_req: Option<payments::BuildMintReqCB>,
27 build_set_txn_fees_req: Option<payments::BuildSetTxnFeesReqCB>,
28 build_get_txn_fees_req: Option<payments::BuildGetTxnFeesReqCB>,
29 parse_get_txn_fees_response: Option<payments::ParseGetTxnFeesResponseCB>,
30 build_verify_payment_req: Option<payments::BuildVerifyPaymentReqCB>,
31 parse_verify_payment_response: Option<payments::ParseVerifyPaymentResponseCB>) -> Result<(), ErrorCode> {
32 let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
33
34 let err = Payment::_register_method(command_handle,
35 payment_method,
36 create_payment_address,
37 add_request_fees,
38 parse_response_with_fees,
39 build_get_payment_sources_request,
40 parse_get_payment_sources_response,
41 build_payment_req,
42 parse_payment_response,
43 build_mint_req,
44 build_set_txn_fees_req,
45 build_get_txn_fees_req,
46 parse_get_txn_fees_response,
47 build_verify_payment_req,
48 parse_verify_payment_response,
49 cb);
50
51 ResultHandler::empty(err, receiver)
52 }
53
54 /// * `timeout` - the maximum time this function waits for a response
55 pub fn register_method_timeout(payment_method: &str,
56 create_payment_address: Option<payments::CreatePaymentAddressCB>,
57 add_request_fees: Option<payments::AddRequestFeesCB>,
58 parse_response_with_fees: Option<payments::ParseResponseWithFeesCB>,
59 build_get_payment_sources_request: Option<payments::BuildGetPaymentSourcesRequestCB>,
60 parse_get_payment_sources_response: Option<payments::ParseGetPaymentSourcesResponseCB>,
61 build_payment_req: Option<payments::BuildPaymentReqCB>,
62 parse_payment_response: Option<payments::ParsePaymentResponseCB>,
63 build_mint_req: Option<payments::BuildMintReqCB>,
64 build_set_txn_fees_req: Option<payments::BuildSetTxnFeesReqCB>,
65 build_get_txn_fees_req: Option<payments::BuildGetTxnFeesReqCB>,
66 parse_get_txn_fees_response: Option<payments::ParseGetTxnFeesResponseCB>,
67 build_verify_payment_req: Option<payments::BuildVerifyPaymentReqCB>,
68 parse_verify_payment_response: Option<payments::ParseVerifyPaymentResponseCB>,
69 timeout: Duration) -> Result<(), ErrorCode> {
70 let (receiver, command_handle, cb) = ClosureHandler::cb_ec();
71
72 let err = Payment::_register_method(command_handle,
73 payment_method,
74 create_payment_address,
75 add_request_fees,
76 parse_response_with_fees,
77 build_get_payment_sources_request,
78 parse_get_payment_sources_response,
79 build_payment_req,
80 parse_payment_response,
81 build_mint_req,
82 build_set_txn_fees_req,
83 build_get_txn_fees_req,
84 parse_get_txn_fees_response,
85 build_verify_payment_req,
86 parse_verify_payment_response,
87 cb);
88
89 ResultHandler::empty_timeout(err, receiver, timeout)
90 }
91
92 /// * `closure` - the closure that is called when finished
93 ///
94 /// # Returns
95 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
96 pub fn register_method_async<F: 'static>(payment_method: &str,
97 create_payment_address: Option<payments::CreatePaymentAddressCB>,
98 add_request_fees: Option<payments::AddRequestFeesCB>,
99 parse_response_with_fees: Option<payments::ParseResponseWithFeesCB>,
100 build_get_payment_sources_request: Option<payments::BuildGetPaymentSourcesRequestCB>,
101 parse_get_payment_sources_response: Option<payments::ParseGetPaymentSourcesResponseCB>,
102 build_payment_req: Option<payments::BuildPaymentReqCB>,
103 parse_payment_response: Option<payments::ParsePaymentResponseCB>,
104 build_mint_req: Option<payments::BuildMintReqCB>,
105 build_set_txn_fees_req: Option<payments::BuildSetTxnFeesReqCB>,
106 build_get_txn_fees_req: Option<payments::BuildGetTxnFeesReqCB>,
107 parse_get_txn_fees_response: Option<payments::ParseGetTxnFeesResponseCB>,
108 build_verify_payment_req: Option<payments::BuildVerifyPaymentReqCB>,
109 parse_verify_payment_response: Option<payments::ParseVerifyPaymentResponseCB>,
110 closure: F) -> ErrorCode where F: FnMut(ErrorCode) + Send {
111 let (command_handle, cb) = ClosureHandler::convert_cb_ec(Box::new(closure));
112
113 Payment::_register_method(command_handle,
114 payment_method,
115 create_payment_address,
116 add_request_fees,
117 parse_response_with_fees,
118 build_get_payment_sources_request,
119 parse_get_payment_sources_response,
120 build_payment_req,
121 parse_payment_response,
122 build_mint_req,
123 build_set_txn_fees_req,
124 build_get_txn_fees_req,
125 parse_get_txn_fees_response,
126 build_verify_payment_req,
127 parse_verify_payment_response,
128 cb)
129 }
130
131 fn _register_method(command_handle: IndyHandle,
132 payment_method: &str,
133 create_payment_address: Option<payments::CreatePaymentAddressCB>,
134 add_request_fees: Option<payments::AddRequestFeesCB>,
135 parse_response_with_fees: Option<payments::ParseResponseWithFeesCB>,
136 build_get_payment_sources_request: Option<payments::BuildGetPaymentSourcesRequestCB>,
137 parse_get_payment_sources_response: Option<payments::ParseGetPaymentSourcesResponseCB>,
138 build_payment_req: Option<payments::BuildPaymentReqCB>,
139 parse_payment_response: Option<payments::ParsePaymentResponseCB>,
140 build_mint_req: Option<payments::BuildMintReqCB>,
141 build_set_txn_fees_req: Option<payments::BuildSetTxnFeesReqCB>,
142 build_get_txn_fees_req: Option<payments::BuildGetTxnFeesReqCB>,
143 parse_get_txn_fees_response: Option<payments::ParseGetTxnFeesResponseCB>,
144 build_verify_payment_req: Option<payments::BuildVerifyPaymentReqCB>,
145 parse_verify_payment_response: Option<payments::ParseVerifyPaymentResponseCB>,
146 cb: Option<ResponseEmptyCB>) -> ErrorCode {
147 let payment_method = c_str!(payment_method);
148
149 ErrorCode::from(unsafe {
150 payments::indy_register_payment_method(command_handle,
151 payment_method.as_ptr(),
152 create_payment_address,
153 add_request_fees,
154 parse_response_with_fees,
155 build_get_payment_sources_request,
156 parse_get_payment_sources_response,
157 build_payment_req, parse_payment_response,
158 build_mint_req,
159 build_set_txn_fees_req,
160 build_get_txn_fees_req,
161 parse_get_txn_fees_response,
162 build_verify_payment_req,
163 parse_verify_payment_response,
164 cb)
165 })
166 }
167
168 /// Create the payment address for specified payment method
169 ///
170 /// This method generates private part of payment address
171 /// and stores it in a secure place. Ideally it should be
172 /// secret in libindy wallet (see crypto module).
173 ///
174 /// Note that payment method should be able to resolve this
175 /// secret by fully resolvable payment address format.
176 ///
177 /// # Arguments
178 /// * `wallet_handle` - wallet handle where to save new address
179 /// * `payment_method` - payment method to use (for example, 'sov')
180 /// * `config` - payment address config as json
181 ///
182 /// # Example
183 /// config
184 /// {
185 /// seed: <str>, // allows deterministic creation of payment address
186 /// }
187 ///
188 /// # Returns
189 /// * `payment_address` - public identifier of payment address in fully resolvable payment address format
190 pub fn create_payment_address(wallet_handle: IndyHandle, payment_method: &str, config: &str) -> Result<String, ErrorCode> {
191 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
192
193 let err = Payment::_create_payment_address(command_handle, wallet_handle, payment_method, config, cb);
194
195 ResultHandler::one(err, receiver)
196 }
197
198 /// Create the payment address for specified payment method
199 ///
200 /// This method generates private part of payment address
201 /// and stores it in a secure place. Ideally it should be
202 /// secret in libindy wallet (see crypto module).
203 ///
204 /// Note that payment method should be able to resolve this
205 /// secret by fully resolvable payment address format.
206 ///
207 /// # Arguments
208 /// * `wallet_handle` - wallet handle where to save new address
209 /// * `payment_method` - payment method to use (for example, 'sov')
210 /// * `config` - payment address config as json
211 /// * `timeout` - the maximum time this function waits for a response
212 ///
213 /// # Example
214 /// config
215 /// {
216 /// seed: <str>, // allows deterministic creation of payment address
217 /// }
218 ///
219 /// # Returns
220 /// * `payment_address` - public identifier of payment address in fully resolvable payment address format
221 pub fn create_payment_address_timeout(wallet_handle: IndyHandle, payment_method: &str, config: &str, timeout: Duration) -> Result<String, ErrorCode> {
222 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
223
224 let err = Payment::_create_payment_address(command_handle, wallet_handle, payment_method, config, cb);
225
226 ResultHandler::one_timeout(err, receiver, timeout)
227 }
228
229 /// Create the payment address for specified payment method
230 ///
231 /// This method generates private part of payment address
232 /// and stores it in a secure place. Ideally it should be
233 /// secret in libindy wallet (see crypto module).
234 ///
235 /// Note that payment method should be able to resolve this
236 /// secret by fully resolvable payment address format.
237 ///
238 /// # Arguments
239 /// * `wallet_handle` - wallet handle where to save new address
240 /// * `payment_method` - payment method to use (for example, 'sov')
241 /// * `config` - payment address config as json
242 /// * `closure` - the closure that is called when finished
243 ///
244 /// # Example
245 /// config
246 /// {
247 /// seed: <str>, // allows deterministic creation of payment address
248 /// }
249 ///
250 /// # Returns
251 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
252 pub fn create_payment_address_async<F: 'static>(wallet_handle: IndyHandle, payment_method: &str, config: &str, closure: F) -> ErrorCode where F:FnMut(ErrorCode, String) + Send {
253 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
254
255 Payment::_create_payment_address(command_handle, wallet_handle, payment_method, config, cb)
256 }
257
258 fn _create_payment_address(command_handle: IndyHandle, wallet_handle: IndyHandle, payment_method: &str, config: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
259 let payment_method = c_str!(payment_method);
260 let config = c_str!(config);
261
262 ErrorCode::from(unsafe { payments::indy_create_payment_address(command_handle, wallet_handle, payment_method.as_ptr(), config.as_ptr(), cb) })
263 }
264
265 /// Lists all payment addresses that are stored in the wallet
266 ///
267 /// # Arguments
268 /// * `wallet_handle` - wallet to search for payment_addresses
269 ///
270 /// # Returns
271 /// * `payment_addresses_json` - json array of string with json addresses
272 pub fn list_payment_addresses(wallet_handle: IndyHandle) -> Result<String, ErrorCode> {
273 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
274
275 let err = Payment::_list_payment_addresses(command_handle, wallet_handle, cb);
276
277 ResultHandler::one(err, receiver)
278 }
279
280 /// Lists all payment addresses that are stored in the wallet
281 ///
282 /// # Arguments
283 /// * `wallet_handle` - wallet to search for payment_addresses
284 /// * `timeout` - the maximum time this function waits for a response
285 ///
286 /// # Returns
287 /// * `payment_addresses_json` - json array of string with json addresses
288 pub fn list_payment_addresses_timeout(wallet_handle: IndyHandle, timeout: Duration) -> Result<String, ErrorCode> {
289 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
290
291 let err = Payment::_list_payment_addresses(command_handle, wallet_handle, cb);
292
293 ResultHandler::one_timeout(err, receiver, timeout)
294 }
295
296 /// Lists all payment addresses that are stored in the wallet
297 ///
298 /// # Arguments
299 /// * `wallet_handle` - wallet to search for payment_addresses
300 /// * `closure` - the closure that is called when finished
301 ///
302 /// # Returns
303 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
304 pub fn list_payment_addresses_async<F: 'static>(wallet_handle: IndyHandle, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
305 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
306
307 Payment::_list_payment_addresses(command_handle, wallet_handle, cb)
308 }
309
310 fn _list_payment_addresses(command_handle: IndyHandle, wallet_handle: IndyHandle, cb: Option<ResponseStringCB>) -> ErrorCode {
311 ErrorCode::from(unsafe { payments::indy_list_payment_addresses(command_handle, wallet_handle, cb) })
312 }
313
314 /// Modifies Indy request by adding information how to pay fees for this transaction
315 /// according to selected payment method.
316 ///
317 /// Payment selection is performed by looking to o
318 ///
319 /// This method consumes set of UTXO inputs and outputs. The difference between inputs balance
320 /// and outputs balance is the fee for this transaction.
321 ///
322 /// Not that this method also produces correct fee signatures.
323 ///
324 /// Format of inputs is specific for payment method. Usually it should reference payment transaction
325 /// with at least one output that corresponds to payment address that user owns.
326 ///
327 /// # Arguments
328 /// * `wallet_handle` - wallet handle
329 /// * `submitter_did` - DID of request sender
330 /// * `req_json` - initial transaction request as json
331 /// * `inputs_json` - the list of UTXO inputs as json array
332 ///
333 /// # Examples
334 /// inputs_json:
335 /// ["input1", ...]
336 /// Notes:
337 /// - each input should reference paymentAddress
338 /// - this param will be used to determine payment_method
339 /// outputs_json: The list of UTXO outputs as json array:
340 /// [{
341 /// paymentAddress: <str>, // payment address used as output
342 /// amount: <int>, // amount of tokens to transfer to this payment address
343 /// extra: <str>, // optional data
344 /// }]
345 ///
346 /// # Returns
347 /// * `req_with_fees_json` - modified Indy request with added fees info
348 /// * `payment_method`
349 pub fn add_request_fees(wallet_handle: IndyHandle,
350 submitter_did: &str,
351 req_json: &str,
352 inputs_json: &str,
353 outputs_json: &str,
354 extra: Option<&str>) -> Result<(String, String), ErrorCode> {
355 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
356
357 let err = Payment::_add_request_fees(command_handle, wallet_handle, submitter_did, req_json, inputs_json, outputs_json, extra, cb);
358
359 ResultHandler::two(err, receiver)
360 }
361
362 /// Modifies Indy request by adding information how to pay fees for this transaction
363 /// according to selected payment method.
364 ///
365 /// Payment selection is performed by looking to o
366 ///
367 /// This method consumes set of UTXO inputs and outputs. The difference between inputs balance
368 /// and outputs balance is the fee for this transaction.
369 ///
370 /// Not that this method also produces correct fee signatures.
371 ///
372 /// Format of inputs is specific for payment method. Usually it should reference payment transaction
373 /// with at least one output that corresponds to payment address that user owns.
374 ///
375 /// # Arguments
376 /// * `wallet_handle` - wallet handle
377 /// * `submitter_did` - DID of request sender
378 /// * `req_json` - initial transaction request as json
379 /// * `inputs_json` - the list of UTXO inputs as json array
380 /// * `timeout` - the maximum time this function waits for a response
381 ///
382 /// # Examples
383 /// inputs_json:
384 /// ["input1", ...]
385 /// Notes:
386 /// - each input should reference paymentAddress
387 /// - this param will be used to determine payment_method
388 /// outputs_json: The list of UTXO outputs as json array:
389 /// [{
390 /// paymentAddress: <str>, // payment address used as output
391 /// amount: <int>, // amount of tokens to transfer to this payment address
392 /// extra: <str>, // optional data
393 /// }]
394 ///
395 /// # Returns
396 /// * `req_with_fees_json` - modified Indy request with added fees info
397 /// * `payment_method`
398 pub fn add_request_fees_timeout(wallet_handle: IndyHandle,
399 submitter_did: &str,
400 req_json: &str,
401 inputs_json: &str,
402 outputs_json: &str,
403 extra: Option<&str>,
404 timeout: Duration) -> Result<(String, String), ErrorCode> {
405 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
406
407 let err = Payment::_add_request_fees(command_handle, wallet_handle, submitter_did, req_json, inputs_json, outputs_json, extra, cb);
408
409 ResultHandler::two_timeout(err, receiver, timeout)
410 }
411
412 /// Modifies Indy request by adding information how to pay fees for this transaction
413 /// according to selected payment method.
414 ///
415 /// Payment selection is performed by looking to o
416 ///
417 /// This method consumes set of UTXO inputs and outputs. The difference between inputs balance
418 /// and outputs balance is the fee for this transaction.
419 ///
420 /// Not that this method also produces correct fee signatures.
421 ///
422 /// Format of inputs is specific for payment method. Usually it should reference payment transaction
423 /// with at least one output that corresponds to payment address that user owns.
424 ///
425 /// # Arguments
426 /// * `wallet_handle` - wallet handle
427 /// * `submitter_did` - DID of request sender
428 /// * `req_json` - initial transaction request as json
429 /// * `inputs_json` - the list of UTXO inputs as json array
430 /// * `closure` - the closure that is called when finished
431 ///
432 /// # Examples
433 /// inputs_json:
434 /// ["input1", ...]
435 /// Notes:
436 /// - each input should reference paymentAddress
437 /// - this param will be used to determine payment_method
438 /// outputs_json: The list of UTXO outputs as json array:
439 /// [{
440 /// paymentAddress: <str>, // payment address used as output
441 /// amount: <int>, // amount of tokens to transfer to this payment address
442 /// extra: <str>, // optional data
443 /// }]
444 ///
445 /// # Returns
446 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
447 pub fn add_request_fees_async<F: 'static>(wallet_handle: IndyHandle,
448 submitter_did: &str,
449 req_json: &str,
450 inputs_json: &str,
451 outputs_json: &str,
452 extra: Option<&str>,
453 closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
454 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));
455
456 Payment::_add_request_fees(command_handle, wallet_handle, submitter_did, req_json, inputs_json, outputs_json, extra, cb)
457 }
458
459 fn _add_request_fees(command_handle: IndyHandle,
460 wallet_handle: IndyHandle,
461 submitter_did: &str,
462 req_json: &str,
463 inputs_json: &str,
464 outputs_json: &str,
465 extra: Option<&str>,
466 cb: Option<ResponseStringStringCB>) -> ErrorCode {
467 let submitter_did = c_str!(submitter_did);
468 let req_json = c_str!(req_json);
469 let inputs_json = c_str!(inputs_json);
470 let outputs_json = c_str!(outputs_json);
471 let extra_str = opt_c_str!(extra);
472
473 ErrorCode::from(unsafe {
474 payments::indy_add_request_fees(command_handle,
475 wallet_handle,
476 submitter_did.as_ptr(),
477 req_json.as_ptr(),
478 inputs_json.as_ptr(),
479 outputs_json.as_ptr(),
480 opt_c_ptr!(extra, extra_str),
481 cb)
482 })
483 }
484
485 /// Parses response for Indy request with fees.
486 ///
487 /// # Arguments
488 /// * `payment_method`
489 /// * `resp_json`: response for Indy request with fees
490 /// Note: this param will be used to determine payment_method
491 ///
492 /// # Returns
493 /// * `utxo_json` - parsed (payment method and node version agnostic) utxo info as json
494 ///
495 /// # Example
496 /// utxo_json
497 /// [{
498 /// input: <str>, // UTXO input
499 /// amount: <int>, // amount of tokens in this input
500 /// extra: <str>, // optional data from payment transaction
501 /// }]
502 pub fn parse_response_with_fees(payment_method: &str, resp_json: &str) -> Result<String, ErrorCode> {
503 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
504
505 let err = Payment::_parse_response_with_fees(command_handle, payment_method, resp_json, cb);
506
507 ResultHandler::one(err, receiver)
508 }
509
510 /// Parses response for Indy request with fees.
511 ///
512 /// # Arguments
513 /// * `payment_method`
514 /// * `resp_json`: response for Indy request with fees
515 /// * `timeout` - the maximum time this function waits for a response
516 /// Note: this param will be used to determine payment_method
517 ///
518 /// # Returns
519 /// * `utxo_json` - parsed (payment method and node version agnostic) utxo info as json
520 ///
521 /// # Example
522 /// utxo_json
523 /// [{
524 /// input: <str>, // UTXO input
525 /// amount: <int>, // amount of tokens in this input
526 /// extra: <str>, // optional data from payment transaction
527 /// }]
528 pub fn parse_response_with_fees_timeout(payment_method: &str, resp_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
529 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
530
531 let err = Payment::_parse_response_with_fees(command_handle, payment_method, resp_json, cb);
532
533 ResultHandler::one_timeout(err, receiver, timeout)
534 }
535
536 /// Parses response for Indy request with fees.
537 ///
538 /// # Arguments
539 /// * `payment_method`
540 /// * `resp_json`: response for Indy request with fees
541 /// * `closure` - the closure that is called when finished
542 /// Note: this param will be used to determine payment_method
543 ///
544 /// # Returns
545 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
546 pub fn parse_response_with_fees_async<F: 'static>(payment_method: &str, resp_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
547 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
548 Payment::_parse_response_with_fees(command_handle, payment_method, resp_json, cb)
549 }
550
551 fn _parse_response_with_fees(command_handle: IndyHandle, payment_method: &str, resp_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
552 let payment_method = c_str!(payment_method);
553 let resp_json = c_str!(resp_json);
554
555 ErrorCode::from(unsafe { payments::indy_parse_response_with_fees(command_handle, payment_method.as_ptr(), resp_json.as_ptr(), cb) })
556 }
557
558 /// Builds Indy request for getting UTXO list for payment address
559 /// according to this payment method.
560 ///
561 /// # Arguments
562 /// * `wallet_handle` - wallet handle
563 /// * `submitter_did` - DID of request sender
564 /// * `payment_address` -: target payment address
565 ///
566 /// # Returns
567 /// * `get_utxo_txn_json` - Indy request for getting UTXO list for payment address
568 /// * `payment_method`
569 pub fn build_get_payment_sources_request(wallet_handle: IndyHandle, submitter_did: &str, payment_address: &str) -> Result<(String, String), ErrorCode> {
570 let (receiver, command_handle, cb) =
571 ClosureHandler::cb_ec_string_string();
572
573 let err = Payment::_build_get_payment_sources_request(command_handle, wallet_handle, submitter_did, payment_address, cb);
574
575 ResultHandler::two(err, receiver)
576 }
577
578 /// Builds Indy request for getting UTXO list for payment address
579 /// according to this payment method.
580 ///
581 /// # Arguments
582 /// * `wallet_handle` - wallet handle
583 /// * `submitter_did` - DID of request sender
584 /// * `payment_address` -: target payment address
585 /// * `timeout` - the maximum time this function waits for a response
586 ///
587 /// # Returns
588 /// * `get_utxo_txn_json` - Indy request for getting UTXO list for payment address
589 /// * `payment_method`
590 pub fn build_get_payment_sources_request_timeout(wallet_handle: IndyHandle, submitter_did: &str, payment_address: &str, timeout: Duration) -> Result<(String, String), ErrorCode> {
591 let (receiver, command_handle, cb) =
592 ClosureHandler::cb_ec_string_string();
593
594 let err = Payment::_build_get_payment_sources_request(command_handle, wallet_handle, submitter_did, payment_address, cb);
595
596 ResultHandler::two_timeout(err, receiver, timeout)
597 }
598
599 /// Builds Indy request for getting UTXO list for payment address
600 /// according to this payment method.
601 ///
602 /// # Arguments
603 /// * `wallet_handle` - wallet handle
604 /// * `submitter_did` - DID of request sender
605 /// * `payment_address` -: target payment address
606 /// * `closure` - the closure that is called when finished
607 ///
608 /// # Returns
609 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
610 pub fn build_get_payment_sources_request_async<F: 'static>(wallet_handle: IndyHandle, submitter_did: &str, payment_address: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
611 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));
612 Payment::_build_get_payment_sources_request(command_handle, wallet_handle, submitter_did, payment_address, cb)
613 }
614
615 fn _build_get_payment_sources_request(command_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, payment_address: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
616 let submitter_did = c_str!(submitter_did);
617 let payment_address = c_str!(payment_address);
618
619 ErrorCode::from(unsafe { payments::indy_build_get_payment_sources_request(command_handle, wallet_handle, submitter_did.as_ptr(), payment_address.as_ptr(), cb) })
620 }
621
622 /// Parses response for Indy request for getting UTXO list.
623 ///
624 /// # Arguments
625 /// * `payment_method`
626 /// * `resp_json` - response for Indy request for getting UTXO list
627 /// Note: this param will be used to determine payment_method
628 ///
629 /// # Returns
630 /// * `utxo_json` - parsed (payment method and node version agnostic) utxo info as json:
631 /// # Examples:
632 /// [{
633 /// input: <str>, // UTXO input
634 /// amount: <int>, // amount of tokens in this input
635 /// extra: <str>, // optional data from payment transaction
636 /// }]
637 pub fn parse_get_payment_sources_response(payment_method: &str, resp_json: &str) -> Result<String, ErrorCode> {
638 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
639
640 let err = Payment::_parse_get_payment_sources_response(command_handle, payment_method, resp_json, cb);
641
642 ResultHandler::one(err, receiver)
643 }
644
645 /// Parses response for Indy request for getting UTXO list.
646 ///
647 /// # Arguments
648 /// * `payment_method`
649 /// * `resp_json` - response for Indy request for getting UTXO list
650 /// * `timeout` - the maximum time this function waits for a response
651 /// Note: this param will be used to determine payment_method
652 ///
653 /// # Returns
654 /// * `utxo_json` - parsed (payment method and node version agnostic) utxo info as json:
655 /// # Examples:
656 /// [{
657 /// input: <str>, // UTXO input
658 /// amount: <int>, // amount of tokens in this input
659 /// extra: <str>, // optional data from payment transaction
660 /// }]
661 pub fn parse_get_payment_sources_response_timeout(payment_method: &str, resp_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
662 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
663
664 let err = Payment::_parse_get_payment_sources_response(command_handle, payment_method, resp_json, cb);
665
666 ResultHandler::one_timeout(err, receiver, timeout)
667 }
668
669 /// Parses response for Indy request for getting UTXO list.
670 ///
671 /// # Arguments
672 /// * `payment_method`
673 /// * `resp_json` - response for Indy request for getting UTXO list
674 /// * `closure` - the closure that is called when finished
675 /// Note: this param will be used to determine payment_method
676 ///
677 /// # Returns
678 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
679 pub fn parse_get_payment_sources_response_async<F: 'static>(payment_method: &str, resp_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send{
680 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
681
682 Payment::_parse_get_payment_sources_response(command_handle, payment_method, resp_json, cb)
683 }
684
685 fn _parse_get_payment_sources_response(command_handle: IndyHandle, payment_method: &str, resp_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
686 let payment_method = c_str!(payment_method);
687 let resp_json = c_str!(resp_json);
688
689 ErrorCode::from(unsafe { payments::indy_parse_get_payment_sources_response(command_handle, payment_method.as_ptr(), resp_json.as_ptr(), cb) })
690 }
691
692 /// Builds Indy request for doing tokens payment
693 /// according to this payment method.
694 ///
695 /// This method consumes set of UTXO inputs and outputs.
696 ///
697 /// Format of inputs is specific for payment method. Usually it should reference payment transaction
698 /// with at least one output that corresponds to payment address that user owns.
699 ///
700 /// # Arguments
701 /// * `wallet_handle` - wallet handle
702 /// * `submitter_did` - DID of request sender
703 /// * `inputs_json` - The list of UTXO inputs as json array:
704 /// ["input1", ...]
705 /// Note that each input should reference paymentAddress
706 /// * `outputs_json` - The list of UTXO outputs as json array:
707 /// [{
708 /// paymentAddress: <str>, // payment address used as output
709 /// amount: <int>, // amount of tokens to transfer to this payment address
710 /// extra: <str>, // optional data
711 /// }]
712 ///
713 /// # Returns
714 /// * `payment_req_json` - Indy request for doing tokens payment
715 /// * `payment_method`
716 pub fn build_payment_req(wallet_handle: IndyHandle, submitter_did: &str, inputs: &str, outputs: &str, extra: Option<&str>) -> Result<(String, String), ErrorCode> {
717 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
718
719 let err = Payment::_build_payment_req(command_handle, wallet_handle, submitter_did, inputs, outputs, extra, cb);
720
721 ResultHandler::two(err, receiver)
722 }
723
724 /// Builds Indy request for doing tokens payment
725 /// according to this payment method.
726 ///
727 /// This method consumes set of UTXO inputs and outputs.
728 ///
729 /// Format of inputs is specific for payment method. Usually it should reference payment transaction
730 /// with at least one output that corresponds to payment address that user owns.
731 ///
732 /// # Arguments
733 /// * `wallet_handle` - wallet handle
734 /// * `submitter_did` - DID of request sender
735 /// * `inputs_json` - The list of UTXO inputs as json array:
736 /// ["input1", ...]
737 /// Note that each input should reference paymentAddress
738 /// * `outputs_json` - The list of UTXO outputs as json array:
739 /// [{
740 /// paymentAddress: <str>, // payment address used as output
741 /// amount: <int>, // amount of tokens to transfer to this payment address
742 /// extra: <str>, // optional data
743 /// }]
744 /// * `timeout` - the maximum time this function waits for a response
745 ///
746 /// # Returns
747 /// * `payment_req_json` - Indy request for doing tokens payment
748 /// * `payment_method`
749 pub fn build_payment_req_timeout(wallet_handle: IndyHandle, submitter_did: &str, inputs: &str, outputs: &str, extra: Option<&str>, timeout: Duration) -> Result<(String, String), ErrorCode> {
750 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
751
752 let err = Payment::_build_payment_req(command_handle, wallet_handle, submitter_did, inputs, outputs, extra, cb);
753
754 ResultHandler::two_timeout(err, receiver, timeout)
755 }
756
757 /// Builds Indy request for doing tokens payment
758 /// according to this payment method.
759 ///
760 /// This method consumes set of UTXO inputs and outputs.
761 ///
762 /// Format of inputs is specific for payment method. Usually it should reference payment transaction
763 /// with at least one output that corresponds to payment address that user owns.
764 ///
765 /// # Arguments
766 /// * `wallet_handle` - wallet handle
767 /// * `submitter_did` - DID of request sender
768 /// * `inputs_json` - The list of UTXO inputs as json array:
769 /// ["input1", ...]
770 /// Note that each input should reference paymentAddress
771 /// * `outputs_json` - The list of UTXO outputs as json array:
772 /// [{
773 /// paymentAddress: <str>, // payment address used as output
774 /// amount: <int>, // amount of tokens to transfer to this payment address
775 /// extra: <str>, // optional data
776 /// }]
777 /// * `closure` - the closure that is called when finished
778 ///
779 /// # Returns
780 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
781 pub fn build_payment_req_async<F: 'static>(wallet_handle: IndyHandle, submitter_did: &str, inputs: &str, outputs: &str, extra: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
782 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));
783
784 Payment::_build_payment_req(command_handle, wallet_handle, submitter_did, inputs, outputs, extra, cb)
785 }
786
787 fn _build_payment_req(command_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, inputs: &str, outputs: &str, extra: Option<&str>, cb: Option<ResponseStringStringCB>) -> ErrorCode {
788 let submitter_did = c_str!(submitter_did);
789 let inputs = c_str!(inputs);
790 let outputs = c_str!(outputs);
791 let extra_str = opt_c_str!(extra);
792
793 ErrorCode::from(unsafe {
794 payments::indy_build_payment_req(command_handle,
795 wallet_handle,
796 submitter_did.as_ptr(),
797 inputs.as_ptr(),
798 outputs.as_ptr(),
799 opt_c_ptr!(extra, extra_str),
800 cb)
801 })
802 }
803
804 /// Parses response for Indy request for payment txn.
805 ///
806 /// # Arguments
807 /// * `command_handle`
808 /// * `payment_method`
809 /// * `resp_json` - response for Indy request for payment txn
810 /// Note: this param will be used to determine payment_method
811 ///
812 /// # Returns
813 /// * `utxo_json` - parsed (payment method and node version agnostic) utxo info as jso-n
814 /// [{
815 /// input: <str>, // UTXO input
816 /// amount: <int>, // amount of tokens in this input
817 /// extra: <str>, // optional data from payment transaction
818 /// }]
819 pub fn parse_payment_response(payment_method: &str, resp_json: &str) -> Result<String, ErrorCode> {
820 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
821
822 let err = Payment::_parse_payment_response(command_handle, payment_method, resp_json, cb);
823
824 ResultHandler::one(err, receiver)
825 }
826
827 /// Parses response for Indy request for payment txn.
828 ///
829 /// # Arguments
830 /// * `command_handle`
831 /// * `payment_method`
832 /// * `resp_json` - response for Indy request for payment txn
833 /// * `timeout` - the maximum time this function waits for a response
834 /// Note: this param will be used to determine payment_method
835 ///
836 /// # Returns
837 /// * `utxo_json` - parsed (payment method and node version agnostic) utxo info as jso-n
838 /// [{
839 /// input: <str>, // UTXO input
840 /// amount: <int>, // amount of tokens in this input
841 /// extra: <str>, // optional data from payment transaction
842 /// }]
843 pub fn parse_payment_response_timeout(payment_method: &str, resp_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
844 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
845
846 let err = Payment::_parse_payment_response(command_handle, payment_method, resp_json, cb);
847
848 ResultHandler::one_timeout(err, receiver, timeout)
849 }
850
851 /// Parses response for Indy request for payment txn.
852 ///
853 /// # Arguments
854 /// * `command_handle`
855 /// * `payment_method`
856 /// * `resp_json` - response for Indy request for payment txn
857 /// * `closure` - the closure that is called when finished
858 /// Note: this param will be used to determine payment_method
859 ///
860 /// # Returns
861 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
862 pub fn parse_payment_response_async<F: 'static>(payment_method: &str, resp_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
863 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
864
865 Payment::_parse_payment_response(command_handle, payment_method, resp_json, cb)
866 }
867
868 fn _parse_payment_response(command_handle: IndyHandle, payment_method: &str, resp_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
869 let payment_method = c_str!(payment_method);
870 let resp_json = c_str!(resp_json);
871
872 ErrorCode::from(unsafe { payments::indy_parse_payment_response(command_handle, payment_method.as_ptr(), resp_json.as_ptr(), cb) })
873
874 }
875
876 /// Builds Indy request for doing tokens minting
877 /// according to this payment method.
878 ///
879 /// # Arguments
880 /// * `wallet_handle` - wallet handle
881 /// * `submitter_did` - DID of request sender
882 /// * `outputs_json` - The list of UTXO outputs as json array:
883 /// [{
884 /// paymentAddress: <str>, // payment address used as output
885 /// amount: <int>, // amount of tokens to transfer to this payment address
886 /// extra: <str>, // optional data
887 /// }]
888 ///
889 /// # Returns
890 /// * `mint_req_json` - Indy request for doing tokens minting
891 /// * `payment_method`
892 pub fn build_mint_req(wallet_handle: IndyHandle, submitter_did: &str, outputs_json: &str, extra: Option<&str>) -> Result<(String, String), ErrorCode> {
893 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
894
895 let err = Payment::_build_mint_req(command_handle, wallet_handle, submitter_did, outputs_json, extra, cb);
896
897 ResultHandler::two(err, receiver)
898 }
899
900 /// Builds Indy request for doing tokens minting
901 /// according to this payment method.
902 ///
903 /// # Arguments
904 /// * `wallet_handle` - wallet handle
905 /// * `submitter_did` - DID of request sender
906 /// * `outputs_json` - The list of UTXO outputs as json array:
907 /// [{
908 /// paymentAddress: <str>, // payment address used as output
909 /// amount: <int>, // amount of tokens to transfer to this payment address
910 /// extra: <str>, // optional data
911 /// }]
912 /// * `timeout` - the maximum time this function waits for a response
913 ///
914 /// # Returns
915 /// * `mint_req_json` - Indy request for doing tokens minting
916 /// * `payment_method`
917 pub fn build_mint_req_timeout(wallet_handle: IndyHandle, submitter_did: &str, outputs_json: &str, extra: Option<&str>, timeout: Duration) -> Result<(String, String), ErrorCode> {
918 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
919
920 let err = Payment::_build_mint_req(command_handle, wallet_handle, submitter_did, outputs_json, extra, cb);
921
922 ResultHandler::two_timeout(err, receiver, timeout)
923 }
924
925 /// Builds Indy request for doing tokens minting
926 /// according to this payment method.
927 ///
928 /// # Arguments
929 /// * `wallet_handle` - wallet handle
930 /// * `submitter_did` - DID of request sender
931 /// * `outputs_json` - The list of UTXO outputs as json array:
932 /// [{
933 /// paymentAddress: <str>, // payment address used as output
934 /// amount: <int>, // amount of tokens to transfer to this payment address
935 /// extra: <str>, // optional data
936 /// }]
937 /// * `closure` - the closure that is called when finished
938 ///
939 /// # Returns
940 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
941 pub fn build_mint_req_async<F: 'static>(wallet_handle: IndyHandle, submitter_did: &str, outputs_json: &str, extra: Option<&str>, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
942 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));
943
944 Payment::_build_mint_req(command_handle, wallet_handle, submitter_did, outputs_json, extra, cb)
945 }
946
947 fn _build_mint_req(command_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, outputs_json: &str, extra: Option<&str>, cb: Option<ResponseStringStringCB>) -> ErrorCode {
948 let submitter_did = c_str!(submitter_did);
949 let outputs_json = c_str!(outputs_json);
950 let extra_str = opt_c_str!(extra);
951
952 ErrorCode::from(unsafe { payments::indy_build_mint_req(command_handle, wallet_handle, submitter_did.as_ptr(), outputs_json.as_ptr(), opt_c_ptr!(extra, extra_str), cb) })
953 }
954
955 /// Builds Indy request for setting fees for transactions in the ledger
956 ///
957 /// # Arguments
958 /// * `wallet_handle` - wallet handle
959 /// * `submitter_did` - DID of request sender
960 /// * `payment_method`
961 /// * `fees_json` - {
962 /// txnType1: amount1,
963 /// txnType2: amount2,
964 /// .................
965 /// txnTypeN: amountN,
966 /// }
967 ///
968 /// # Returns
969 /// * `set_txn_fees_json` - Indy request for setting fees for transactions in the ledger
970 pub fn build_set_txn_fees_req(wallet_handle: IndyHandle, submitter_did: &str, payment_method: &str, fees_json: &str) -> Result<String, ErrorCode> {
971 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
972
973 let err = Payment::_build_set_txn_fees_req(command_handle, wallet_handle, submitter_did, payment_method, fees_json, cb);
974
975 ResultHandler::one(err, receiver)
976 }
977
978 /// Builds Indy request for setting fees for transactions in the ledger
979 ///
980 /// # Arguments
981 /// * `wallet_handle` - wallet handle
982 /// * `submitter_did` - DID of request sender
983 /// * `payment_method`
984 /// * `fees_json` - {
985 /// txnType1: amount1,
986 /// txnType2: amount2,
987 /// .................
988 /// txnTypeN: amountN,
989 /// }
990 /// * `timeout` - the maximum time this function waits for a response
991 ///
992 /// # Returns
993 /// * `set_txn_fees_json` - Indy request for setting fees for transactions in the ledger
994 pub fn build_set_txn_fees_req_timeout(wallet_handle: IndyHandle, submitter_did: &str, payment_method: &str, fees_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
995 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
996
997 let err = Payment::_build_set_txn_fees_req(command_handle, wallet_handle, submitter_did, payment_method, fees_json, cb);
998
999 ResultHandler::one_timeout(err, receiver, timeout)
1000 }
1001
1002 /// Builds Indy request for setting fees for transactions in the ledger
1003 ///
1004 /// # Arguments
1005 /// * `wallet_handle` - wallet handle
1006 /// * `submitter_did` - DID of request sender
1007 /// * `payment_method`
1008 /// * `fees_json` - {
1009 /// txnType1: amount1,
1010 /// txnType2: amount2,
1011 /// .................
1012 /// txnTypeN: amountN,
1013 /// }
1014 /// * `closure` - the closure that is called when finished
1015 ///
1016 /// # Returns
1017 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1018 pub fn build_set_txn_fees_req_async<F: 'static>(wallet_handle: IndyHandle, submitter_did: &str, payment_method: &str, fees_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1019 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1020
1021 Payment::_build_set_txn_fees_req(command_handle, wallet_handle, submitter_did, payment_method, fees_json, cb)
1022 }
1023
1024 fn _build_set_txn_fees_req(command_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, payment_method: &str, fees_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1025 let submitter_did = c_str!(submitter_did);
1026 let payment_method = c_str!(payment_method);
1027 let fees_json = c_str!(fees_json);
1028
1029 ErrorCode::from(unsafe { payments::indy_build_set_txn_fees_req(command_handle, wallet_handle, submitter_did.as_ptr(), payment_method.as_ptr(), fees_json.as_ptr(), cb) })
1030 }
1031
1032 /// Builds Indy get request for getting fees for transactions in the ledger
1033 ///
1034 /// # Arguments
1035 /// * `command_handle`
1036 /// * `wallet_handle` - wallet handle
1037 /// * `submitter_did` - DID of request sender
1038 /// * `payment_method`
1039 ///
1040 /// # Returns
1041 /// * `get_txn_fees_json` - Indy request for getting fees for transactions in the ledger
1042 pub fn build_get_txn_fees_req(wallet_handle: IndyHandle, submitter_did: &str, payment_method: &str) -> Result<String, ErrorCode> {
1043 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1044
1045 let err = Payment::_build_get_txn_fees_req(command_handle, wallet_handle, submitter_did, payment_method, cb);
1046
1047 ResultHandler::one(err, receiver)
1048 }
1049
1050 /// Builds Indy get request for getting fees for transactions in the ledger
1051 ///
1052 /// # Arguments
1053 /// * `command_handle`
1054 /// * `wallet_handle` - wallet handle
1055 /// * `submitter_did` - DID of request sender
1056 /// * `payment_method`
1057 /// * `timeout` - the maximum time this function waits for a response
1058 ///
1059 /// # Returns
1060 /// * `get_txn_fees_json` - Indy request for getting fees for transactions in the ledger
1061 pub fn build_get_txn_fees_req_timeout(wallet_handle: IndyHandle, submitter_did: &str, payment_method: &str, timeout: Duration) -> Result<String, ErrorCode> {
1062 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1063
1064 let err = Payment::_build_get_txn_fees_req(command_handle, wallet_handle, submitter_did, payment_method, cb);
1065
1066 ResultHandler::one_timeout(err, receiver, timeout)
1067 }
1068
1069 /// Builds Indy get request for getting fees for transactions in the ledger
1070 ///
1071 /// # Arguments
1072 /// * `command_handle`
1073 /// * `wallet_handle` - wallet handle
1074 /// * `submitter_did` - DID of request sender
1075 /// * `payment_method`
1076 /// * `closure` - the closure that is called when finished
1077 ///
1078 /// # Returns
1079 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1080 pub fn build_get_txn_fees_req_async<F: 'static>(wallet_handle: IndyHandle, submitter_did: &str, payment_method: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1081 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1082 Payment::_build_get_txn_fees_req(command_handle, wallet_handle, submitter_did, payment_method, cb)
1083 }
1084
1085 fn _build_get_txn_fees_req(command_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, payment_method: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1086 let submitter_did = c_str!(submitter_did);
1087 let payment_method = c_str!(payment_method);
1088
1089 ErrorCode::from(unsafe { payments::indy_build_get_txn_fees_req(command_handle, wallet_handle, submitter_did.as_ptr(), payment_method.as_ptr(), cb) })
1090 }
1091
1092 /// Parses response for Indy request for getting fees
1093 ///
1094 /// # Arguments
1095 /// * `command_handle`
1096 /// * `payment_method`
1097 /// * `resp_json` - response for Indy request for getting fees
1098 ///
1099 /// # Returns
1100 /// * `fees_json` {
1101 /// txnType1: amount1,
1102 /// txnType2: amount2,
1103 /// .................
1104 /// txnTypeN: amountN,
1105 /// }
1106 pub fn parse_get_txn_fees_response(payment_method: &str, resp_json: &str) -> Result<String, ErrorCode> {
1107 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1108
1109 let err = Payment::_parse_get_txn_fees_response(command_handle, payment_method, resp_json, cb);
1110
1111 ResultHandler::one(err, receiver)
1112 }
1113
1114 /// Parses response for Indy request for getting fees
1115 ///
1116 /// # Arguments
1117 /// * `command_handle`
1118 /// * `payment_method`
1119 /// * `resp_json` - response for Indy request for getting fees
1120 /// * `timeout` - the maximum time this function waits for a response
1121 ///
1122 /// # Returns
1123 /// * `fees_json` {
1124 /// txnType1: amount1,
1125 /// txnType2: amount2,
1126 /// .................
1127 /// txnTypeN: amountN,
1128 /// }
1129 pub fn parse_get_txn_fees_response_timeout(payment_method: &str, resp_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
1130 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1131
1132 let err = Payment::_parse_get_txn_fees_response(command_handle, payment_method, resp_json, cb);
1133
1134 ResultHandler::one_timeout(err, receiver, timeout)
1135 }
1136
1137 /// Parses response for Indy request for getting fees
1138 ///
1139 /// # Arguments
1140 /// * `command_handle`
1141 /// * `payment_method`
1142 /// * `resp_json` - response for Indy request for getting fees
1143 /// * `closure` - the closure that is called when finished
1144 ///
1145 /// # Returns
1146 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1147 pub fn parse_get_txn_fees_response_async<F: 'static>(payment_method: &str, resp_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1148 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1149
1150 Payment::_parse_get_txn_fees_response(command_handle, payment_method, resp_json, cb)
1151 }
1152
1153 fn _parse_get_txn_fees_response(command_handle: IndyHandle, payment_method: &str, resp_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1154 let payment_method = c_str!(payment_method);
1155 let resp_json = c_str!(resp_json);
1156
1157 ErrorCode::from(unsafe { payments::indy_parse_get_txn_fees_response(command_handle, payment_method.as_ptr(), resp_json.as_ptr(), cb) })
1158 }
1159
1160 pub fn build_verify_req(wallet_handle: IndyHandle, submitter_did: &str, receipt: &str) -> Result<(String, String), ErrorCode> {
1161 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
1162
1163 let err = Payment::_build_verify_req(command_handle, wallet_handle, submitter_did, receipt, cb);
1164
1165 ResultHandler::two(err, receiver)
1166 }
1167
1168 /// * `timeout` - the maximum time this function waits for a response
1169 pub fn build_verify_req_timeout(wallet_handle: IndyHandle, submitter_did: &str, receipt: &str, timeout: Duration) -> Result<(String, String), ErrorCode> {
1170 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string_string();
1171
1172 let err = Payment::_build_verify_req(command_handle, wallet_handle, submitter_did, receipt, cb);
1173
1174 ResultHandler::two_timeout(err, receiver, timeout)
1175 }
1176
1177 /// * `closure` - the closure that is called when finished
1178 ///
1179 /// # Returns
1180 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1181 pub fn build_verify_req_async<F: 'static>(wallet_handle: IndyHandle, submitter_did: &str, receipt: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String, String) + Send {
1182 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string_string(Box::new(closure));
1183
1184 Payment::_build_verify_req(command_handle, wallet_handle, submitter_did, receipt, cb)
1185 }
1186
1187 fn _build_verify_req(command_handle: IndyHandle, wallet_handle: IndyHandle, submitter_did: &str, receipt: &str, cb: Option<ResponseStringStringCB>) -> ErrorCode {
1188 let submitter_did = c_str!(submitter_did);
1189 let receipt = c_str!(receipt);
1190
1191 ErrorCode::from(unsafe {
1192 payments::indy_build_verify_payment_req(command_handle, wallet_handle, submitter_did.as_ptr(), receipt.as_ptr(), cb)
1193 })
1194 }
1195
1196 pub fn parse_verify_response(payment_method: &str, resp_json: &str) -> Result<String, ErrorCode> {
1197 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1198
1199 let err = Payment::_parse_verify_response(command_handle, payment_method, resp_json, cb);
1200
1201 ResultHandler::one(err, receiver)
1202 }
1203
1204 /// * `timeout` - the maximum time this function waits for a response
1205 pub fn parse_verify_response_timeout(payment_method: &str, resp_json: &str, timeout: Duration) -> Result<String, ErrorCode> {
1206 let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string();
1207
1208 let err = Payment::_parse_verify_response(command_handle, payment_method, resp_json, cb);
1209
1210 ResultHandler::one_timeout(err, receiver, timeout)
1211 }
1212
1213 /// * `closure` - the closure that is called when finished
1214 ///
1215 /// # Returns
1216 /// * `errorcode` - errorcode from calling ffi function. The closure receives the return result
1217 pub fn parse_verify_response_async<F: 'static>(payment_method: &str, resp_json: &str, closure: F) -> ErrorCode where F: FnMut(ErrorCode, String) + Send {
1218 let (command_handle, cb) = ClosureHandler::convert_cb_ec_string(Box::new(closure));
1219
1220 Payment::_parse_verify_response(command_handle, payment_method, resp_json, cb)
1221 }
1222
1223 fn _parse_verify_response(command_handle: IndyHandle, payment_method: &str, resp_json: &str, cb: Option<ResponseStringCB>) -> ErrorCode {
1224 let payment_method = c_str!(payment_method);
1225 let resp_json = c_str!(resp_json);
1226
1227 ErrorCode::from(unsafe {
1228 payments::indy_parse_verify_payment_response(command_handle, payment_method.as_ptr(), resp_json.as_ptr(), cb)
1229 })
1230 }
1231}