@@ -748,7 +748,9 @@ impl OutputCache {
748
748
confirmed_account_nonce,
749
749
) {
750
750
if let WalletTx :: Tx ( tx) = unconfirmed_tx {
751
- conflicting_txs. insert ( tx. get_transaction ( ) . get_id ( ) ) ;
751
+ if confirmed_tx. get_id ( ) != tx. get_transaction ( ) . get_id ( ) {
752
+ conflicting_txs. insert ( tx. get_transaction ( ) . get_id ( ) ) ;
753
+ }
752
754
}
753
755
}
754
756
}
@@ -759,14 +761,10 @@ impl OutputCache {
759
761
let mut conflicting_txs_with_descendants = vec ! [ ] ;
760
762
761
763
for conflicting_tx in conflicting_txs {
762
- if conflicting_tx != confirmed_tx. get_id ( ) {
763
- let descendants = self . remove_descendants_and_mark_as (
764
- conflicting_tx,
765
- TxState :: Conflicted ( block_id) ,
766
- ) ?;
764
+ let descendants =
765
+ self . remove_descendants_and_mark_as ( conflicting_tx, TxState :: Conflicted ( block_id) ) ?;
767
766
768
- conflicting_txs_with_descendants. extend ( descendants. into_iter ( ) ) ;
769
- }
767
+ conflicting_txs_with_descendants. extend ( descendants. into_iter ( ) ) ;
770
768
}
771
769
772
770
Ok ( conflicting_txs_with_descendants)
@@ -1431,65 +1429,75 @@ impl OutputCache {
1431
1429
match self . txs . entry ( tx_id. into ( ) ) {
1432
1430
Entry :: Occupied ( mut entry) => match entry. get_mut ( ) {
1433
1431
WalletTx :: Block ( _) => Err ( WalletError :: CannotFindTransactionWithId ( tx_id) ) ,
1434
- WalletTx :: Tx ( tx) => match tx. state ( ) {
1435
- TxState :: Inactive ( _) | TxState :: Conflicted ( _) | TxState :: Abandoned => {
1436
- tx. set_state ( new_state) ;
1437
- for input in tx. get_transaction ( ) . inputs ( ) {
1438
- match input {
1439
- TxInput :: Utxo ( outpoint) => {
1440
- self . consumed . insert ( outpoint. clone ( ) , * tx. state ( ) ) ;
1441
- }
1442
- TxInput :: Account ( outpoint) => match outpoint. account ( ) {
1443
- AccountSpending :: DelegationBalance ( delegation_id, _) => {
1444
- if let Some ( data) =
1445
- self . delegations . get_mut ( delegation_id)
1446
- {
1447
- data. last_nonce = outpoint. nonce ( ) . decrement ( ) ;
1448
- data. last_parent = find_parent (
1449
- & self . unconfirmed_descendants ,
1450
- tx_id. into ( ) ,
1451
- ) ;
1452
- }
1432
+ WalletTx :: Tx ( tx) => {
1433
+ ensure ! (
1434
+ tx. state( ) != & new_state,
1435
+ WalletError :: CannotChangeTransactionState ( * tx. state( ) , new_state)
1436
+ ) ;
1437
+
1438
+ match tx. state ( ) {
1439
+ TxState :: Inactive ( _) | TxState :: Conflicted ( _) | TxState :: Abandoned => {
1440
+ tx. set_state ( new_state) ;
1441
+ for input in tx. get_transaction ( ) . inputs ( ) {
1442
+ match input {
1443
+ TxInput :: Utxo ( outpoint) => {
1444
+ self . consumed . insert ( outpoint. clone ( ) , * tx. state ( ) ) ;
1453
1445
}
1454
- } ,
1455
- TxInput :: AccountCommand ( nonce, op) => match op {
1456
- AccountCommand :: MintTokens ( token_id, _)
1457
- | AccountCommand :: UnmintTokens ( token_id)
1458
- | AccountCommand :: LockTokenSupply ( token_id)
1459
- | AccountCommand :: FreezeToken ( token_id, _)
1460
- | AccountCommand :: UnfreezeToken ( token_id)
1461
- | AccountCommand :: ChangeTokenMetadataUri ( token_id, _)
1462
- | AccountCommand :: ChangeTokenAuthority ( token_id, _) => {
1463
- if let Some ( data) =
1464
- self . token_issuance . get_mut ( token_id)
1465
- {
1466
- data. last_nonce = nonce. decrement ( ) ;
1467
- data. last_parent = find_parent (
1468
- & self . unconfirmed_descendants ,
1469
- tx_id. into ( ) ,
1470
- ) ;
1471
- data. unconfirmed_txs . remove ( & tx_id. into ( ) ) ;
1446
+ TxInput :: Account ( outpoint) => match outpoint. account ( ) {
1447
+ AccountSpending :: DelegationBalance (
1448
+ delegation_id,
1449
+ _,
1450
+ ) => {
1451
+ if let Some ( data) =
1452
+ self . delegations . get_mut ( delegation_id)
1453
+ {
1454
+ data. last_nonce = outpoint. nonce ( ) . decrement ( ) ;
1455
+ data. last_parent = find_parent (
1456
+ & self . unconfirmed_descendants ,
1457
+ tx_id. into ( ) ,
1458
+ ) ;
1459
+ }
1472
1460
}
1473
- }
1474
- AccountCommand :: ConcludeOrder ( order_id)
1475
- | AccountCommand :: FillOrder ( order_id, _, _) => {
1476
- if let Some ( data) = self . orders . get_mut ( order_id) {
1477
- data. last_nonce = nonce. decrement ( ) ;
1478
- data. last_parent = find_parent (
1479
- & self . unconfirmed_descendants ,
1480
- tx_id. into ( ) ,
1481
- ) ;
1461
+ } ,
1462
+ TxInput :: AccountCommand ( nonce, op) => match op {
1463
+ AccountCommand :: MintTokens ( token_id, _)
1464
+ | AccountCommand :: UnmintTokens ( token_id)
1465
+ | AccountCommand :: LockTokenSupply ( token_id)
1466
+ | AccountCommand :: FreezeToken ( token_id, _)
1467
+ | AccountCommand :: UnfreezeToken ( token_id)
1468
+ | AccountCommand :: ChangeTokenMetadataUri ( token_id, _)
1469
+ | AccountCommand :: ChangeTokenAuthority ( token_id, _) => {
1470
+ if let Some ( data) =
1471
+ self . token_issuance . get_mut ( token_id)
1472
+ {
1473
+ data. last_nonce = nonce. decrement ( ) ;
1474
+ data. last_parent = find_parent (
1475
+ & self . unconfirmed_descendants ,
1476
+ tx_id. into ( ) ,
1477
+ ) ;
1478
+ data. unconfirmed_txs . remove ( & tx_id. into ( ) ) ;
1479
+ }
1482
1480
}
1483
- }
1484
- } ,
1481
+ AccountCommand :: ConcludeOrder ( order_id)
1482
+ | AccountCommand :: FillOrder ( order_id, _, _) => {
1483
+ if let Some ( data) = self . orders . get_mut ( order_id) {
1484
+ data. last_nonce = nonce. decrement ( ) ;
1485
+ data. last_parent = find_parent (
1486
+ & self . unconfirmed_descendants ,
1487
+ tx_id. into ( ) ,
1488
+ ) ;
1489
+ }
1490
+ }
1491
+ } ,
1492
+ }
1485
1493
}
1494
+ Ok ( ( ) )
1486
1495
}
1487
- Ok ( ( ) )
1496
+ TxState :: Confirmed ( ..) | TxState :: InMempool ( ..) => Err (
1497
+ WalletError :: CannotChangeTransactionState ( * tx. state ( ) , new_state) ,
1498
+ ) ,
1488
1499
}
1489
- TxState :: Confirmed ( ..) | TxState :: InMempool ( ..) => Err (
1490
- WalletError :: CannotChangeTransactionState ( * tx. state ( ) , new_state) ,
1491
- ) ,
1492
- } ,
1500
+ }
1493
1501
} ,
1494
1502
Entry :: Vacant ( _) => Err ( WalletError :: CannotFindTransactionWithId ( tx_id) ) ,
1495
1503
} ?;
0 commit comments