@@ -800,7 +800,9 @@ impl OutputCache {
800
800
confirmed_account_nonce,
801
801
) {
802
802
if let WalletTx :: Tx ( tx) = unconfirmed_tx {
803
- conflicting_txs. insert ( tx. get_transaction ( ) . get_id ( ) ) ;
803
+ if confirmed_tx. get_id ( ) != tx. get_transaction ( ) . get_id ( ) {
804
+ conflicting_txs. insert ( tx. get_transaction ( ) . get_id ( ) ) ;
805
+ }
804
806
}
805
807
}
806
808
}
@@ -811,14 +813,10 @@ impl OutputCache {
811
813
let mut conflicting_txs_with_descendants = vec ! [ ] ;
812
814
813
815
for conflicting_tx in conflicting_txs {
814
- if conflicting_tx != confirmed_tx. get_id ( ) {
815
- let descendants = self . remove_descendants_and_mark_as (
816
- conflicting_tx,
817
- TxState :: Conflicted ( block_id) ,
818
- ) ?;
816
+ let descendants =
817
+ self . remove_descendants_and_mark_as ( conflicting_tx, TxState :: Conflicted ( block_id) ) ?;
819
818
820
- conflicting_txs_with_descendants. extend ( descendants. into_iter ( ) ) ;
821
- }
819
+ conflicting_txs_with_descendants. extend ( descendants. into_iter ( ) ) ;
822
820
}
823
821
824
822
Ok ( conflicting_txs_with_descendants)
@@ -1468,65 +1466,75 @@ impl OutputCache {
1468
1466
match self . txs . entry ( tx_id. into ( ) ) {
1469
1467
Entry :: Occupied ( mut entry) => match entry. get_mut ( ) {
1470
1468
WalletTx :: Block ( _) => Err ( WalletError :: CannotFindTransactionWithId ( tx_id) ) ,
1471
- WalletTx :: Tx ( tx) => match tx. state ( ) {
1472
- TxState :: Inactive ( _) | TxState :: Conflicted ( _) | TxState :: Abandoned => {
1473
- tx. set_state ( new_state) ;
1474
- for input in tx. get_transaction ( ) . inputs ( ) {
1475
- match input {
1476
- TxInput :: Utxo ( outpoint) => {
1477
- self . consumed . insert ( outpoint. clone ( ) , * tx. state ( ) ) ;
1478
- }
1479
- TxInput :: Account ( outpoint) => match outpoint. account ( ) {
1480
- AccountSpending :: DelegationBalance ( delegation_id, _) => {
1481
- if let Some ( data) =
1482
- self . delegations . get_mut ( delegation_id)
1483
- {
1484
- data. last_nonce = outpoint. nonce ( ) . decrement ( ) ;
1485
- data. last_parent = find_parent (
1486
- & self . unconfirmed_descendants ,
1487
- tx_id. into ( ) ,
1488
- ) ;
1489
- }
1469
+ WalletTx :: Tx ( tx) => {
1470
+ ensure ! (
1471
+ tx. state( ) != & new_state,
1472
+ WalletError :: CannotChangeTransactionState ( * tx. state( ) , new_state)
1473
+ ) ;
1474
+
1475
+ match tx. state ( ) {
1476
+ TxState :: Inactive ( _) | TxState :: Conflicted ( _) | TxState :: Abandoned => {
1477
+ tx. set_state ( new_state) ;
1478
+ for input in tx. get_transaction ( ) . inputs ( ) {
1479
+ match input {
1480
+ TxInput :: Utxo ( outpoint) => {
1481
+ self . consumed . insert ( outpoint. clone ( ) , * tx. state ( ) ) ;
1490
1482
}
1491
- } ,
1492
- TxInput :: AccountCommand ( nonce, op) => match op {
1493
- AccountCommand :: MintTokens ( token_id, _)
1494
- | AccountCommand :: UnmintTokens ( token_id)
1495
- | AccountCommand :: LockTokenSupply ( token_id)
1496
- | AccountCommand :: FreezeToken ( token_id, _)
1497
- | AccountCommand :: UnfreezeToken ( token_id)
1498
- | AccountCommand :: ChangeTokenMetadataUri ( token_id, _)
1499
- | AccountCommand :: ChangeTokenAuthority ( token_id, _) => {
1500
- if let Some ( data) =
1501
- self . token_issuance . get_mut ( token_id)
1502
- {
1503
- data. last_nonce = nonce. decrement ( ) ;
1504
- data. last_parent = find_parent (
1505
- & self . unconfirmed_descendants ,
1506
- tx_id. into ( ) ,
1507
- ) ;
1508
- data. unconfirmed_txs . remove ( & tx_id. into ( ) ) ;
1483
+ TxInput :: Account ( outpoint) => match outpoint. account ( ) {
1484
+ AccountSpending :: DelegationBalance (
1485
+ delegation_id,
1486
+ _,
1487
+ ) => {
1488
+ if let Some ( data) =
1489
+ self . delegations . get_mut ( delegation_id)
1490
+ {
1491
+ data. last_nonce = outpoint. nonce ( ) . decrement ( ) ;
1492
+ data. last_parent = find_parent (
1493
+ & self . unconfirmed_descendants ,
1494
+ tx_id. into ( ) ,
1495
+ ) ;
1496
+ }
1509
1497
}
1510
- }
1511
- AccountCommand :: ConcludeOrder ( order_id)
1512
- | AccountCommand :: FillOrder ( order_id, _, _) => {
1513
- if let Some ( data) = self . orders . get_mut ( order_id) {
1514
- data. last_nonce = nonce. decrement ( ) ;
1515
- data. last_parent = find_parent (
1516
- & self . unconfirmed_descendants ,
1517
- tx_id. into ( ) ,
1518
- ) ;
1498
+ } ,
1499
+ TxInput :: AccountCommand ( nonce, op) => match op {
1500
+ AccountCommand :: MintTokens ( token_id, _)
1501
+ | AccountCommand :: UnmintTokens ( token_id)
1502
+ | AccountCommand :: LockTokenSupply ( token_id)
1503
+ | AccountCommand :: FreezeToken ( token_id, _)
1504
+ | AccountCommand :: UnfreezeToken ( token_id)
1505
+ | AccountCommand :: ChangeTokenMetadataUri ( token_id, _)
1506
+ | AccountCommand :: ChangeTokenAuthority ( token_id, _) => {
1507
+ if let Some ( data) =
1508
+ self . token_issuance . get_mut ( token_id)
1509
+ {
1510
+ data. last_nonce = nonce. decrement ( ) ;
1511
+ data. last_parent = find_parent (
1512
+ & self . unconfirmed_descendants ,
1513
+ tx_id. into ( ) ,
1514
+ ) ;
1515
+ data. unconfirmed_txs . remove ( & tx_id. into ( ) ) ;
1516
+ }
1519
1517
}
1520
- }
1521
- } ,
1518
+ AccountCommand :: ConcludeOrder ( order_id)
1519
+ | AccountCommand :: FillOrder ( order_id, _, _) => {
1520
+ if let Some ( data) = self . orders . get_mut ( order_id) {
1521
+ data. last_nonce = nonce. decrement ( ) ;
1522
+ data. last_parent = find_parent (
1523
+ & self . unconfirmed_descendants ,
1524
+ tx_id. into ( ) ,
1525
+ ) ;
1526
+ }
1527
+ }
1528
+ } ,
1529
+ }
1522
1530
}
1531
+ Ok ( ( ) )
1523
1532
}
1524
- Ok ( ( ) )
1533
+ TxState :: Confirmed ( ..) | TxState :: InMempool ( ..) => Err (
1534
+ WalletError :: CannotChangeTransactionState ( * tx. state ( ) , new_state) ,
1535
+ ) ,
1525
1536
}
1526
- TxState :: Confirmed ( ..) | TxState :: InMempool ( ..) => Err (
1527
- WalletError :: CannotChangeTransactionState ( * tx. state ( ) , new_state) ,
1528
- ) ,
1529
- } ,
1537
+ }
1530
1538
} ,
1531
1539
Entry :: Vacant ( _) => Err ( WalletError :: CannotFindTransactionWithId ( tx_id) ) ,
1532
1540
} ?;
0 commit comments