@@ -25,81 +25,84 @@ use super::*;
25
25
/// any uncommitted changes (see `commit` function) will be automatically committed to storage when
26
26
/// dropped. Changes, even after committed, may be reverted to their original values with the
27
27
/// `revert` function.
28
- pub struct ExtraMutator < T : Config > {
29
- id : T :: AssetId ,
30
- who : T :: AccountId ,
31
- original : T :: Extra ,
32
- pending : Option < T :: Extra > ,
28
+ pub struct ExtraMutator < T : Config < I > , I : ' static = ( ) > {
29
+ id : T :: AssetId ,
30
+ who : T :: AccountId ,
31
+ original : T :: Extra ,
32
+ pending : Option < T :: Extra > ,
33
33
}
34
34
35
- impl < T : Config > Drop for ExtraMutator < T > {
36
- fn drop ( & mut self ) {
37
- debug_assert ! ( self . commit( ) . is_ok( ) , "attempt to write to non-existent asset account" ) ;
38
- }
35
+ impl < T : Config < I > , I : ' static > Drop for ExtraMutator < T , I > {
36
+ fn drop ( & mut self ) {
37
+ debug_assert ! (
38
+ self . commit( ) . is_ok( ) ,
39
+ "attempt to write to non-existent asset account"
40
+ ) ;
41
+ }
39
42
}
40
43
41
- impl < T : Config > sp_std:: ops:: Deref for ExtraMutator < T > {
42
- type Target = T :: Extra ;
43
- fn deref ( & self ) -> & T :: Extra {
44
- match self . pending {
45
- Some ( ref value) => value,
46
- None => & self . original ,
47
- }
48
- }
44
+ impl < T : Config < I > , I : ' static > sp_std:: ops:: Deref for ExtraMutator < T , I > {
45
+ type Target = T :: Extra ;
46
+ fn deref ( & self ) -> & T :: Extra {
47
+ match self . pending {
48
+ Some ( ref value) => value,
49
+ None => & self . original ,
50
+ }
51
+ }
49
52
}
50
53
51
- impl < T : Config > sp_std:: ops:: DerefMut for ExtraMutator < T > {
52
- fn deref_mut ( & mut self ) -> & mut T :: Extra {
53
- if self . pending . is_none ( ) {
54
- self . pending = Some ( self . original . clone ( ) ) ;
55
- }
56
- self . pending . as_mut ( ) . unwrap ( )
57
- }
54
+ impl < T : Config < I > , I : ' static > sp_std:: ops:: DerefMut for ExtraMutator < T , I > {
55
+ fn deref_mut ( & mut self ) -> & mut T :: Extra {
56
+ if self . pending . is_none ( ) {
57
+ self . pending = Some ( self . original . clone ( ) ) ;
58
+ }
59
+ self . pending . as_mut ( ) . unwrap ( )
60
+ }
58
61
}
59
62
60
- impl < T : Config > ExtraMutator < T > {
61
- pub ( super ) fn maybe_new ( id : T :: AssetId , who : impl sp_std:: borrow:: Borrow < T :: AccountId > )
62
- -> Option < ExtraMutator < T > >
63
- {
64
- if Account :: < T > :: contains_key ( id, who. borrow ( ) ) {
65
- Some ( ExtraMutator :: < T > {
66
- id,
67
- who : who. borrow ( ) . clone ( ) ,
68
- original : Account :: < T > :: get ( id, who. borrow ( ) ) . extra ,
69
- pending : None ,
70
- } )
71
- } else {
72
- None
73
- }
74
- }
63
+ impl < T : Config < I > , I : ' static > ExtraMutator < T , I > {
64
+ pub ( super ) fn maybe_new (
65
+ id : T :: AssetId ,
66
+ who : impl sp_std:: borrow:: Borrow < T :: AccountId > ,
67
+ ) -> Option < ExtraMutator < T , I > > {
68
+ if Account :: < T , I > :: contains_key ( id, who. borrow ( ) ) {
69
+ Some ( ExtraMutator :: < T , I > {
70
+ id,
71
+ who : who. borrow ( ) . clone ( ) ,
72
+ original : Account :: < T , I > :: get ( id, who. borrow ( ) ) . extra ,
73
+ pending : None ,
74
+ } )
75
+ } else {
76
+ None
77
+ }
78
+ }
75
79
80
+ /// Commit any changes to storage.
81
+ pub fn commit ( & mut self ) -> Result < ( ) , ( ) > {
82
+ if let Some ( extra) = self . pending . take ( ) {
83
+ Account :: < T , I > :: try_mutate_exists ( self . id , self . who . borrow ( ) , |maybe_account| {
84
+ if let Some ( ref mut account) = maybe_account {
85
+ account. extra = extra;
86
+ Ok ( ( ) )
87
+ } else {
88
+ Err ( ( ) )
89
+ }
90
+ } )
91
+ } else {
92
+ Ok ( ( ) )
93
+ }
94
+ }
76
95
77
- /// Commit any changes to storage.
78
- pub fn commit ( & mut self ) -> Result < ( ) , ( ) > {
79
- if let Some ( extra) = self . pending . take ( ) {
80
- Account :: < T > :: try_mutate_exists ( self . id , self . who . borrow ( ) , |maybe_account|
81
- if let Some ( ref mut account) = maybe_account {
82
- account. extra = extra;
83
- Ok ( ( ) )
84
- } else {
85
- Err ( ( ) )
86
- }
87
- )
88
- } else {
89
- Ok ( ( ) )
90
- }
91
- }
92
-
93
- /// Revert any changes, even those already committed by `self` and drop self.
94
- pub fn revert ( mut self ) -> Result < ( ) , ( ) > {
95
- self . pending = None ;
96
- Account :: < T > :: try_mutate_exists ( self . id , self . who . borrow ( ) , |maybe_account|
97
- if let Some ( ref mut account) = maybe_account {
98
- account. extra = self . original . clone ( ) ;
99
- Ok ( ( ) )
100
- } else {
101
- Err ( ( ) )
102
- }
103
- )
104
- }
96
+ /// Revert any changes, even those already committed by `self` and drop self.
97
+ pub fn revert ( mut self ) -> Result < ( ) , ( ) > {
98
+ self . pending = None ;
99
+ Account :: < T , I > :: try_mutate_exists ( self . id , self . who . borrow ( ) , |maybe_account| {
100
+ if let Some ( ref mut account) = maybe_account {
101
+ account. extra = self . original . clone ( ) ;
102
+ Ok ( ( ) )
103
+ } else {
104
+ Err ( ( ) )
105
+ }
106
+ } )
107
+ }
105
108
}
0 commit comments