@@ -255,7 +255,10 @@ pub trait WalletOnline: WalletOffline {
255255 ( inputs, usable_btc_amount)
256256 } else {
257257 inputs. push ( outpoint) ;
258- ( inputs, usable_btc_amount + value)
258+ let usable_btc_amount = usable_btc_amount
259+ . checked_add ( value)
260+ . expect ( "total UTXO value cannot exceed u64::MAX" ) ;
261+ ( inputs, usable_btc_amount)
259262 }
260263 } ,
261264 ) ;
@@ -1809,7 +1812,7 @@ pub trait WalletOnline: WalletOffline {
18091812 }
18101813
18111814 let mut assignments_collected = AssignmentsCollection :: default ( ) ;
1812- let mut input_btc_amt = 0 ;
1815+ let mut input_btc_amt: u64 = 0 ;
18131816 for unspent in mut_unspents {
18141817 // get spendable allocations for the required asset
18151818 let asset_allocations: Vec < LocalRgbAllocation > = unspent
@@ -1857,7 +1860,14 @@ pub trait WalletOnline: WalletOffline {
18571860 . for_each ( |a| a. assignment . add_to_assignments ( & mut assignments_collected) ) ;
18581861 input_outpoints. push ( unspent. utxo . outpoint ( ) ) ;
18591862
1860- input_btc_amt += unspent. utxo . btc_amount . parse :: < u64 > ( ) . unwrap ( ) ;
1863+ let utxo_btc_amt = unspent
1864+ . utxo
1865+ . btc_amount
1866+ . parse :: < u64 > ( )
1867+ . expect ( "DB should contain a valid BTC amount" ) ;
1868+ input_btc_amt = input_btc_amt
1869+ . checked_add ( utxo_btc_amt)
1870+ . expect ( "total input BTC value cannot exceed u64::MAX" ) ;
18611871
18621872 // stop as soon as we have the needed assignments
18631873 if assignments_collected. enough ( assignments_needed) {
@@ -1961,7 +1971,12 @@ pub trait WalletOnline: WalletOffline {
19611971 details : e. to_string ( ) ,
19621972 } ) ?;
19631973 }
1964- free_utxos. sort_by_key ( |u| u. utxo . btc_amount . parse :: < u64 > ( ) . unwrap ( ) ) ;
1974+ free_utxos. sort_by_key ( |u| {
1975+ u. utxo
1976+ . btc_amount
1977+ . parse :: < u64 > ( )
1978+ . expect ( "DB should contain a valid BTC amount" )
1979+ } ) ;
19651980 }
19661981 if let Some ( a) = free_utxos. pop ( ) {
19671982 all_inputs. insert ( a. utxo . into ( ) ) ;
@@ -3493,13 +3508,15 @@ pub trait WalletOnline: WalletOffline {
34933508 let ( asset_id, transfer_info) = info_contents. transfers . into_iter ( ) . next ( ) . unwrap ( ) ;
34943509 let inflation = transfer_info. original_assignments_needed . inflation ;
34953510 let db_asset = txn. get_asset ( asset_id) . unwrap ( ) . unwrap ( ) ;
3496- let updated_known_circulating_supply = db_asset
3511+ let known_circulating_supply = db_asset
34973512 . known_circulating_supply
34983513 . as_ref ( )
34993514 . unwrap ( )
35003515 . parse :: < u64 > ( )
3501- . unwrap ( )
3502- + inflation;
3516+ . expect ( "DB should contain a valid known circulating supply" ) ;
3517+ let updated_known_circulating_supply = known_circulating_supply
3518+ . checked_add ( inflation)
3519+ . expect ( "known circulating supply plus inflation cannot exceed u64::MAX" ) ;
35033520 let mut updated_asset: DbAssetActMod = db_asset. into ( ) ;
35043521 updated_asset. known_circulating_supply =
35053522 ActiveValue :: Set ( Some ( updated_known_circulating_supply. to_string ( ) ) ) ;
0 commit comments