@@ -11,8 +11,8 @@ use crate::constants::LAST_BLOCK_HASH_KEY;
11
11
use crate :: db_utils:: SimpleDb ;
12
12
use crate :: interfaces:: {
13
13
node_type_as_str, AddressesWithOutPoints , BlockchainItem , BlockchainItemMeta ,
14
- BlockchainItemType , ComputeApi , DebugData , DruidPool , OutPointData , StoredSerializingBlock ,
15
- UserApiRequest , UserRequest , UtxoFetchType ,
14
+ BlockchainItemType , ComputeApi , DebugData , DruidPool , MineApiRequest , MineRequest , NodeType ,
15
+ OutPointData , StoredSerializingBlock , UserApiRequest , UserRequest , UtxoFetchType ,
16
16
} ;
17
17
use crate :: miner:: { BlockPoWReceived , CurrentBlockWithMutex } ;
18
18
use crate :: storage:: { get_stored_value_from_db, indexed_block_hash_key} ;
@@ -55,6 +55,11 @@ pub struct Addresses {
55
55
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
56
56
struct WalletInfo {
57
57
running_total : f64 ,
58
+ running_total_tokens : u64 ,
59
+ locked_total : f64 ,
60
+ locked_total_tokens : u64 ,
61
+ available_total : f64 ,
62
+ available_total_tokens : u64 ,
58
63
item_total : BTreeMap < String , u64 > , /* DRS tx hash - amount */
59
64
addresses : AddressesWithOutPoints ,
60
65
}
@@ -71,6 +76,7 @@ pub struct EncapsulatedPayment {
71
76
pub address : String ,
72
77
pub amount : TokenAmount ,
73
78
pub passphrase : String ,
79
+ pub locktime : Option < u64 > ,
74
80
}
75
81
76
82
/// Item asset creation structure received from client
@@ -172,7 +178,7 @@ pub async fn get_wallet_info(
172
178
) -> Result < JsonReply , JsonReply > {
173
179
let r = CallResponse :: new ( route, & call_id) ;
174
180
175
- let fund_store = match wallet_db. get_fund_store_err ( ) {
181
+ let mut fund_store = match wallet_db. get_fund_store_err ( ) {
176
182
Ok ( fund) => fund,
177
183
Err ( _) => return r. into_err_internal ( ApiErrorType :: CannotAccessWallet ) ,
178
184
} ;
@@ -200,15 +206,20 @@ pub async fn get_wallet_info(
200
206
. or_default ( )
201
207
. push ( OutPointData :: new ( out_point. clone ( ) , asset. clone ( ) ) ) ;
202
208
}
203
-
204
- let total = fund_store. running_total ( ) ;
205
- let ( running_total , item_total ) = (
206
- total . tokens . 0 as f64 / D_DISPLAY_PLACES ,
207
- total . items . clone ( ) ,
208
- ) ;
209
+ let locked_coinbase = wallet_db . get_locked_coinbase ( ) . await ;
210
+ let total = fund_store. running_total ( ) . clone ( ) ;
211
+ let available = {
212
+ fund_store . filter_locked_coinbase ( & locked_coinbase ) ;
213
+ fund_store . running_total ( )
214
+ } ;
209
215
let send_val = WalletInfo {
210
- running_total,
211
- item_total,
216
+ running_total : total. tokens . 0 as f64 / D_DISPLAY_PLACES ,
217
+ running_total_tokens : total. tokens . 0 ,
218
+ locked_total : ( total. tokens . 0 - available. tokens . 0 ) as f64 / D_DISPLAY_PLACES ,
219
+ locked_total_tokens : ( total. tokens . 0 - available. tokens . 0 ) ,
220
+ available_total : available. tokens . 0 as f64 / D_DISPLAY_PLACES ,
221
+ available_total_tokens : available. tokens . 0 ,
222
+ item_total : total. items ,
212
223
addresses,
213
224
} ;
214
225
@@ -401,6 +412,7 @@ pub async fn post_block_by_num(
401
412
402
413
/// Post to import new keypairs to the connected wallet
403
414
pub async fn post_import_keypairs (
415
+ peer : Node ,
404
416
db : WalletDb ,
405
417
keypairs : Addresses ,
406
418
route : & ' static str ,
@@ -409,6 +421,7 @@ pub async fn post_import_keypairs(
409
421
let response_keys: Vec < String > = keypairs. addresses . keys ( ) . cloned ( ) . collect ( ) ;
410
422
let response_data = json_serialize_embed ( response_keys) ;
411
423
let r = CallResponse :: new ( route, & call_id) ;
424
+ let addresses: Vec < String > = keypairs. addresses . keys ( ) . cloned ( ) . collect ( ) ;
412
425
413
426
let mut key_pairs_converted = BTreeMap :: new ( ) ;
414
427
for ( address, address_store_hex) in keypairs. addresses . into_iter ( ) {
@@ -439,6 +452,34 @@ pub async fn post_import_keypairs(
439
452
}
440
453
}
441
454
455
+ match peer. get_node_type ( ) {
456
+ NodeType :: Miner => {
457
+ // Update running total from compute node
458
+ if let Err ( e) = peer. inject_next_event (
459
+ peer. local_address ( ) ,
460
+ MineRequest :: MinerApi ( MineApiRequest :: RequestUTXOSet ( UtxoFetchType :: AnyOf (
461
+ addresses,
462
+ ) ) ) ,
463
+ ) {
464
+ error ! ( "route:update_running_total error: {:?}" , e) ;
465
+ return r. into_err_internal ( ApiErrorType :: CannotAccessMinerNode ) ;
466
+ }
467
+ }
468
+ NodeType :: User => {
469
+ // Update running total from compute node
470
+ if let Err ( e) = peer. inject_next_event (
471
+ peer. local_address ( ) ,
472
+ UserRequest :: UserApi ( UserApiRequest :: UpdateWalletFromUtxoSet {
473
+ address_list : UtxoFetchType :: AnyOf ( addresses) ,
474
+ } ) ,
475
+ ) {
476
+ error ! ( "route:update_running_total error: {:?}" , e) ;
477
+ return r. into_err_internal ( ApiErrorType :: CannotAccessUserNode ) ;
478
+ }
479
+ }
480
+ _ => return r. into_err_internal ( ApiErrorType :: InternalError ) ,
481
+ }
482
+
442
483
r. into_ok ( "Key-pairs successfully imported" , response_data)
443
484
}
444
485
@@ -454,6 +495,7 @@ pub async fn post_make_payment(
454
495
address,
455
496
amount,
456
497
passphrase,
498
+ locktime,
457
499
} = encapsulated_data;
458
500
459
501
let r = CallResponse :: new ( route, & call_id) ;
@@ -462,6 +504,7 @@ pub async fn post_make_payment(
462
504
Ok ( _) => UserRequest :: UserApi ( UserApiRequest :: MakePayment {
463
505
address : address. clone ( ) ,
464
506
amount,
507
+ locktime,
465
508
} ) ,
466
509
Err ( e) => {
467
510
return wallet_db_error ( e, r) ;
@@ -491,6 +534,7 @@ pub async fn post_make_ip_payment(
491
534
address,
492
535
amount,
493
536
passphrase,
537
+ locktime,
494
538
} = encapsulated_data;
495
539
496
540
let r = CallResponse :: new ( route, & call_id) ;
@@ -506,6 +550,7 @@ pub async fn post_make_ip_payment(
506
550
Ok ( _) => UserRequest :: UserApi ( UserApiRequest :: MakeIpPayment {
507
551
payment_peer,
508
552
amount,
553
+ locktime,
509
554
} ) ,
510
555
Err ( e) => {
511
556
return wallet_db_error ( e, r) ;
0 commit comments