Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update index in Index::open #545

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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