From 9fbd54ffb2598e03c1abfa8379ab870346f7fa6e Mon Sep 17 00:00:00 2001 From: ericatallah Date: Sun, 4 Jun 2023 14:26:36 -0700 Subject: [PATCH 01/21] add inscription_satpoint logger --- src/index/updater/inscription_updater.rs | 67 ++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 45deef074c..4a117697ab 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -1,10 +1,13 @@ use {super::*, inscription::Curse}; +use serde_json::Value; #[derive(Debug, Clone)] pub(super) struct Flotsam { inscription_id: InscriptionId, offset: u64, origin: Origin, + // populated if new inscription, None if transfer of existing inscription + inscription_data: Option, } #[derive(Debug, Clone)] @@ -134,6 +137,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { offset, inscription_id, origin: Origin::Old { old_satpoint }, + inscription_data: None, }); inscribed_offsets @@ -252,6 +256,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { pointer: inscription.payload.pointer(), unbound, }, + inscription_data: Some(inscription.inscription), }); envelopes.next(); @@ -294,6 +299,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { pointer, unbound, }, + inscription_data, } = flotsam { Flotsam { @@ -306,6 +312,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { pointer, unbound, }, + inscription_data, } } else { flotsam @@ -518,6 +525,66 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { self.satpoint_to_id.insert(&satpoint, &inscription_id)?; self.id_to_satpoint.insert(&inscription_id, &satpoint)?; + let inscription_id = InscriptionId::load(inscription_id); + let satpoint = SatPoint::load(satpoint); + let inscription_entry = self.id_to_entry.get(&inscription_id.store())?.unwrap(); + let inscription_number = InscriptionEntry::load(inscription_entry.value()).number; + + if let Some(inscription) = flotsam.inscription_data { + let is_brc_20 = Self::is_brc_20(&self, &inscription); + let content_type = inscription.content_type().unwrap_or(""); + let content_len = inscription.body().map_or(0, |body| body.len()); + + log::info!( + target: "new_inscription_satpoint", + "{},{},{},{},{},{},{}", + self.height, + satpoint, + inscription_id, + inscription_number, + content_type, + content_len, + is_brc_20, + ); + } else { + log::info!( + target: "new_inscription_satpoint", + "{},{},{},{}", + self.height, + satpoint, + inscription_id, + inscription_number, + ); + } + Ok(()) } + + fn valid_json(data: Option<&[u8]>) -> bool { + match data { + Some(bytes) => serde_json::from_slice::(bytes).is_ok(), + None => false, + } + } + + fn is_brc_20(&self, inscription: &Inscription) -> bool { + let valid_json = Self::valid_json(inscription.body()); + if valid_json { + let json_result: Result = + serde_json::from_slice(&inscription.body().unwrap()); + let json: Value = json_result.unwrap(); + let empty_json = serde_json::Map::new(); + let json_obj = json.as_object().unwrap_or(&empty_json); + if json_obj.contains_key("p") { + let p = json_obj.get("p").unwrap(); + if p.is_string() { + let p_str = p.as_str().unwrap(); + if p_str.to_lowercase() == "brc-20" { + return true; + } + } + } + } + false + } } From 927ee7b621a38f672bf35242bf45b0fad54dd29d Mon Sep 17 00:00:00 2001 From: ericatallah Date: Sun, 4 Jun 2023 14:29:03 -0700 Subject: [PATCH 02/21] fix compile error --- src/index/updater/inscription_updater.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 4a117697ab..4131d70e67 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -256,7 +256,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { pointer: inscription.payload.pointer(), unbound, }, - inscription_data: Some(inscription.inscription), + inscription_data: Some(inscription.inscription.clone()), }); envelopes.next(); From 47534f2a98003ba2f7da4d88c6550027164a5fb1 Mon Sep 17 00:00:00 2001 From: ericatallah Date: Sun, 4 Jun 2023 15:00:10 -0700 Subject: [PATCH 03/21] add logfile to lib, log block data, fix csp --- src/index/updater.rs | 15 +++++++++++++-- src/index/updater/inscription_updater.rs | 11 +++++++++-- src/lib.rs | 19 ++++++++++++++++--- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/index/updater.rs b/src/index/updater.rs index 8a3c3550f0..e99cfb190b 100644 --- a/src/index/updater.rs +++ b/src/index/updater.rs @@ -94,10 +94,21 @@ impl<'index> Updater<'_> { &mut outpoint_sender, &mut value_receiver, &mut wtx, - block, + &block, &mut value_cache, )?; + if self.height.checked_sub(1).is_some() { + log::info!( + target: "new_inscription_satpoint", + "{{\"height\":{},\"block_hash\":\"{}\",\"prev_block_hash\":\"{}\",\"tx_count\":{}}}", + &self.height - 1, + &block.header.block_hash(), + &block.header.prev_blockhash, + &block.txdata.len(), + ); + } + if let Some(progress_bar) = &mut progress_bar { progress_bar.inc(1); @@ -316,7 +327,7 @@ impl<'index> Updater<'_> { outpoint_sender: &mut Sender, value_receiver: &mut Receiver, wtx: &mut WriteTransaction, - block: BlockData, + block: &BlockData, value_cache: &mut HashMap, ) -> Result<()> { Reorg::detect_reorg(&block, self.height, self.index)?; diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 4131d70e67..6ccfac8690 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -440,6 +440,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { new_satpoint: SatPoint, ) -> Result { let inscription_id = flotsam.inscription_id.store(); + let mut new_inscription_number: i64 = 0; let unbound = match flotsam.origin { Origin::Old { old_satpoint } => { self.satpoint_to_id.remove_all(&old_satpoint.store())?; @@ -527,8 +528,14 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { let inscription_id = InscriptionId::load(inscription_id); let satpoint = SatPoint::load(satpoint); - let inscription_entry = self.id_to_entry.get(&inscription_id.store())?.unwrap(); - let inscription_number = InscriptionEntry::load(inscription_entry.value()).number; + // let inscription_entry = self.id_to_entry.get(&inscription_id.store())?.unwrap(); + // let inscription_number = InscriptionEntry::load(inscription_entry.value()).number; + let inscription_number = if new_inscription_number != 0 { + new_inscription_number + } else { + let inscription_entry = self.id_to_entry.get(&inscription_id.store())?.unwrap(); + InscriptionEntry::load(inscription_entry.value()).number + }; if let Some(inscription) = flotsam.inscription_data { let is_brc_20 = Self::is_brc_20(&self, &inscription); diff --git a/src/lib.rs b/src/lib.rs index c1aca40a89..f6671fec46 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,8 +59,8 @@ use { env, ffi::OsString, fmt::{self, Display, Formatter}, - fs::{self, File}, - io::{self, Cursor}, + fs::{self, File, OpenOptions}, + io::{self, Cursor, Write}, net::{TcpListener, ToSocketAddrs}, ops::{Add, AddAssign, Sub}, path::{Path, PathBuf}, @@ -175,7 +175,20 @@ fn gracefully_shutdown_indexer() { } pub fn main() { - env_logger::init(); + let inscription_satpoint_logs_file = OpenOptions::new() + .write(true) + .append(true) + .create(true) + .open("inscription_satpoint.txt") + .unwrap(); + + env_logger::builder() + .filter(Some("new_inscription_satpoint"), log::LevelFilter::Info) + .target(env_logger::Target::Pipe(Box::new( + inscription_satpoint_logs_file, + ))) + .format(|buf, record| writeln!(buf, "{}", record.args())) + .init(); ctrlc::set_handler(move || { if SHUTTING_DOWN.fetch_or(true, atomic::Ordering::Relaxed) { From 6199d2c15633add4beebe57ddfac0f8bd95794e9 Mon Sep 17 00:00:00 2001 From: ericatallah Date: Sun, 4 Jun 2023 15:08:06 -0700 Subject: [PATCH 04/21] ignore logfile --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 26154489a5..b80534e689 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /target /test-times.txt /tmp +/inscription_satpoint.txt \ No newline at end of file From a02963829eb88baa0e2590f959e0b3ca88dd8866 Mon Sep 17 00:00:00 2001 From: ericatallah Date: Mon, 5 Jun 2023 11:56:06 -0700 Subject: [PATCH 05/21] add pub key and address to wallet create output --- src/subcommand/wallet/create.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/subcommand/wallet/create.rs b/src/subcommand/wallet/create.rs index 34cd762450..45b00406ba 100644 --- a/src/subcommand/wallet/create.rs +++ b/src/subcommand/wallet/create.rs @@ -1,8 +1,15 @@ +use bitcoin::{ + secp256k1::PublicKey, + util::bip32::{self, ExtendedPubKey}, +}; + use super::*; #[derive(Serialize, Deserialize)] pub struct Output { pub mnemonic: Mnemonic, + pub address: Address, + pub public_key: PublicKey, pub passphrase: Option, } @@ -22,11 +29,26 @@ impl Create { rand::thread_rng().fill_bytes(&mut entropy); let mnemonic = Mnemonic::from_entropy(&entropy)?; + let seed = mnemonic.to_seed(self.passphrase.clone()); + let secp = Secp256k1::new(); + let root = bip32::ExtendedPrivKey::new_master(options.chain().network(), &seed)?; + + let xprv = root.derive_priv(&secp, &DerivationPath::from_str("m/86'/1'/0'")?)?; + let xpub = ExtendedPubKey::from_priv(&secp, &xprv); + let public_key = xpub + .derive_pub(&secp, &DerivationPath::from_str("m/0/0")?)? + .public_key; initialize_wallet(&options, mnemonic.to_seed(self.passphrase.clone()))?; + let address = options + .bitcoin_rpc_client_for_wallet_command(false)? + .get_new_address(None, Some(bitcoincore_rpc::json::AddressType::Bech32m))?; + Ok(Box::new(Output { mnemonic, + address, + public_key, passphrase: Some(self.passphrase), })) } From 6029fc5bb1df66a2edbadc9542f2ff55be4ce258 Mon Sep 17 00:00:00 2001 From: ericatallah Date: Tue, 13 Jun 2023 12:17:40 -0700 Subject: [PATCH 06/21] put guardrail to ensure index is only updated from home dir --- src/index.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/index.rs b/src/index.rs index 9572560be1..7a190890f0 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1,3 +1,4 @@ +use dirs::home_dir; use { self::{ entry::{ @@ -448,6 +449,20 @@ impl Index { } pub(crate) fn update(&self) -> Result { + // verify cwd is ~ + if let Ok(current_dir) = env::current_dir() { + if let Some(home) = home_dir() { + if current_dir != home { + println!("Current working directory is not home ({:?}), cannot update the index!", home); + panic!("Current working directory must be the home directory") + } + } else { + panic!("Failed to get the home directory") + } + } else { + panic!("Failed to get the current working directory"); + } + let mut updater = Updater::new(self)?; loop { From 52bd369c98ba9e7d5eb7b7724e4de3fa6975ec07 Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Wed, 14 Jun 2023 03:10:05 -0300 Subject: [PATCH 07/21] fix deriv path --- src/subcommand/wallet/create.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/subcommand/wallet/create.rs b/src/subcommand/wallet/create.rs index 45b00406ba..8ab1e80012 100644 --- a/src/subcommand/wallet/create.rs +++ b/src/subcommand/wallet/create.rs @@ -33,7 +33,13 @@ impl Create { let secp = Secp256k1::new(); let root = bip32::ExtendedPrivKey::new_master(options.chain().network(), &seed)?; - let xprv = root.derive_priv(&secp, &DerivationPath::from_str("m/86'/1'/0'")?)?; + let coin_type = match options.chain().network() { + Network::Bitcoin => 0, + _ => 1, + }; + + let derivation_path = &DerivationPath::from_str(format!("m/86'/{}'/0'", coin_type).as_str())?; + let xprv = root.derive_priv(&secp, derivation_path)?; let xpub = ExtendedPubKey::from_priv(&secp, &xprv); let public_key = xpub .derive_pub(&secp, &DerivationPath::from_str("m/0/0")?)? From 80393d840841fb20b9a925363415cc3068a78f59 Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Mon, 10 Jul 2023 19:11:47 -0300 Subject: [PATCH 08/21] create file cmd --- src/index.rs | 5 ++++- src/index/updater/inscription_updater.rs | 4 ++-- src/subcommand.rs | 4 ++++ src/subcommand/file.rs | 24 ++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/subcommand/file.rs diff --git a/src/index.rs b/src/index.rs index 7a190890f0..39c75c5a37 100644 --- a/src/index.rs +++ b/src/index.rs @@ -453,7 +453,10 @@ impl Index { if let Ok(current_dir) = env::current_dir() { if let Some(home) = home_dir() { if current_dir != home { - println!("Current working directory is not home ({:?}), cannot update the index!", home); + println!( + "Current working directory is not home ({:?}), cannot update the index!", + home + ); panic!("Current working directory must be the home directory") } } else { diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 6ccfac8690..487c8079fc 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -299,7 +299,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { pointer, unbound, }, - inscription_data, + inscription_data, } = flotsam { Flotsam { @@ -532,7 +532,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { // let inscription_number = InscriptionEntry::load(inscription_entry.value()).number; let inscription_number = if new_inscription_number != 0 { new_inscription_number - } else { + } else { let inscription_entry = self.id_to_entry.get(&inscription_id.store())?.unwrap(); InscriptionEntry::load(inscription_entry.value()).number }; diff --git a/src/subcommand.rs b/src/subcommand.rs index 93e393dcea..8bd3a63fc7 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -2,6 +2,7 @@ use super::*; pub mod decode; pub mod epochs; +pub mod file; pub mod find; mod index; pub mod info; @@ -45,6 +46,8 @@ pub(crate) enum Subcommand { Traits(traits::Traits), #[command(subcommand, about = "Wallet commands")] Wallet(wallet::Wallet), + #[clap(about = "Create a file with the inscription's content")] + File(file::File), } impl Subcommand { @@ -69,6 +72,7 @@ impl Subcommand { Self::Teleburn(teleburn) => teleburn.run(), Self::Traits(traits) => traits.run(), Self::Wallet(wallet) => wallet.run(options), + Self::File(file) => file.run(options), } } } diff --git a/src/subcommand/file.rs b/src/subcommand/file.rs new file mode 100644 index 0000000000..ead49c9d83 --- /dev/null +++ b/src/subcommand/file.rs @@ -0,0 +1,24 @@ +use super::*; + +#[derive(Debug, Parser)] +pub(crate) struct File { + #[clap(long)] + pub(crate) inscription: InscriptionId, + #[clap()] + pub(crate) filename: String, +} + +impl File { + pub(crate) fn run(&self, options: Options) -> Result { + let client = options.bitcoin_rpc_client_for_wallet_command(false)?; + + let tx = client.get_raw_transaction(&self.inscription.txid, None)?; + let inscription = &Inscription::from_transaction(&tx)[self.inscription.index as usize]; + + let content_bytes = inscription.inscription.body().unwrap(); + let mut file = fs::File::create(self.filename.clone())?; + file.write_all(content_bytes)?; + + Ok(()) + } +} From 829385d10e43cd34872f6d29c640fcf13ca6f382 Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Wed, 12 Jul 2023 13:29:59 -0300 Subject: [PATCH 09/21] change rpc client --- src/index/updater/inscription_updater.rs | 2 +- src/subcommand/file.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 487c8079fc..7559f88b61 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -1,5 +1,5 @@ -use {super::*, inscription::Curse}; use serde_json::Value; +use {super::*, inscription::Curse}; #[derive(Debug, Clone)] pub(super) struct Flotsam { diff --git a/src/subcommand/file.rs b/src/subcommand/file.rs index ead49c9d83..929c9dae51 100644 --- a/src/subcommand/file.rs +++ b/src/subcommand/file.rs @@ -10,7 +10,7 @@ pub(crate) struct File { impl File { pub(crate) fn run(&self, options: Options) -> Result { - let client = options.bitcoin_rpc_client_for_wallet_command(false)?; + let client = options.bitcoin_rpc_client()?; let tx = client.get_raw_transaction(&self.inscription.txid, None)?; let inscription = &Inscription::from_transaction(&tx)[self.inscription.index as usize]; From df90126500cba5d0fbe3099fae5d062e535be1fb Mon Sep 17 00:00:00 2001 From: ericatallah Date: Thu, 27 Jul 2023 16:59:44 -0700 Subject: [PATCH 10/21] fix mismatched type --- src/subcommand/wallet/create.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/subcommand/wallet/create.rs b/src/subcommand/wallet/create.rs index 8ab1e80012..f5420424ce 100644 --- a/src/subcommand/wallet/create.rs +++ b/src/subcommand/wallet/create.rs @@ -1,14 +1,12 @@ -use bitcoin::{ - secp256k1::PublicKey, - util::bip32::{self, ExtendedPubKey}, -}; +use bitcoin::secp256k1::PublicKey; +use bitcoin::bip32::{self, ExtendedPubKey}; use super::*; #[derive(Serialize, Deserialize)] pub struct Output { pub mnemonic: Mnemonic, - pub address: Address, + pub address: bitcoin::Address, pub public_key: PublicKey, pub passphrase: Option, } From 2a30f7659655dd64a1d04b804eaade75e63d868a Mon Sep 17 00:00:00 2001 From: ericatallah Date: Sun, 4 Jun 2023 14:26:36 -0700 Subject: [PATCH 11/21] add inscription_satpoint logger --- src/index/updater/inscription_updater.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 7559f88b61..0c03e5bc14 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -1,5 +1,6 @@ use serde_json::Value; use {super::*, inscription::Curse}; +use serde_json::Value; #[derive(Debug, Clone)] pub(super) struct Flotsam { From b695a79ab00594176d4814e87dd53bc05f4ba13c Mon Sep 17 00:00:00 2001 From: ericatallah Date: Mon, 5 Jun 2023 11:56:06 -0700 Subject: [PATCH 12/21] add pub key and address to wallet create output --- src/subcommand/wallet/create.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/subcommand/wallet/create.rs b/src/subcommand/wallet/create.rs index f5420424ce..7e1a2cc550 100644 --- a/src/subcommand/wallet/create.rs +++ b/src/subcommand/wallet/create.rs @@ -1,5 +1,7 @@ -use bitcoin::secp256k1::PublicKey; -use bitcoin::bip32::{self, ExtendedPubKey}; +use bitcoin::{ + secp256k1::PublicKey, + util::bip32::{self, ExtendedPubKey}, +}; use super::*; From 766148e43b91a66f3ee222087f015d123e55852b Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Mon, 10 Jul 2023 19:11:47 -0300 Subject: [PATCH 13/21] create file cmd --- src/subcommand/file.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/subcommand/file.rs b/src/subcommand/file.rs index 929c9dae51..4ce69958bb 100644 --- a/src/subcommand/file.rs +++ b/src/subcommand/file.rs @@ -11,6 +11,8 @@ pub(crate) struct File { impl File { pub(crate) fn run(&self, options: Options) -> Result { let client = options.bitcoin_rpc_client()?; + // TODO: not sure which one we need here + // let client = options.bitcoin_rpc_client_for_wallet_command(false)?; let tx = client.get_raw_transaction(&self.inscription.txid, None)?; let inscription = &Inscription::from_transaction(&tx)[self.inscription.index as usize]; From 196b7e3eb417c16e202df073b3fcfc9ccfe2a3ee Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Wed, 12 Jul 2023 13:29:59 -0300 Subject: [PATCH 14/21] change rpc client --- src/index/updater/inscription_updater.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 0c03e5bc14..7559f88b61 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -1,6 +1,5 @@ use serde_json::Value; use {super::*, inscription::Curse}; -use serde_json::Value; #[derive(Debug, Clone)] pub(super) struct Flotsam { From 6b5399489db91915d6214378158ba8bf2b39e5c0 Mon Sep 17 00:00:00 2001 From: ericatallah Date: Thu, 27 Jul 2023 16:59:44 -0700 Subject: [PATCH 15/21] fix mismatched type --- src/subcommand/wallet/create.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/subcommand/wallet/create.rs b/src/subcommand/wallet/create.rs index 7e1a2cc550..f5420424ce 100644 --- a/src/subcommand/wallet/create.rs +++ b/src/subcommand/wallet/create.rs @@ -1,7 +1,5 @@ -use bitcoin::{ - secp256k1::PublicKey, - util::bip32::{self, ExtendedPubKey}, -}; +use bitcoin::secp256k1::PublicKey; +use bitcoin::bip32::{self, ExtendedPubKey}; use super::*; From 5caddeb00f0ddc5f0eab51c74f2869e909ab8b81 Mon Sep 17 00:00:00 2001 From: ericatallah Date: Wed, 13 Sep 2023 22:46:15 -0700 Subject: [PATCH 16/21] fix mismatched return type in file cmd --- src/subcommand/file.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/subcommand/file.rs b/src/subcommand/file.rs index 4ce69958bb..7cbce11f15 100644 --- a/src/subcommand/file.rs +++ b/src/subcommand/file.rs @@ -9,7 +9,7 @@ pub(crate) struct File { } impl File { - pub(crate) fn run(&self, options: Options) -> Result { + pub(crate) fn run(&self, options: Options) -> SubcommandResult { let client = options.bitcoin_rpc_client()?; // TODO: not sure which one we need here // let client = options.bitcoin_rpc_client_for_wallet_command(false)?; @@ -21,6 +21,6 @@ impl File { let mut file = fs::File::create(self.filename.clone())?; file.write_all(content_bytes)?; - Ok(()) + Ok(Box::new(())) } } From 3997ddbe3c4299ee16fcf5295489af1208089efc Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Mon, 30 Oct 2023 20:49:42 -0300 Subject: [PATCH 17/21] fix conflicts --- src/index/updater/inscription_updater.rs | 6 +++--- src/subcommand/file.rs | 26 ++++++++++++++++-------- src/subcommand/wallet/create.rs | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 7559f88b61..4eaf2639b8 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -256,7 +256,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { pointer: inscription.payload.pointer(), unbound, }, - inscription_data: Some(inscription.inscription.clone()), + inscription_data: Some(inscription.payload.clone()), }); envelopes.next(); @@ -440,7 +440,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { new_satpoint: SatPoint, ) -> Result { let inscription_id = flotsam.inscription_id.store(); - let mut new_inscription_number: i64 = 0; + let new_inscription_number: i64 = 0; let unbound = match flotsam.origin { Origin::Old { old_satpoint } => { self.satpoint_to_id.remove_all(&old_satpoint.store())?; @@ -534,7 +534,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> { new_inscription_number } else { let inscription_entry = self.id_to_entry.get(&inscription_id.store())?.unwrap(); - InscriptionEntry::load(inscription_entry.value()).number + InscriptionEntry::load(inscription_entry.value()).inscription_number }; if let Some(inscription) = flotsam.inscription_data { diff --git a/src/subcommand/file.rs b/src/subcommand/file.rs index 7cbce11f15..28848685b2 100644 --- a/src/subcommand/file.rs +++ b/src/subcommand/file.rs @@ -5,21 +5,31 @@ pub(crate) struct File { #[clap(long)] pub(crate) inscription: InscriptionId, #[clap()] - pub(crate) filename: String, + pub(crate) filename: PathBuf, } impl File { pub(crate) fn run(&self, options: Options) -> SubcommandResult { let client = options.bitcoin_rpc_client()?; - // TODO: not sure which one we need here - // let client = options.bitcoin_rpc_client_for_wallet_command(false)?; - let tx = client.get_raw_transaction(&self.inscription.txid, None)?; - let inscription = &Inscription::from_transaction(&tx)[self.inscription.index as usize]; + let inscriptions = ParsedEnvelope::from_transaction(&tx); + + let mut filename = self.filename.clone(); + let mut file_number = 2; + + for inscription in inscriptions { + let content_bytes = inscription.payload.body().unwrap(); + let mut file = fs::File::create(self.filename.clone())?; + file.write_all(content_bytes)?; - let content_bytes = inscription.inscription.body().unwrap(); - let mut file = fs::File::create(self.filename.clone())?; - file.write_all(content_bytes)?; + filename.set_file_name(format!( + "{}-{}{}", + file_number, + filename.file_stem().unwrap().to_str().unwrap(), + filename.extension().unwrap().to_str().unwrap() + )); + file_number += 1; + } Ok(Box::new(())) } diff --git a/src/subcommand/wallet/create.rs b/src/subcommand/wallet/create.rs index f5420424ce..e230a5b4d5 100644 --- a/src/subcommand/wallet/create.rs +++ b/src/subcommand/wallet/create.rs @@ -1,5 +1,5 @@ -use bitcoin::secp256k1::PublicKey; use bitcoin::bip32::{self, ExtendedPubKey}; +use bitcoin::secp256k1::PublicKey; use super::*; From dc574a5782f88bf1d74afe2d97c836d9231ec03f Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Mon, 30 Oct 2023 21:00:20 -0300 Subject: [PATCH 18/21] add log message --- src/subcommand/file.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/subcommand/file.rs b/src/subcommand/file.rs index 28848685b2..da8d589120 100644 --- a/src/subcommand/file.rs +++ b/src/subcommand/file.rs @@ -18,6 +18,7 @@ impl File { let mut file_number = 2; for inscription in inscriptions { + println!("Saving inscription to file {:?}", filename); let content_bytes = inscription.payload.body().unwrap(); let mut file = fs::File::create(self.filename.clone())?; file.write_all(content_bytes)?; From d48936e705229da714edd85781ad67c677ee8c4a Mon Sep 17 00:00:00 2001 From: Felipe Lincoln Date: Mon, 30 Oct 2023 21:09:47 -0300 Subject: [PATCH 19/21] reorder format --- src/subcommand/file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommand/file.rs b/src/subcommand/file.rs index da8d589120..1c0d58e270 100644 --- a/src/subcommand/file.rs +++ b/src/subcommand/file.rs @@ -25,8 +25,8 @@ impl File { filename.set_file_name(format!( "{}-{}{}", - file_number, filename.file_stem().unwrap().to_str().unwrap(), + file_number, filename.extension().unwrap().to_str().unwrap() )); file_number += 1; From 18eb595772d73e75ab21412c6f7135591ccd4db5 Mon Sep 17 00:00:00 2001 From: ericatallah Date: Fri, 17 Nov 2023 11:53:33 -0800 Subject: [PATCH 20/21] loosen csp for iphone --- src/subcommand/server.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index 9f69a6d9b8..fd94bddbbb 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -946,12 +946,28 @@ impl Server { ); headers.insert( header::CONTENT_SECURITY_POLICY, - HeaderValue::from_static("default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob:"), + HeaderValue::from_static("default-src 'self' https://ord.osura.com/content/ 'unsafe-eval' 'unsafe-inline' data: blob:"), ); headers.append( header::CONTENT_SECURITY_POLICY, HeaderValue::from_static("default-src *:*/content/ *:*/blockheight *:*/blockhash *:*/blockhash/ *:*/blocktime 'unsafe-eval' 'unsafe-inline' data: blob:"), ); + headers.append( + header::CONTENT_SECURITY_POLICY, + HeaderValue::from_static("script-src-elem 'self' 'unsafe-eval' 'unsafe-inline' https://ord.osura.com/content/ blob:"), + ); + headers.append( + header::CONTENT_SECURITY_POLICY, + HeaderValue::from_static("style-src 'self' 'unsafe-eval' 'unsafe-hashes' 'unsafe-inline' https://ord.osura.com/content/"), + ); + headers.append( + header::CONTENT_SECURITY_POLICY, + HeaderValue::from_static("style-src-elem 'self' 'unsafe-eval' 'unsafe-hashes' 'unsafe-inline' https://ord.osura.com/content/"), + ); + headers.append( + header::CONTENT_SECURITY_POLICY, + HeaderValue::from_static("script-src 'self' 'unsafe-eval' 'unsafe-inline' https://ord.osura.com/content/ data: blob:"), + ); headers.insert( header::CACHE_CONTROL, HeaderValue::from_static("max-age=31536000, immutable"), From 7009feed19ad278094108bc5dad2041579f600be Mon Sep 17 00:00:00 2001 From: ericatallah Date: Fri, 17 Nov 2023 12:06:00 -0800 Subject: [PATCH 21/21] remove wildcards --- src/subcommand/server.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index fd94bddbbb..3de54376a3 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -950,7 +950,8 @@ impl Server { ); headers.append( header::CONTENT_SECURITY_POLICY, - HeaderValue::from_static("default-src *:*/content/ *:*/blockheight *:*/blockhash *:*/blockhash/ *:*/blocktime 'unsafe-eval' 'unsafe-inline' data: blob:"), + // HeaderValue::from_static("default-src *:*/content/ *:*/blockheight *:*/blockhash *:*/blockhash/ *:*/blocktime 'unsafe-eval' 'unsafe-inline' data: blob:"), + HeaderValue::from_static("default-src https://ord.osura.com/content/ https://ord.osura.com/blockheight https://ord.osura.com/blockhash https://ord.osura.com/blockhash/ https://ord.osura.com/blocktime 'unsafe-eval' 'unsafe-inline' data: blob:"), ); headers.append( header::CONTENT_SECURITY_POLICY,