@@ -261,6 +261,11 @@ impl Account {
261
261
262
262
total_fees_not_paid =
263
263
( total_fees_not_paid + preselected_fee) . ok_or ( WalletError :: OutputAmountOverflow ) ?;
264
+ total_fees_not_paid = preselected_inputs
265
+ . values ( )
266
+ . try_fold ( total_fees_not_paid, |total, ( _amount, fee) | total + * fee)
267
+ . ok_or ( WalletError :: OutputAmountOverflow ) ?;
268
+
264
269
let mut amount_to_be_paid_in_currency_with_fees = ( amount_to_be_paid_in_currency_with_fees
265
270
+ total_fees_not_paid)
266
271
. ok_or ( WalletError :: OutputAmountOverflow ) ?;
@@ -720,6 +725,8 @@ impl Account {
720
725
let outputs =
721
726
make_mint_token_outputs ( token_id, amount, address, self . chain_config . as_ref ( ) ) ?;
722
727
728
+ self . find_token ( & token_id) ?. total_supply . check_can_mint ( amount) ?;
729
+
723
730
self . change_token_supply_transaction (
724
731
token_id,
725
732
amount,
@@ -730,42 +737,6 @@ impl Account {
730
737
)
731
738
}
732
739
733
- fn change_token_supply_transaction (
734
- & mut self ,
735
- token_id : TokenId ,
736
- amount : Amount ,
737
- outputs : Vec < TxOutput > ,
738
- db_tx : & mut impl WalletStorageWriteUnlocked ,
739
- median_time : BlockTimestamp ,
740
- fee_rate : CurrentFeeRate ,
741
- ) -> Result < SignedTransaction , WalletError > {
742
- let token_data = self . find_token ( & token_id) ?;
743
- let nonce = token_data
744
- . last_nonce
745
- . map_or ( Some ( AccountNonce :: new ( 0 ) ) , |nonce| nonce. increment ( ) )
746
- . ok_or ( WalletError :: TokenIssuanceNonceOverflow ( token_id) ) ?;
747
- let tx_input = TxInput :: Account ( AccountOutPoint :: new (
748
- nonce,
749
- AccountSpending :: TokenSupply ( token_id, amount) ,
750
- ) ) ;
751
-
752
- let request = SendRequest :: new ( )
753
- . with_outputs ( outputs)
754
- . with_inputs_and_destinations ( [ ( tx_input, token_data. reissuance_controller . clone ( ) ) ] ) ;
755
-
756
- let request = self . select_inputs_for_send_request (
757
- request,
758
- vec ! [ ] ,
759
- db_tx,
760
- median_time,
761
- fee_rate. current_fee_rate ,
762
- fee_rate. consolidate_fee_rate ,
763
- ) ?;
764
-
765
- let tx = self . sign_transaction_from_req ( request, db_tx) ?;
766
- Ok ( tx)
767
- }
768
-
769
740
pub fn redeem_tokens (
770
741
& mut self ,
771
742
db_tx : & mut impl WalletStorageWriteUnlocked ,
@@ -776,6 +747,8 @@ impl Account {
776
747
) -> WalletResult < SignedTransaction > {
777
748
let outputs = make_redeem_token_outputs ( token_id, amount, self . chain_config . as_ref ( ) ) ?;
778
749
750
+ self . find_token ( & token_id) ?. total_supply . check_can_redeem ( amount) ?;
751
+
779
752
self . change_token_supply_transaction (
780
753
token_id,
781
754
amount,
@@ -795,6 +768,8 @@ impl Account {
795
768
) -> WalletResult < SignedTransaction > {
796
769
let outputs = make_lock_token_outputs ( token_id, self . chain_config . as_ref ( ) ) ?;
797
770
771
+ self . find_token ( & token_id) ?. total_supply . check_can_lock ( ) ?;
772
+
798
773
self . change_token_supply_transaction (
799
774
token_id,
800
775
Amount :: ZERO ,
@@ -805,6 +780,43 @@ impl Account {
805
780
)
806
781
}
807
782
783
+ fn change_token_supply_transaction (
784
+ & mut self ,
785
+ token_id : TokenId ,
786
+ amount : Amount ,
787
+ outputs : Vec < TxOutput > ,
788
+ db_tx : & mut impl WalletStorageWriteUnlocked ,
789
+ median_time : BlockTimestamp ,
790
+ fee_rate : CurrentFeeRate ,
791
+ ) -> Result < SignedTransaction , WalletError > {
792
+ let token_data = self . find_token ( & token_id) ?;
793
+
794
+ let nonce = token_data
795
+ . last_nonce
796
+ . map_or ( Some ( AccountNonce :: new ( 0 ) ) , |nonce| nonce. increment ( ) )
797
+ . ok_or ( WalletError :: TokenIssuanceNonceOverflow ( token_id) ) ?;
798
+ let tx_input = TxInput :: Account ( AccountOutPoint :: new (
799
+ nonce,
800
+ AccountSpending :: TokenSupply ( token_id, amount) ,
801
+ ) ) ;
802
+
803
+ let request = SendRequest :: new ( )
804
+ . with_outputs ( outputs)
805
+ . with_inputs_and_destinations ( [ ( tx_input, token_data. reissuance_controller . clone ( ) ) ] ) ;
806
+
807
+ let request = self . select_inputs_for_send_request (
808
+ request,
809
+ vec ! [ ] ,
810
+ db_tx,
811
+ median_time,
812
+ fee_rate. current_fee_rate ,
813
+ fee_rate. consolidate_fee_rate ,
814
+ ) ?;
815
+
816
+ let tx = self . sign_transaction_from_req ( request, db_tx) ?;
817
+ Ok ( tx)
818
+ }
819
+
808
820
pub fn get_pos_gen_block_data (
809
821
& self ,
810
822
db_tx : & impl WalletStorageReadUnlocked ,
@@ -1364,6 +1376,10 @@ impl Account {
1364
1376
}
1365
1377
}
1366
1378
1379
+ /// There are some preselected inputs like the Token account inputs with a nonce
1380
+ /// that need to be included in the request
1381
+ /// Here we group them up by currency and sum the total amount and fee they bring to the
1382
+ /// transaction
1367
1383
fn group_preselected_inputs (
1368
1384
request : & SendRequest ,
1369
1385
current_fee_rate : FeeRate ,
@@ -1433,7 +1449,18 @@ fn group_outputs<T, Grouped: Clone>(
1433
1449
}
1434
1450
TxOutput :: CreateStakePool ( _, stake) => OutputValue :: Coin ( stake. value ( ) ) ,
1435
1451
TxOutput :: DelegateStaking ( amount, _) => OutputValue :: Coin ( * amount) ,
1436
- TxOutput :: TokensOp ( _) | TxOutput :: CreateDelegationId ( _, _) => continue ,
1452
+ TxOutput :: TokensOp ( token_output) => match token_output {
1453
+ TokenOutput :: MintTokens ( token_id, amount, _) => {
1454
+ OutputValue :: TokenV1 ( * token_id, * amount)
1455
+ }
1456
+ TokenOutput :: RedeemTokens ( token_id, amount) => {
1457
+ OutputValue :: TokenV1 ( * token_id, * amount)
1458
+ }
1459
+ TokenOutput :: IssueFungibleToken ( _)
1460
+ | TokenOutput :: IssueNft ( _, _, _)
1461
+ | TokenOutput :: LockCirculatingSupply ( _) => continue ,
1462
+ } ,
1463
+ TxOutput :: CreateDelegationId ( _, _) => continue ,
1437
1464
TxOutput :: ProduceBlockFromStake ( _, _) => {
1438
1465
return Err ( WalletError :: UnsupportedTransactionOutput ( Box :: new (
1439
1466
get_tx_output ( & output) . clone ( ) ,
0 commit comments