@@ -26,68 +26,73 @@ use super::*;
2626/// dropped. Changes, even after committed, may be reverted to their original values with the
2727/// `revert` function.
2828pub struct ExtraMutator < T : Config < I > , I : ' static = ( ) > {
29- id : T :: AssetId ,
30- who : T :: AccountId ,
31- original : T :: Extra ,
32- pending : Option < T :: Extra > ,
29+ id : T :: AssetId ,
30+ who : T :: AccountId ,
31+ original : T :: Extra ,
32+ pending : Option < T :: Extra > ,
3333}
3434
3535impl < T : Config < I > , I : ' static > Drop for ExtraMutator < T , I > {
36- fn drop ( & mut self ) {
37- debug_assert ! ( self . commit( ) . is_ok( ) , "attempt to write to non-existent asset account" ) ;
38- }
36+ fn drop ( & mut self ) {
37+ debug_assert ! ( self . commit( ) . is_ok( ) , "attempt to write to non-existent asset account" ) ;
38+ }
3939}
4040
4141impl < T : Config < I > , I : ' static > sp_std:: ops:: Deref for ExtraMutator < T , I > {
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- }
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+ }
4949}
5050
5151impl < T : Config < I > , I : ' static > sp_std:: ops:: DerefMut for ExtraMutator < T , I > {
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- }
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+ }
5858}
5959
6060impl < T : Config < I > , I : ' static > ExtraMutator < T , I > {
61- pub ( super ) fn maybe_new (
62- id : T :: AssetId ,
63- who : impl sp_std:: borrow:: Borrow < T :: AccountId > ,
64- ) -> Option < ExtraMutator < T , I > > {
65- if let Some ( a) = Account :: < T , I > :: get ( id, who. borrow ( ) ) {
66- Some ( ExtraMutator :: < T , I > { id, who : who. borrow ( ) . clone ( ) , original : a. extra , pending : None } )
67- } else {
68- None
69- }
70- }
61+ pub ( super ) fn maybe_new (
62+ id : T :: AssetId ,
63+ who : impl sp_std:: borrow:: Borrow < T :: AccountId > ,
64+ ) -> Option < ExtraMutator < T , I > > {
65+ if let Some ( a) = Account :: < T , I > :: get ( id, who. borrow ( ) ) {
66+ Some ( ExtraMutator :: < T , I > {
67+ id,
68+ who : who. borrow ( ) . clone ( ) ,
69+ original : a. extra ,
70+ pending : None ,
71+ } )
72+ } else {
73+ None
74+ }
75+ }
7176
72- /// Commit any changes to storage.
73- pub fn commit ( & mut self ) -> Result < ( ) , ( ) > {
74- if let Some ( extra) = self . pending . take ( ) {
75- Account :: < T , I > :: try_mutate ( self . id , self . who . borrow ( ) , |maybe_account| {
76- maybe_account. as_mut ( ) . ok_or ( ( ) ) . map ( |account| account. extra = extra)
77- } )
78- } else {
79- Ok ( ( ) )
80- }
81- }
77+ /// Commit any changes to storage.
78+ pub fn commit ( & mut self ) -> Result < ( ) , ( ) > {
79+ if let Some ( extra) = self . pending . take ( ) {
80+ Account :: < T , I > :: try_mutate ( self . id , self . who . borrow ( ) , |maybe_account| {
81+ maybe_account. as_mut ( ) . ok_or ( ( ) ) . map ( |account| account. extra = extra)
82+ } )
83+ } else {
84+ Ok ( ( ) )
85+ }
86+ }
8287
83- /// Revert any changes, even those already committed by `self` and drop self.
84- pub fn revert ( mut self ) -> Result < ( ) , ( ) > {
85- self . pending = None ;
86- Account :: < T , I > :: try_mutate ( self . id , self . who . borrow ( ) , |maybe_account| {
87- maybe_account
88- . as_mut ( )
89- . ok_or ( ( ) )
90- . map ( |account| account. extra = self . original . clone ( ) )
91- } )
92- }
88+ /// Revert any changes, even those already committed by `self` and drop self.
89+ pub fn revert ( mut self ) -> Result < ( ) , ( ) > {
90+ self . pending = None ;
91+ Account :: < T , I > :: try_mutate ( self . id , self . who . borrow ( ) , |maybe_account| {
92+ maybe_account
93+ . as_mut ( )
94+ . ok_or ( ( ) )
95+ . map ( |account| account. extra = self . original . clone ( ) )
96+ } )
97+ }
9398}
0 commit comments