@@ -6,8 +6,9 @@ use std::thread;
6
6
use utils:: cstring:: CStringUtils ;
7
7
use utils:: error;
8
8
use utils:: error:: error_string;
9
+ use error:: ToErrorCode ;
9
10
use serde_json;
10
- use utils:: libindy:: payments:: { get_wallet_token_info, create_address} ;
11
+ use utils:: libindy:: payments:: { pay_a_payee , get_wallet_token_info, create_address} ;
11
12
12
13
/// Get the total balance from all addresses contained in the configured wallet
13
14
///
@@ -371,13 +372,20 @@ pub extern fn vcx_wallet_send_tokens(command_handle: u32,
371
372
command_handle, payment_handle, tokens, recipient) ;
372
373
373
374
thread:: spawn ( move || {
374
- let msg = format ! ( "{{\" paid\" :\" true\" }}" ) ;
375
-
376
- info ! ( "vcx_wallet_send_tokens_cb(command_handle: {}, rc: {}, receipt: {})" ,
377
- command_handle, error_string( 0 ) , msg) ;
378
-
379
- let msg = CStringUtils :: string_to_cstring ( msg) ;
380
- cb ( command_handle, error:: SUCCESS . code_num , msg. as_ptr ( ) ) ;
375
+ match pay_a_payee ( tokens, & recipient) {
376
+ Ok ( msg) => {
377
+ info ! ( "vcx_wallet_send_tokens_cb(command_handle: {}, rc: {}, receipt: {})" ,
378
+ command_handle, error_string( 0 ) , msg) ;
379
+ let msg = CStringUtils :: string_to_cstring ( msg) ;
380
+ cb ( command_handle, error:: SUCCESS . code_num , msg. as_ptr ( ) ) ;
381
+ } ,
382
+ Err ( e) => {
383
+ let msg = "Failed to send tokens" . to_string ( ) ;
384
+ info ! ( "vcx_wallet_send_tokens_cb(command_handle: {}, rc: {}, reciept: {})" , command_handle, e. to_error_code( ) , msg) ;
385
+ let msg = CStringUtils :: string_to_cstring ( msg) ;
386
+ cb ( command_handle, e. to_error_code ( ) , msg. as_ptr ( ) ) ;
387
+ } ,
388
+ }
381
389
} ) ;
382
390
383
391
error:: SUCCESS . code_num
@@ -531,4 +539,27 @@ mod tests {
531
539
assert_eq ! ( vcx_wallet_create_payment_address( 0 , Some ( generic_cb) ) , error:: SUCCESS . code_num) ;
532
540
thread:: sleep ( Duration :: from_millis ( 200 ) ) ;
533
541
}
542
+
543
+ #[ cfg( feature = "nullpay" ) ]
544
+ #[ test]
545
+ fn test_send_payment ( ) {
546
+ use utils:: devsetup:: tests;
547
+ use utils:: libindy:: payments:: { mint_tokens, get_wallet_token_info, init_payments} ;
548
+ let name = "test_send_payment" ;
549
+ tests:: setup_dev_env ( name) ;
550
+ init_payments ( ) . unwrap ( ) ;
551
+ mint_tokens ( Some ( 1 ) , Some ( 1000 ) ) . unwrap ( ) ;
552
+ let balance = get_wallet_token_info ( ) . unwrap ( ) . get_balance ( ) ;
553
+ let recipient = CStringUtils :: string_to_cstring ( "pay:null:iXvVdM4mjCUZFrnnFU2F0VoJrkzQEoLy" . to_string ( ) ) ;
554
+ let command_handle = 0 ;
555
+ let payment_handle = 0 ;
556
+ let tokens = 100 ;
557
+ let cb = generic_cb;
558
+ let err = vcx_wallet_send_tokens ( command_handle, payment_handle, tokens, recipient. as_ptr ( ) , Some ( cb) ) ;
559
+ assert_eq ! ( err, 0 ) ;
560
+ thread:: sleep ( Duration :: from_secs ( 2 ) ) ;
561
+ let new_balance = get_wallet_token_info ( ) . unwrap ( ) . get_balance ( ) ;
562
+ assert_eq ! ( balance - tokens, new_balance) ;
563
+ tests:: cleanup_dev_env ( name) ;
564
+ }
534
565
}
0 commit comments