From 39d50507089060ec729efabf11fc8a8765dec2bc Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Mon, 27 Feb 2023 21:05:49 -0300 Subject: [PATCH 01/11] add `/inscription_by_number/` endpoint --- src/subcommand/server.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 09abccee39..f7dcafab0e 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -156,6 +156,7 @@ impl Server { .route("/feed.xml", get(Self::feed)) .route("/input/:block/:transaction/:input", get(Self::input)) .route("/inscription/:inscription_id", get(Self::inscription)) + .route("/inscription_by_number/:inscription_number", get(Self::inscription_by_number)) .route("/inscriptions", get(Self::inscriptions)) .route("/inscriptions/:from", get(Self::inscriptions_from)) .route("/install.sh", get(Self::install_script)) @@ -943,6 +944,19 @@ impl Server { ) } + async fn inscription_by_number( + Extension(page_config): Extension>, + Extension(index): Extension>, + Path(inscription_number): Path, + ) -> ServerResult>{ + + let inscription_id = index + .get_inscription_id_by_inscription_number(inscription_number)? + .ok_or_not_found(|| format!("inscription number {inscription_number}"))?; + + Self::inscription(Extension(page_config), Extension(index), Path(inscription_id)).await + } + async fn inscriptions( Extension(page_config): Extension>, Extension(index): Extension>, From 801ca90d5dfd84cb9c5996243ba68efb416748d8 Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Mon, 27 Feb 2023 22:18:56 -0300 Subject: [PATCH 02/11] update readme --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 03d6cb6b8c..57b79b46fc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,14 @@ -`ord` +`ord-ocm` ===== +* Added the endpoint `/inscription_by_number/:number`. + To use this endpoint, 1) install rust and build `ord` from source (see [building section](#building)) and then 2) start your `bitcoind` daemon and finally 3) start `ord` server + ``` + sudo ./target/release/ord --chain= --cookie-file=~/.bitcoin/ --rpc-url= server + ``` + for `signet`, the cookie file should be `~/.bitcoin/signet/.cookie`, for mainnet `~/.bitcoin/.cookie`. +`ord` +===== `ord` is an index, block explorer, and command-line wallet. It is experimental software with no warranty. See [LICENSE](LICENSE) for more details. From 2634d508272f0ab3c7ae175549302caa8991d80f Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Tue, 28 Feb 2023 22:32:30 -0300 Subject: [PATCH 03/11] add snapshot cli command --- README.md | 2 ++ src/index.rs | 31 +++++++++++++++++++++++++++++++ src/subcommand.rs | 6 +++++- src/subcommand/snapshot.rs | 22 ++++++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/subcommand/snapshot.rs diff --git a/README.md b/README.md index 57b79b46fc..3523ec079d 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ ``` for `signet`, the cookie file should be `~/.bitcoin/signet/.cookie`, for mainnet `~/.bitcoin/.cookie`. +* Added the cli command `ord snapshot`. + `ord` ===== `ord` is an index, block explorer, and command-line wallet. It is experimental diff --git a/src/index.rs b/src/index.rs index 45980383f3..77bbef2ce5 100644 --- a/src/index.rs +++ b/src/index.rs @@ -244,6 +244,37 @@ impl Index { }) } + pub(crate) fn get_inscription_number_and_ids( + &self, + ) -> Result> { + + Ok( + self + .database + .begin_read()? + .open_table(INSCRIPTION_NUMBER_TO_INSCRIPTION_ID)? + .range(0..)? + .map(|(n, id)| (n.value(), Entry::load(*id.value()))) + .collect(), + ) + } + + pub(crate) fn get_inscription_sats_and_ids( + &self, + ) -> Result> { + + Ok( + self + .database + .begin_read()? + .open_table(INSCRIPTION_ID_TO_SATPOINT)? + //.range::<&[u8;36],&[u8;44]>? + .range::<&[u8;36]>(&[0; 36]..)? + .map(|(id, satpoint)| (Entry::load(*satpoint.value()), Entry::load(*id.value()))) + .collect(), + ) + } + pub(crate) fn get_unspent_outputs(&self, _wallet: Wallet) -> Result> { let mut utxos = BTreeMap::new(); utxos.extend( diff --git a/src/subcommand.rs b/src/subcommand.rs index cc1848b252..5f4aea53e2 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -12,6 +12,7 @@ pub mod subsidy; pub mod supply; pub mod traits; pub mod wallet; +mod snapshot; fn print_json(output: impl Serialize) -> Result { serde_json::to_writer_pretty(io::stdout(), &output)?; @@ -45,6 +46,8 @@ pub(crate) enum Subcommand { Traits(traits::Traits), #[clap(subcommand, about = "Wallet commands")] Wallet(wallet::Wallet), + #[clap(about = "Take a snapshot of current indexed inscriptions")] + Snapshot, } impl Subcommand { @@ -67,6 +70,7 @@ impl Subcommand { Self::Supply => supply::run(), Self::Traits(traits) => traits.run(), Self::Wallet(wallet) => wallet.run(options), + Self::Snapshot => snapshot::run(options), } } -} +} \ No newline at end of file diff --git a/src/subcommand/snapshot.rs b/src/subcommand/snapshot.rs new file mode 100644 index 0000000000..b81193dde5 --- /dev/null +++ b/src/subcommand/snapshot.rs @@ -0,0 +1,22 @@ +use super::*; + +pub(crate) fn run(options: Options) -> Result { + println!("Updating ord index..."); + let index = Index::open(&options)?; + index.update()?; + + println!("Taking snapshot of database..."); + println!("number - id"); + let numbers_and_ids = index.get_inscription_number_and_ids()?; + for (number, id) in numbers_and_ids { + println!("{number} - {id}"); + } + + println!("satoshi - id"); + let sats_and_ids = index.get_inscription_sats_and_ids()?; + for (sat, id) in sats_and_ids { + println!("{sat} - {id}"); + } + + Ok(()) +} \ No newline at end of file From 09ebd2e9aebaa92f8719f56fe272913531b70697 Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Wed, 1 Mar 2023 01:13:27 -0300 Subject: [PATCH 04/11] docs --- .gitignore | 1 + README.md | 27 ++++++++++++++++++++++----- src/index.rs | 32 ++++++++------------------------ src/subcommand/snapshot.rs | 38 +++++++++++++++++++++++++++----------- 4 files changed, 58 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 26154489a5..81289eee8b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /target /test-times.txt /tmp +inscriptions_snapshot.csv \ No newline at end of file diff --git a/README.md b/README.md index 3523ec079d..abfbea1aef 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,30 @@ `ord-ocm` ===== -* Added the endpoint `/inscription_by_number/:number`. - To use this endpoint, 1) install rust and build `ord` from source (see [building section](#building)) and then 2) start your `bitcoind` daemon and finally 3) start `ord` server +First of all, install rust and build `ord` from source (see [building section](#building)) and then start your `bitcoind` daemon. +On the examples we are going to use the `signet` settings, starting by the `bitcoin.conf` file for the bitcoin node: +```bash +# ~/.bitcoin/bitcoin.conf +rpcallowip=127.0.0.1 +txindex=1 +chain=signet +server=1 + +[signet] +rpcport=38332 +``` + +**New features:** +* Added the endpoint `/inscription_by_number/:number` + To use this endpoint start the `ord` server ``` - sudo ./target/release/ord --chain= --cookie-file=~/.bitcoin/ --rpc-url= server + sudo ./target/release/ord -s --cookie-file ~/.bitcoin/signet/.cookie --rpc-url 127.0.0.1:38332 server ``` - for `signet`, the cookie file should be `~/.bitcoin/signet/.cookie`, for mainnet `~/.bitcoin/.cookie`. -* Added the cli command `ord snapshot`. +* Added the cli command `ord snapshot` + To use this cli run + ``` + sudo ./target/release/ord -s --cookie-file ~/.bitcoin/signet/.cookie --rpc-url 127.0.0.1:38332 snapshot > inscriptions_snapshot.csv + ``` `ord` ===== diff --git a/src/index.rs b/src/index.rs index 77bbef2ce5..787b83e0ab 100644 --- a/src/index.rs +++ b/src/index.rs @@ -208,8 +208,8 @@ impl Index { tx.open_table(INSCRIPTION_NUMBER_TO_INSCRIPTION_ID)?; tx.open_table(OUTPOINT_TO_VALUE)?; tx.open_table(SATPOINT_TO_INSCRIPTION_ID)?; - tx.open_table(SAT_TO_INSCRIPTION_ID)?; - tx.open_table(SAT_TO_SATPOINT)?; + tx.open_table(SAT_TO_INSCRIPTION_ID)?; // empty + tx.open_table(SAT_TO_SATPOINT)?; // empty tx.open_table(WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP)?; tx.open_table(STATISTIC_TO_COUNT)? @@ -244,35 +244,19 @@ impl Index { }) } - pub(crate) fn get_inscription_number_and_ids( + pub(crate) fn get_inscription_ids_by_number( &self, - ) -> Result> { - - Ok( + ) -> Result> { + let map: HashMap = HashMap::from_iter( self .database .begin_read()? .open_table(INSCRIPTION_NUMBER_TO_INSCRIPTION_ID)? .range(0..)? - .map(|(n, id)| (n.value(), Entry::load(*id.value()))) - .collect(), - ) - } - - pub(crate) fn get_inscription_sats_and_ids( - &self, - ) -> Result> { + .map(|(n, id)| (Entry::load(*id.value()), n.value())) + ); - Ok( - self - .database - .begin_read()? - .open_table(INSCRIPTION_ID_TO_SATPOINT)? - //.range::<&[u8;36],&[u8;44]>? - .range::<&[u8;36]>(&[0; 36]..)? - .map(|(id, satpoint)| (Entry::load(*satpoint.value()), Entry::load(*id.value()))) - .collect(), - ) + Ok(map) } pub(crate) fn get_unspent_outputs(&self, _wallet: Wallet) -> Result> { diff --git a/src/subcommand/snapshot.rs b/src/subcommand/snapshot.rs index b81193dde5..373902a01c 100644 --- a/src/subcommand/snapshot.rs +++ b/src/subcommand/snapshot.rs @@ -1,21 +1,37 @@ use super::*; +struct SnapshotData { + inscription_number: u64, + inscription_id: InscriptionId, + transaction_id: Txid, + satoshi_location: SatPoint, +} + pub(crate) fn run(options: Options) -> Result { - println!("Updating ord index..."); let index = Index::open(&options)?; index.update()?; - - println!("Taking snapshot of database..."); - println!("number - id"); - let numbers_and_ids = index.get_inscription_number_and_ids()?; - for (number, id) in numbers_and_ids { - println!("{number} - {id}"); + + let inscriptions = index.get_inscriptions(None)?; + let inscription_numbers = index.get_inscription_ids_by_number()?; + + let mut snapshot_rows: Vec = vec![]; + + for (satpoint, id) in inscriptions { + let row = SnapshotData { + inscription_number: inscription_numbers[&id], + inscription_id: id, + transaction_id: id.txid, + satoshi_location: satpoint, + }; + + snapshot_rows.push(row); } - println!("satoshi - id"); - let sats_and_ids = index.get_inscription_sats_and_ids()?; - for (sat, id) in sats_and_ids { - println!("{sat} - {id}"); + snapshot_rows.sort_by(|a, b| a.inscription_number.cmp(&b.inscription_number)); + + println!("inscription_number, inscription_id, transaction_id, satoshi_location"); + for row in snapshot_rows { + println!("{}, {}, {}, {}", row.inscription_number, row.inscription_id, row.transaction_id, row.satoshi_location); } Ok(()) From cf9e92351f69b2619ce20f0ac185fc4520e07add Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Wed, 1 Mar 2023 19:36:47 -0300 Subject: [PATCH 05/11] add outpoint fn --- src/index.rs | 12 ++++++++++++ src/subcommand/snapshot.rs | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/index.rs b/src/index.rs index 787b83e0ab..81b72095d7 100644 --- a/src/index.rs +++ b/src/index.rs @@ -244,6 +244,18 @@ impl Index { }) } + pub(crate) fn get_outpoints(&self) -> Result>{ + let db = self.database.begin_read()?; + let table = db.open_table(OUTPOINT_TO_SAT_RANGES)?; + let data = table.iter()?.map(|(outp, satp)| { + let first_sat_chunk = satp.value().chunks_exact(11).nth(0).unwrap(); + (Entry::load(*outp.value()), SatRange::load(first_sat_chunk.try_into().unwrap())) + }); + + Ok(HashMap::from_iter(data)) + } + + pub(crate) fn get_inscription_ids_by_number( &self, ) -> Result> { diff --git a/src/subcommand/snapshot.rs b/src/subcommand/snapshot.rs index 373902a01c..9db597c583 100644 --- a/src/subcommand/snapshot.rs +++ b/src/subcommand/snapshot.rs @@ -13,6 +13,7 @@ pub(crate) fn run(options: Options) -> Result { let inscriptions = index.get_inscriptions(None)?; let inscription_numbers = index.get_inscription_ids_by_number()?; + let outpoints = index.get_outpoints()?; let mut snapshot_rows: Vec = vec![]; @@ -29,10 +30,16 @@ pub(crate) fn run(options: Options) -> Result { snapshot_rows.sort_by(|a, b| a.inscription_number.cmp(&b.inscription_number)); + /* println!("inscription_number, inscription_id, transaction_id, satoshi_location"); for row in snapshot_rows { println!("{}, {}, {}, {}", row.inscription_number, row.inscription_id, row.transaction_id, row.satoshi_location); } + */ + + for (outp, (satp_start, satp_end)) in outpoints { + println!("{}, {}, {}", outp, satp_start, satp_end); + } Ok(()) } \ No newline at end of file From 5c0c73f15f8576a5cef93540283e5b040e8b9cc6 Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Wed, 15 Mar 2023 15:10:31 -0300 Subject: [PATCH 06/11] refactor csv structure --- src/subcommand/snapshot.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/subcommand/snapshot.rs b/src/subcommand/snapshot.rs index 9db597c583..d9117340d3 100644 --- a/src/subcommand/snapshot.rs +++ b/src/subcommand/snapshot.rs @@ -13,7 +13,6 @@ pub(crate) fn run(options: Options) -> Result { let inscriptions = index.get_inscriptions(None)?; let inscription_numbers = index.get_inscription_ids_by_number()?; - let outpoints = index.get_outpoints()?; let mut snapshot_rows: Vec = vec![]; @@ -30,16 +29,11 @@ pub(crate) fn run(options: Options) -> Result { snapshot_rows.sort_by(|a, b| a.inscription_number.cmp(&b.inscription_number)); - /* + println!("inscription_number, inscription_id, transaction_id, satoshi_location"); for row in snapshot_rows { println!("{}, {}, {}, {}", row.inscription_number, row.inscription_id, row.transaction_id, row.satoshi_location); } - */ - - for (outp, (satp_start, satp_end)) in outpoints { - println!("{}, {}, {}", outp, satp_start, satp_end); - } Ok(()) } \ No newline at end of file From ed62e3f8b1c784f8cf500ffe4d638444ee7c1090 Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Wed, 15 Mar 2023 15:19:27 -0300 Subject: [PATCH 07/11] update title --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index abfbea1aef..6f70c82139 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -`ord-ocm` +`ord` ===== First of all, install rust and build `ord` from source (see [building section](#building)) and then start your `bitcoind` daemon. On the examples we are going to use the `signet` settings, starting by the `bitcoin.conf` file for the bitcoin node: From 2e8acb40cbb22ed802838920c0be8f8197e6f8b7 Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Wed, 15 Mar 2023 21:22:50 -0300 Subject: [PATCH 08/11] add subcommand query --- src/subcommand.rs | 6 +++++- src/subcommand/query.rs | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/subcommand/query.rs diff --git a/src/subcommand.rs b/src/subcommand.rs index 5f4aea53e2..81eac02758 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -12,7 +12,8 @@ pub mod subsidy; pub mod supply; pub mod traits; pub mod wallet; -mod snapshot; +pub mod snapshot; +pub mod query; fn print_json(output: impl Serialize) -> Result { serde_json::to_writer_pretty(io::stdout(), &output)?; @@ -48,6 +49,8 @@ pub(crate) enum Subcommand { Wallet(wallet::Wallet), #[clap(about = "Take a snapshot of current indexed inscriptions")] Snapshot, + #[clap(subcommand, about = "Database query commands")] + Query(query::Query), } impl Subcommand { @@ -71,6 +74,7 @@ impl Subcommand { Self::Traits(traits) => traits.run(), Self::Wallet(wallet) => wallet.run(options), Self::Snapshot => snapshot::run(options), + Self::Query(query) => query.run(options), } } } \ No newline at end of file diff --git a/src/subcommand/query.rs b/src/subcommand/query.rs new file mode 100644 index 0000000000..2426f14bbd --- /dev/null +++ b/src/subcommand/query.rs @@ -0,0 +1,22 @@ +use super::*; + +#[derive(Debug, Parser)] +pub(crate) enum Query { + InscriptionId, + InscriptionNumber, + Sat, + Block, +} + +impl Query { + pub(crate) fn run(self, options: Options) -> Result { + match self { + Self::InscriptionId => println!("Query by inscription id"), + Self::InscriptionNumber => println!("Query by inscription number"), + Self::Sat => println!("Query by sat number"), + Self::Block => println!("Query by block number"), + } + + Ok(()) + } +} \ No newline at end of file From 16b2b195b1db75b4d19784b4d1a01417f8d4fe6a Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Thu, 16 Mar 2023 14:17:35 -0300 Subject: [PATCH 09/11] implement block cli --- src/subcommand/query.rs | 21 ++++++++------- src/subcommand/query/block.rs | 24 +++++++++++++++++ src/subcommand/query/inscription.rs | 40 +++++++++++++++++++++++++++++ src/subcommand/query/sat.rs | 7 +++++ 4 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 src/subcommand/query/block.rs create mode 100644 src/subcommand/query/inscription.rs create mode 100644 src/subcommand/query/sat.rs diff --git a/src/subcommand/query.rs b/src/subcommand/query.rs index 2426f14bbd..1fe627042e 100644 --- a/src/subcommand/query.rs +++ b/src/subcommand/query.rs @@ -1,22 +1,25 @@ use super::*; +pub mod inscription; +pub mod sat; +pub(crate) mod block; + #[derive(Debug, Parser)] pub(crate) enum Query { - InscriptionId, - InscriptionNumber, + #[clap(about = "Display information about an inscription")] + Inscription, + #[clap(about = "Display information about a satoshi")] Sat, - Block, + #[clap(about = "Display information about a block")] + Block(block::Block), } impl Query { pub(crate) fn run(self, options: Options) -> Result { match self { - Self::InscriptionId => println!("Query by inscription id"), - Self::InscriptionNumber => println!("Query by inscription number"), - Self::Sat => println!("Query by sat number"), - Self::Block => println!("Query by block number"), + Self::Inscription => inscription::run(options), + Self::Sat => sat::run(options), + Self::Block(block) => block.run(options), } - - Ok(()) } } \ No newline at end of file diff --git a/src/subcommand/query/block.rs b/src/subcommand/query/block.rs new file mode 100644 index 0000000000..a17927f432 --- /dev/null +++ b/src/subcommand/query/block.rs @@ -0,0 +1,24 @@ +use std::ptr::null; + +use super::*; + +#[derive(Debug, Parser)] +pub(crate) struct Block { + #[clap(help = "Block number")] + pub(crate) height: u64, +} + +impl Block { + pub(crate) fn run(self, options: Options) -> Result { + let index = Index::open(&options)?; + index.update()?; + + if let Some(block) = index.get_block_by_height(self.height)?{ + print_json(block)?; + } else { + print_json({})?; + } + + Ok(()) + } +} \ No newline at end of file diff --git a/src/subcommand/query/inscription.rs b/src/subcommand/query/inscription.rs new file mode 100644 index 0000000000..07a330d802 --- /dev/null +++ b/src/subcommand/query/inscription.rs @@ -0,0 +1,40 @@ +use super::*; + +pub(crate) fn run(options: Options) -> Result { + println!("[subcommand::query::inscription]: Not implemented yet."); + /* + let index = Index::open(&options)?; + index.update()?; + + + let inscription_id = index.get_inscription_id_by_inscription_number(666)?.unwrap(); + let entry = index.get_inscription_entry(inscription_id)?.unwrap(); + let inscription = index.get_inscription_by_id(inscription_id)?.unwrap(); + let satpoint = index.get_inscription_satpoint_by_id(inscription_id)?.unwrap(); + + let output = index + .get_transaction(satpoint.outpoint.txid)?.unwrap() + .output + .into_iter() + .nth(satpoint.outpoint.vout.try_into().unwrap()).unwrap(); + + let previous = if let Some(previous) = entry.number.checked_sub(1) { + Some( + index + .get_inscription_id_by_inscription_number(previous)?.unwrap() + ) + } else { + None + }; + + let next = index.get_inscription_id_by_inscription_number(entry.number + 1)?.unwrap(); + + print_json(inscription_id); + print_json(satpoint); + print_json(output); + print_json(previous); + print_json(next); + */ + + Ok(()) +} \ No newline at end of file diff --git a/src/subcommand/query/sat.rs b/src/subcommand/query/sat.rs new file mode 100644 index 0000000000..2f5f8ca6dd --- /dev/null +++ b/src/subcommand/query/sat.rs @@ -0,0 +1,7 @@ +use super::*; + +pub(crate) fn run(options: Options) -> Result { + println!("[subcommand::query::sat]: Not implemented yet."); + + Ok(()) +} \ No newline at end of file From 94b0f017754a9819d2f62d565785c285f5b4581b Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Thu, 16 Mar 2023 15:40:40 -0300 Subject: [PATCH 10/11] add block_json endpoint --- src/index.rs | 12 ------------ src/subcommand/query/block.rs | 6 ++---- src/subcommand/query/inscription.rs | 2 +- src/subcommand/query/sat.rs | 2 +- src/subcommand/server.rs | 14 +++++++++++++- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/index.rs b/src/index.rs index 81b72095d7..787b83e0ab 100644 --- a/src/index.rs +++ b/src/index.rs @@ -244,18 +244,6 @@ impl Index { }) } - pub(crate) fn get_outpoints(&self) -> Result>{ - let db = self.database.begin_read()?; - let table = db.open_table(OUTPOINT_TO_SAT_RANGES)?; - let data = table.iter()?.map(|(outp, satp)| { - let first_sat_chunk = satp.value().chunks_exact(11).nth(0).unwrap(); - (Entry::load(*outp.value()), SatRange::load(first_sat_chunk.try_into().unwrap())) - }); - - Ok(HashMap::from_iter(data)) - } - - pub(crate) fn get_inscription_ids_by_number( &self, ) -> Result> { diff --git a/src/subcommand/query/block.rs b/src/subcommand/query/block.rs index a17927f432..65d5c3488c 100644 --- a/src/subcommand/query/block.rs +++ b/src/subcommand/query/block.rs @@ -1,5 +1,3 @@ -use std::ptr::null; - use super::*; #[derive(Debug, Parser)] @@ -14,9 +12,9 @@ impl Block { index.update()?; if let Some(block) = index.get_block_by_height(self.height)?{ - print_json(block)?; + print_json(block)?; } else { - print_json({})?; + print_json({})?; } Ok(()) diff --git a/src/subcommand/query/inscription.rs b/src/subcommand/query/inscription.rs index 07a330d802..e1e30c86d2 100644 --- a/src/subcommand/query/inscription.rs +++ b/src/subcommand/query/inscription.rs @@ -1,6 +1,6 @@ use super::*; -pub(crate) fn run(options: Options) -> Result { +pub(crate) fn run(_options: Options) -> Result { println!("[subcommand::query::inscription]: Not implemented yet."); /* let index = Index::open(&options)?; diff --git a/src/subcommand/query/sat.rs b/src/subcommand/query/sat.rs index 2f5f8ca6dd..c432f6af3c 100644 --- a/src/subcommand/query/sat.rs +++ b/src/subcommand/query/sat.rs @@ -1,6 +1,6 @@ use super::*; -pub(crate) fn run(options: Options) -> Result { +pub(crate) fn run(_options: Options) -> Result { println!("[subcommand::query::sat]: Not implemented yet."); Ok(()) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index f7dcafab0e..7197e16220 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -19,7 +19,7 @@ use { http::{header, HeaderMap, HeaderValue, StatusCode, Uri}, response::{IntoResponse, Redirect, Response}, routing::get, - Router, TypedHeader, + Router, TypedHeader,Json }, axum_server::Handle, rust_embed::RustEmbed, @@ -148,6 +148,7 @@ impl Server { .route("/", get(Self::home)) .route("/block-count", get(Self::block_count)) .route("/block/:query", get(Self::block)) + .route("/block_json/:query", get(Self::block_json)) .route("/bounties", get(Self::bounties)) .route("/clock", get(Self::clock)) .route("/content/:inscription_id", get(Self::content)) @@ -480,6 +481,17 @@ impl Server { Redirect::to("https://raw.githubusercontent.com/casey/ord/master/install.sh") } + async fn block_json( + Extension(index): Extension>, + Path(DeserializeFromStr(height)): Path> + ) -> ServerResult> { + let block = index + .get_block_by_height(height)? + .ok_or_not_found(|| format!("block {height}"))?; + + Ok(Json(block)) + } + async fn block( Extension(page_config): Extension>, Extension(index): Extension>, From 1de55d32f34cb599dfbb9666d6a95a520eb516fe Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Thu, 16 Mar 2023 15:48:49 -0300 Subject: [PATCH 11/11] update documentation --- README.md | 6 +++++- src/index.rs | 4 ++-- src/subcommand.rs | 2 +- src/subcommand/query.rs | 4 ++-- src/subcommand/query/block.rs | 2 +- src/subcommand/query/inscription.rs | 2 +- src/subcommand/query/sat.rs | 2 +- src/subcommand/server.rs | 2 +- src/subcommand/snapshot.rs | 2 +- 9 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6f70c82139..f0d62d8c81 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,16 @@ rpcport=38332 sudo ./target/release/ord -s --cookie-file ~/.bitcoin/signet/.cookie --rpc-url 127.0.0.1:38332 server ``` -* Added the cli command `ord snapshot` +* Added the endpoint `/block_json/:height` + +* Added the snapshot cli command `ord snapshot` To use this cli run ``` sudo ./target/release/ord -s --cookie-file ~/.bitcoin/signet/.cookie --rpc-url 127.0.0.1:38332 snapshot > inscriptions_snapshot.csv ``` +* Added a set of queries cli commands `ord query ` + `ord` ===== `ord` is an index, block explorer, and command-line wallet. It is experimental diff --git a/src/index.rs b/src/index.rs index 787b83e0ab..af650c2b74 100644 --- a/src/index.rs +++ b/src/index.rs @@ -208,8 +208,8 @@ impl Index { tx.open_table(INSCRIPTION_NUMBER_TO_INSCRIPTION_ID)?; tx.open_table(OUTPOINT_TO_VALUE)?; tx.open_table(SATPOINT_TO_INSCRIPTION_ID)?; - tx.open_table(SAT_TO_INSCRIPTION_ID)?; // empty - tx.open_table(SAT_TO_SATPOINT)?; // empty + tx.open_table(SAT_TO_INSCRIPTION_ID)?; + tx.open_table(SAT_TO_SATPOINT)?; tx.open_table(WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP)?; tx.open_table(STATISTIC_TO_COUNT)? diff --git a/src/subcommand.rs b/src/subcommand.rs index 81eac02758..a6b4de1ad8 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -77,4 +77,4 @@ impl Subcommand { Self::Query(query) => query.run(options), } } -} \ No newline at end of file +} diff --git a/src/subcommand/query.rs b/src/subcommand/query.rs index 1fe627042e..afe76a5580 100644 --- a/src/subcommand/query.rs +++ b/src/subcommand/query.rs @@ -1,7 +1,7 @@ use super::*; -pub mod inscription; -pub mod sat; +pub(crate) mod inscription; +pub(crate) mod sat; pub(crate) mod block; #[derive(Debug, Parser)] diff --git a/src/subcommand/query/block.rs b/src/subcommand/query/block.rs index 65d5c3488c..1883d7fb79 100644 --- a/src/subcommand/query/block.rs +++ b/src/subcommand/query/block.rs @@ -19,4 +19,4 @@ impl Block { Ok(()) } -} \ No newline at end of file +} diff --git a/src/subcommand/query/inscription.rs b/src/subcommand/query/inscription.rs index e1e30c86d2..92610433ce 100644 --- a/src/subcommand/query/inscription.rs +++ b/src/subcommand/query/inscription.rs @@ -37,4 +37,4 @@ pub(crate) fn run(_options: Options) -> Result { */ Ok(()) -} \ No newline at end of file +} diff --git a/src/subcommand/query/sat.rs b/src/subcommand/query/sat.rs index c432f6af3c..6cafd89275 100644 --- a/src/subcommand/query/sat.rs +++ b/src/subcommand/query/sat.rs @@ -4,4 +4,4 @@ pub(crate) fn run(_options: Options) -> Result { println!("[subcommand::query::sat]: Not implemented yet."); Ok(()) -} \ No newline at end of file +} diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 7197e16220..bbf44ce415 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -19,7 +19,7 @@ use { http::{header, HeaderMap, HeaderValue, StatusCode, Uri}, response::{IntoResponse, Redirect, Response}, routing::get, - Router, TypedHeader,Json + Router, TypedHeader, Json }, axum_server::Handle, rust_embed::RustEmbed, diff --git a/src/subcommand/snapshot.rs b/src/subcommand/snapshot.rs index d9117340d3..217baa7358 100644 --- a/src/subcommand/snapshot.rs +++ b/src/subcommand/snapshot.rs @@ -36,4 +36,4 @@ pub(crate) fn run(options: Options) -> Result { } Ok(()) -} \ No newline at end of file +}