19
19
use crate :: unsafe_debug:: ExecutionObserver ;
20
20
use crate :: {
21
21
gas:: GasMeter ,
22
- storage:: { self , meter:: Diff , DepositAccount , WriteOutcome } ,
22
+ storage:: { self , meter:: Diff , WriteOutcome } ,
23
23
BalanceOf , CodeHash , CodeInfo , CodeInfoOf , Config , ContractInfo , ContractInfoOf ,
24
24
DebugBufferVec , Determinism , Error , Event , Nonce , Origin , Pallet as Contracts , Schedule ,
25
- System , WasmBlob , LOG_TARGET ,
25
+ WasmBlob , LOG_TARGET ,
26
26
} ;
27
27
use frame_support:: {
28
28
crypto:: ecdsa:: ECDSAExt ,
@@ -33,7 +33,7 @@ use frame_support::{
33
33
storage:: { with_transaction, TransactionOutcome } ,
34
34
traits:: {
35
35
fungible:: { Inspect , Mutate } ,
36
- tokens:: { Fortitude :: Polite , Preservation } ,
36
+ tokens:: Preservation ,
37
37
Contains , OriginTrait , Randomness , Time ,
38
38
} ,
39
39
weights:: Weight ,
@@ -547,7 +547,7 @@ enum CachedContract<T: Config> {
547
547
///
548
548
/// In this case a reload is neither allowed nor possible. Please note that recursive
549
549
/// calls cannot remove a contract as this is checked and denied.
550
- Terminated ( DepositAccount < T > ) ,
550
+ Terminated ,
551
551
}
552
552
553
553
impl < T : Config > CachedContract < T > {
@@ -568,15 +568,6 @@ impl<T: Config> CachedContract<T> {
568
568
None
569
569
}
570
570
}
571
-
572
- /// Returns `Some` iff the contract is not `Cached::Invalidated`.
573
- fn deposit_account ( & self ) -> Option < & DepositAccount < T > > {
574
- match self {
575
- CachedContract :: Cached ( contract) => Some ( contract. deposit_account ( ) ) ,
576
- CachedContract :: Terminated ( deposit_account) => Some ( & deposit_account) ,
577
- CachedContract :: Invalidated => None ,
578
- }
579
- }
580
571
}
581
572
582
573
impl < T : Config > Frame < T > {
@@ -655,9 +646,7 @@ impl<T: Config> CachedContract<T> {
655
646
/// Terminate and return the contract info.
656
647
fn terminate ( & mut self , account_id : & T :: AccountId ) -> ContractInfo < T > {
657
648
self . load ( account_id) ;
658
- let contract = get_cached_or_panic_after_load ! ( self ) ;
659
- let deposit_account = contract. deposit_account ( ) . clone ( ) ;
660
- get_cached_or_panic_after_load ! ( mem:: replace( self , Self :: Terminated ( deposit_account) ) )
649
+ get_cached_or_panic_after_load ! ( mem:: replace( self , Self :: Terminated ) )
661
650
}
662
651
}
663
652
@@ -955,7 +944,7 @@ where
955
944
match ( entry_point, delegated_code_hash) {
956
945
( ExportedFunction :: Constructor , _) => {
957
946
// It is not allowed to terminate a contract inside its constructor.
958
- if matches ! ( frame. contract_info, CachedContract :: Terminated ( _ ) ) {
947
+ if matches ! ( frame. contract_info, CachedContract :: Terminated ) {
959
948
return Err ( Error :: < T > :: TerminatedInConstructor . into ( ) )
960
949
}
961
950
@@ -1059,18 +1048,8 @@ where
1059
1048
// in its contract info. The load is necessary to pull it from storage in case
1060
1049
// it was invalidated.
1061
1050
frame. contract_info . load ( account_id) ;
1062
- let deposit_account = frame
1063
- . contract_info
1064
- . deposit_account ( )
1065
- . expect (
1066
- "Is only `None` when the info is invalidated.
1067
- We just re-loaded from storage which either makes the state `Cached` or `Terminated`.
1068
- qed" ,
1069
- )
1070
- . clone ( ) ;
1071
1051
let mut contract = frame. contract_info . into_contract ( ) ;
1072
- prev. nested_storage
1073
- . absorb ( frame. nested_storage , deposit_account, contract. as_mut ( ) ) ;
1052
+ prev. nested_storage . absorb ( frame. nested_storage , account_id, contract. as_mut ( ) ) ;
1074
1053
1075
1054
// In case the contract wasn't terminated we need to persist changes made to it.
1076
1055
if let Some ( contract) = contract {
@@ -1105,14 +1084,10 @@ where
1105
1084
if !persist {
1106
1085
return
1107
1086
}
1108
- let deposit_account = self . first_frame . contract_info . deposit_account ( ) . expect (
1109
- "Is only `None` when the info is invalidated. The first frame can't be invalidated.
1110
- qed" ,
1111
- ) . clone ( ) ;
1112
1087
let mut contract = self . first_frame . contract_info . as_contract ( ) ;
1113
1088
self . storage_meter . absorb (
1114
1089
mem:: take ( & mut self . first_frame . nested_storage ) ,
1115
- deposit_account ,
1090
+ & self . first_frame . account_id ,
1116
1091
contract. as_deref_mut ( ) ,
1117
1092
) ;
1118
1093
if let Some ( contract) = contract {
@@ -1311,14 +1286,8 @@ where
1311
1286
}
1312
1287
let frame = self . top_frame_mut ( ) ;
1313
1288
let info = frame. terminate ( ) ;
1314
- frame. nested_storage . terminate ( & info) ;
1315
- System :: < T > :: dec_consumers ( & frame. account_id ) ;
1316
- Self :: transfer (
1317
- Preservation :: Expendable ,
1318
- & frame. account_id ,
1319
- beneficiary,
1320
- T :: Currency :: reducible_balance ( & frame. account_id , Preservation :: Expendable , Polite ) ,
1321
- ) ?;
1289
+ frame. nested_storage . terminate ( & info, beneficiary. clone ( ) ) ;
1290
+
1322
1291
info. queue_trie_for_deletion ( ) ;
1323
1292
ContractInfoOf :: < T > :: remove ( & frame. account_id ) ;
1324
1293
E :: decrement_refcount ( info. code_hash ) ;
@@ -1327,7 +1296,7 @@ where
1327
1296
E :: decrement_refcount ( * code_hash) ;
1328
1297
frame
1329
1298
. nested_storage
1330
- . charge_deposit ( info . deposit_account ( ) . clone ( ) , StorageDeposit :: Refund ( * deposit) ) ;
1299
+ . charge_deposit ( frame . account_id . clone ( ) , StorageDeposit :: Refund ( * deposit) ) ;
1331
1300
}
1332
1301
1333
1302
Contracts :: < T > :: deposit_event (
@@ -1521,8 +1490,7 @@ where
1521
1490
let deposit = StorageDeposit :: Charge ( new_base_deposit)
1522
1491
. saturating_sub ( & StorageDeposit :: Charge ( old_base_deposit) ) ;
1523
1492
1524
- let deposit_account = info. deposit_account ( ) . clone ( ) ;
1525
- frame. nested_storage . charge_deposit ( deposit_account, deposit) ;
1493
+ frame. nested_storage . charge_deposit ( frame. account_id . clone ( ) , deposit) ;
1526
1494
1527
1495
E :: increment_refcount ( hash) ?;
1528
1496
E :: decrement_refcount ( prev_hash) ;
@@ -1573,7 +1541,7 @@ where
1573
1541
<WasmBlob < T > >:: increment_refcount ( code_hash) ?;
1574
1542
frame
1575
1543
. nested_storage
1576
- . charge_deposit ( info . deposit_account ( ) . clone ( ) , StorageDeposit :: Charge ( deposit) ) ;
1544
+ . charge_deposit ( frame . account_id . clone ( ) , StorageDeposit :: Charge ( deposit) ) ;
1577
1545
Ok ( ( ) )
1578
1546
}
1579
1547
@@ -1589,7 +1557,7 @@ where
1589
1557
1590
1558
frame
1591
1559
. nested_storage
1592
- . charge_deposit ( info . deposit_account ( ) . clone ( ) , StorageDeposit :: Refund ( deposit) ) ;
1560
+ . charge_deposit ( frame . account_id . clone ( ) , StorageDeposit :: Refund ( deposit) ) ;
1593
1561
Ok ( ( ) )
1594
1562
}
1595
1563
}
0 commit comments