@@ -6,22 +6,22 @@ pub use item::SnapshotItem;
66pub use map:: SnapshotMap ;
77
88use crate :: de:: KeyDeserialize ;
9- use crate :: { Bound , Map , Prefixer , PrimaryKey , U64Key } ;
9+ use crate :: { Bound , Map , Prefixer , PrimaryKey } ;
1010use cosmwasm_std:: { Order , StdError , StdResult , Storage } ;
1111use serde:: de:: DeserializeOwned ;
1212use serde:: { Deserialize , Serialize } ;
1313
1414/// Structure holding a map of checkpoints composited from
15- /// height (as U64Key ) and counter of how many times it has
15+ /// height (as u64 ) and counter of how many times it has
1616/// been checkpointed (as u32).
1717/// Stores all changes in changelog.
1818#[ derive( Debug , Clone ) ]
1919pub ( crate ) struct Snapshot < ' a , K , T > {
20- checkpoints : Map < ' a , U64Key , u32 > ,
20+ checkpoints : Map < ' a , u64 , u32 > ,
2121
2222 // this stores all changes (key, height). Must differentiate between no data written,
2323 // and explicit None (just inserted)
24- pub changelog : Map < ' a , ( K , U64Key ) , ChangeSet < T > > ,
24+ pub changelog : Map < ' a , ( K , u64 ) , ChangeSet < T > > ,
2525
2626 // How aggressive we are about checkpointing all data
2727 strategy : Strategy ,
@@ -42,22 +42,20 @@ impl<'a, K, T> Snapshot<'a, K, T> {
4242
4343 pub fn add_checkpoint ( & self , store : & mut dyn Storage , height : u64 ) -> StdResult < ( ) > {
4444 self . checkpoints
45- . update :: < _ , StdError > ( store, height. into ( ) , |count| {
46- Ok ( count. unwrap_or_default ( ) + 1 )
47- } ) ?;
45+ . update :: < _ , StdError > ( store, height, |count| Ok ( count. unwrap_or_default ( ) + 1 ) ) ?;
4846 Ok ( ( ) )
4947 }
5048
5149 pub fn remove_checkpoint ( & self , store : & mut dyn Storage , height : u64 ) -> StdResult < ( ) > {
5250 let count = self
5351 . checkpoints
54- . may_load ( store, height. into ( ) ) ?
52+ . may_load ( store, height) ?
5553 . unwrap_or_default ( ) ;
5654 if count <= 1 {
57- self . checkpoints . remove ( store, height. into ( ) ) ;
55+ self . checkpoints . remove ( store, height) ;
5856 Ok ( ( ) )
5957 } else {
60- self . checkpoints . save ( store, height. into ( ) , & ( count - 1 ) )
58+ self . checkpoints . save ( store, height, & ( count - 1 ) )
6159 }
6260 }
6361}
8684 . transpose ( ) ?;
8785 if let Some ( ( height, _) ) = checkpoint {
8886 // any changelog for the given key since then?
89- let start = Bound :: inclusive ( U64Key :: from ( height) ) ;
87+ let start = Bound :: inclusive ( height) ;
9088 let first = self
9189 . changelog
9290 . prefix ( k. clone ( ) )
@@ -107,7 +105,7 @@ where
107105 let has = match self . strategy {
108106 Strategy :: EveryBlock => true ,
109107 Strategy :: Never => false ,
110- Strategy :: Selected => self . checkpoints . may_load ( store, height. into ( ) ) ?. is_some ( ) ,
108+ Strategy :: Selected => self . checkpoints . may_load ( store, height) ?. is_some ( ) ,
111109 } ;
112110 match has {
113111 true => Ok ( ( ) ) ,
@@ -116,10 +114,7 @@ where
116114 }
117115
118116 pub fn has_changelog ( & self , store : & mut dyn Storage , key : K , height : u64 ) -> StdResult < bool > {
119- Ok ( self
120- . changelog
121- . may_load ( store, ( key, U64Key :: from ( height) ) ) ?
122- . is_some ( ) )
117+ Ok ( self . changelog . may_load ( store, ( key, height) ) ?. is_some ( ) )
123118 }
124119
125120 pub fn write_changelog (
@@ -130,7 +125,7 @@ where
130125 old : Option < T > ,
131126 ) -> StdResult < ( ) > {
132127 self . changelog
133- . save ( store, ( key, U64Key :: from ( height) ) , & ChangeSet { old } )
128+ . save ( store, ( key, height) , & ChangeSet { old } )
134129 }
135130
136131 // may_load_at_height reads historical data from given checkpoints.
@@ -148,7 +143,7 @@ where
148143
149144 // this will look for the first snapshot of height >= given height
150145 // If None, there is no snapshot since that time.
151- let start = Bound :: inclusive ( U64Key :: new ( height) ) ;
146+ let start = Bound :: inclusive ( height. to_be_bytes ( ) . to_vec ( ) ) ;
152147 let first = self
153148 . changelog
154149 . prefix ( key)
0 commit comments