Skip to content

Commit

Permalink
Sync index on Index::open (ordinals#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Sep 21, 2022
1 parent af12866 commit a74475a
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 19 deletions.
17 changes: 4 additions & 13 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,14 @@ impl Index {

tx.commit()?;

Ok(Self {
let index = Self {
client,
database,
database_path,
height_limit: options.height_limit,
})
}

#[allow(clippy::self_named_constructors)]
pub(crate) fn index(options: &Options) -> Result<Self> {
let index = Self::open(options)?;
};

index.index_ranges()?;
index.index()?;

Ok(index)
}
Expand Down Expand Up @@ -148,7 +143,7 @@ impl Index {
(base, base + delta)
}

pub(crate) fn index_ranges(&self) -> Result {
pub(crate) fn index(&self) -> Result {
let mut wtx = self.database.begin_write()?;

let height = wtx
Expand Down Expand Up @@ -572,8 +567,6 @@ mod tests {

let index = Index::open(&options).unwrap();

index.index_ranges().unwrap();

assert_eq!(index.height().unwrap(), 0);
}

Expand All @@ -598,8 +591,6 @@ mod tests {

let index = Index::open(&options).unwrap();

index.index_ranges().unwrap();

assert_eq!(index.height().unwrap(), 1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) struct Find {

impl Find {
pub(crate) fn run(self, options: Options) -> Result<()> {
let index = Index::index(&options)?;
let index = Index::open(&options)?;

match index.find(self.ordinal)? {
Some(satpoint) => {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/index.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

pub(crate) fn run(options: Options) -> Result<()> {
Index::index(&options)?;
Index::open(&options)?;
Ok(())
}
2 changes: 1 addition & 1 deletion src/subcommand/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) struct List {

impl List {
pub(crate) fn run(self, options: Options) -> Result<()> {
let index = Index::index(&options)?;
let index = Index::open(&options)?;

match index.list(self.outpoint)? {
Some(crate::index::List::Unspent(ranges)) => {
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Server {

let clone = index.clone();
thread::spawn(move || loop {
if let Err(error) = clone.index_ranges() {
if let Err(error) = clone.index() {
log::error!("{error}");
}
thread::sleep(Duration::from_millis(100));
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::*;
pub(crate) fn run(options: Options) -> Result {
let purse = Purse::load(&options)?;

let index = Index::index(&options)?;
let index = Index::open(&options)?;

let mut ordinals = purse
.wallet
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/wallet/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl Send {
pub(crate) fn run(self, options: Options) -> Result {
let purse = Purse::load(&options)?;

let index = Index::index(&options)?;
let index = Index::open(&options)?;

let utxo = purse.find(&index, self.ordinal)?;

Expand Down

0 comments on commit a74475a

Please sign in to comment.