@@ -16,6 +16,7 @@ use rustreexo::accumulator::node_hash::BitcoinNodeHash;
1616use serde:: { Deserialize , Serialize } ;
1717use sneed:: {
1818 db:: error:: Error as DbError , DatabaseUnique , Env , EnvError , RwTxnError ,
19+ UnitKey ,
1920} ;
2021use tokio_stream:: { wrappers:: WatchStream , StreamMap } ;
2122
@@ -29,7 +30,7 @@ pub use crate::{
2930use crate :: {
3031 types:: {
3132 hash, Accumulator , AmountOverflowError , AmountUnderflowError ,
32- PointedOutput , UtreexoError ,
33+ PointedOutput , UtreexoError , Version , VERSION ,
3334 } ,
3435 util:: Watchable ,
3536} ;
@@ -100,10 +101,11 @@ pub struct Wallet {
100101 DatabaseUnique < SerdeBincode < [ u8 ; 4 ] > , SerdeBincode < Address > > ,
101102 utxos : DatabaseUnique < SerdeBincode < OutPoint > , SerdeBincode < Output > > ,
102103 stxos : DatabaseUnique < SerdeBincode < OutPoint > , SerdeBincode < SpentOutput > > ,
104+ _version : DatabaseUnique < UnitKey , SerdeBincode < Version > > ,
103105}
104106
105107impl Wallet {
106- pub const NUM_DBS : u32 = 5 ;
108+ pub const NUM_DBS : u32 = 6 ;
107109
108110 pub fn new ( path : & Path ) -> Result < Self , Error > {
109111 std:: fs:: create_dir_all ( path) ?;
@@ -128,6 +130,17 @@ impl Wallet {
128130 . map_err ( EnvError :: from) ?;
129131 let stxos = DatabaseUnique :: create ( & env, & mut rwtxn, "stxos" )
130132 . map_err ( EnvError :: from) ?;
133+ let version = DatabaseUnique :: create ( & env, & mut rwtxn, "version" )
134+ . map_err ( EnvError :: from) ?;
135+ if version
136+ . try_get ( & rwtxn, & ( ) )
137+ . map_err ( DbError :: from) ?
138+ . is_none ( )
139+ {
140+ version
141+ . put ( & mut rwtxn, & ( ) , & * VERSION )
142+ . map_err ( DbError :: from) ?;
143+ }
131144 rwtxn. commit ( ) . map_err ( RwTxnError :: from) ?;
132145 Ok ( Self {
133146 env,
@@ -136,6 +149,7 @@ impl Wallet {
136149 index_to_address,
137150 utxos,
138151 stxos,
152+ _version : version,
139153 } )
140154 }
141155
@@ -518,6 +532,7 @@ impl Watchable<()> for Wallet {
518532 index_to_address,
519533 utxos,
520534 stxos,
535+ _version : _,
521536 } = self ;
522537 let watchables = [
523538 seed. watch ( ) . clone ( ) ,
0 commit comments