diff --git a/src/index.rs b/src/index.rs index 04a0d650a7..c6b6d83507 100644 --- a/src/index.rs +++ b/src/index.rs @@ -633,7 +633,7 @@ impl Index { } pub(crate) fn export(&self, filename: &String, include_addresses: bool) -> Result { - let mut writer = BufWriter::new(File::create(filename)?); + let mut writer = BufWriter::new(fs::File::create(filename)?); let rtx = self.database.begin_read()?; let blocks_indexed = rtx diff --git a/src/lib.rs b/src/lib.rs index 75f08f933f..e3c1797efc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,6 @@ use { }, into_usize::IntoUsize, representation::Representation, - runes::Etching, settings::Settings, subcommand::{Subcommand, SubcommandResult}, tally::Tally, @@ -63,7 +62,7 @@ use { collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque}, env, fmt::{self, Display, Formatter}, - fs::{self, File}, + fs, io::{self, Cursor, Read}, mem, net::ToSocketAddrs, diff --git a/src/settings.rs b/src/settings.rs index 339ae2eb7e..2a06223bc6 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -73,7 +73,7 @@ impl Settings { }; let config = if let Some(config_path) = config_path { - serde_yaml::from_reader(File::open(&config_path).context(anyhow!( + serde_yaml::from_reader(fs::File::open(&config_path).context(anyhow!( "failed to open config file `{}`", config_path.display() ))?) @@ -973,7 +973,7 @@ mod tests { #[test] fn example_config_file_is_valid() { - let _: Settings = serde_yaml::from_reader(File::open("ord.yaml").unwrap()).unwrap(); + let _: Settings = serde_yaml::from_reader(fs::File::open("ord.yaml").unwrap()).unwrap(); } #[test] diff --git a/src/subcommand/decode.rs b/src/subcommand/decode.rs index 15dfef81c8..bc52f945e2 100644 --- a/src/subcommand/decode.rs +++ b/src/subcommand/decode.rs @@ -77,7 +77,7 @@ impl Decode { .bitcoin_rpc_client(None)? .get_raw_transaction(&txid, None)? } else if let Some(file) = self.file { - Transaction::consensus_decode(&mut File::open(file)?)? + Transaction::consensus_decode(&mut fs::File::open(file)?)? } else { Transaction::consensus_decode(&mut io::stdin())? }; diff --git a/src/subcommand/env.rs b/src/subcommand/env.rs index e994195e0c..9e2a4058f3 100644 --- a/src/subcommand/env.rs +++ b/src/subcommand/env.rs @@ -145,7 +145,7 @@ rpcport={bitcoind_port} } serde_json::to_writer_pretty( - File::create(self.directory.join("env.json"))?, + fs::File::create(self.directory.join("env.json"))?, &Info { bitcoind_port, ord_port, diff --git a/src/subcommand/wallet.rs b/src/subcommand/wallet.rs index cbb5484267..9c4e115dcf 100644 --- a/src/subcommand/wallet.rs +++ b/src/subcommand/wallet.rs @@ -1,9 +1,6 @@ use { super::*, - crate::wallet::{ - inscribe::{Batch, Batchfile, Mode}, - Wallet, - }, + crate::wallet::{batch, Wallet}, bitcoincore_rpc::bitcoincore_rpc_json::ListDescriptorsResult, reqwest::Url, }; diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index d81efae624..a97a484314 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -89,7 +89,7 @@ impl Inscribe { let postages; let reinscribe; let reveal_satpoints; - let etch; + let etching; let satpoint = match (self.file, self.batch) { (Some(file), None) => { @@ -116,7 +116,7 @@ impl Inscribe { None, )?]; - mode = Mode::SeparateOutputs; + mode = batch::Mode::SeparateOutputs; reinscribe = self.reinscribe; @@ -127,7 +127,7 @@ impl Inscribe { None => wallet.get_change_address()?, }]; - etch = None; + etching = None; if let Some(sat) = self.sat { Some(wallet.find_sat_in_outputs(sat)?) @@ -136,7 +136,7 @@ impl Inscribe { } } (None, Some(batch)) => { - let batchfile = Batchfile::load(&batch)?; + let batchfile = batch::File::load(&batch)?; parent_info = wallet.get_parent_info(batchfile.parent)?; @@ -157,7 +157,7 @@ impl Inscribe { reinscribe = batchfile.reinscribe; - etch = batchfile.etch; + etching = batchfile.etching; if let Some(sat) = batchfile.sat { Some(wallet.find_sat_in_outputs(sat)?) @@ -168,13 +168,13 @@ impl Inscribe { _ => unreachable!(), }; - if let Some(etch) = etch { - let rune = etch.rune.rune; + if let Some(etching) = etching { + let rune = etching.rune.rune; ensure!(!rune.is_reserved(), "rune `{rune}` is reserved"); ensure!( - etch.divisibility <= crate::runes::MAX_DIVISIBILITY, + etching.divisibility <= crate::runes::MAX_DIVISIBILITY, " must be less than or equal 38" ); @@ -201,11 +201,11 @@ impl Inscribe { ); } - Batch { + batch::Plan { commit_fee_rate: self.commit_fee_rate.unwrap_or(self.fee_rate), destinations, dry_run: self.dry_run, - etch, + etching, inscriptions, mode, no_backup: self.no_backup, @@ -234,7 +234,7 @@ impl Inscribe { Ok(Some(cbor)) } else if let Some(path) = json { let value: serde_json::Value = - serde_json::from_reader(File::open(path)?).context("failed to parse JSON metadata")?; + serde_json::from_reader(fs::File::open(path)?).context("failed to parse JSON metadata")?; let mut cbor = Vec::new(); ciborium::into_writer(&value, &mut cbor)?; @@ -249,7 +249,7 @@ impl Inscribe { mod tests { use { super::*, - crate::wallet::inscribe::{BatchEntry, BatchTransactions, ParentInfo}, + crate::wallet::batch::{self, ParentInfo}, bitcoin::policy::MAX_STANDARD_TX_WEIGHT, serde_yaml::{Mapping, Value}, tempfile::TempDir, @@ -263,11 +263,11 @@ mod tests { let reveal_address = recipient(); let reveal_change = [commit_address, change(1)]; - let BatchTransactions { + let batch::Transactions { commit_tx, reveal_tx, .. - } = Batch { + } = batch::Plan { satpoint: Some(satpoint(1, 0)), parent_info: None, inscriptions: vec![inscription], @@ -277,7 +277,7 @@ mod tests { no_limit: false, reinscribe: false, postages: vec![TARGET_POSTAGE], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -309,11 +309,11 @@ mod tests { let reveal_address = recipient(); let reveal_change = [commit_address, change(1)]; - let BatchTransactions { + let batch::Transactions { commit_tx, reveal_tx, .. - } = Batch { + } = batch::Plan { satpoint: Some(satpoint(1, 0)), parent_info: None, inscriptions: vec![inscription], @@ -323,7 +323,7 @@ mod tests { no_limit: false, reinscribe: false, postages: vec![TARGET_POSTAGE], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -358,7 +358,7 @@ mod tests { let commit_address = change(0); let reveal_address = recipient(); - let error = Batch { + let error = batch::Plan { satpoint, parent_info: None, inscriptions: vec![inscription], @@ -368,7 +368,7 @@ mod tests { no_limit: false, reinscribe: false, postages: vec![TARGET_POSTAGE], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -410,7 +410,7 @@ mod tests { let commit_address = change(0); let reveal_address = recipient(); - assert!(Batch { + assert!(batch::Plan { satpoint, parent_info: None, inscriptions: vec![inscription], @@ -420,7 +420,7 @@ mod tests { no_limit: false, reinscribe: false, postages: vec![TARGET_POSTAGE], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -456,11 +456,11 @@ mod tests { let reveal_address = recipient(); let fee_rate = 3.3; - let BatchTransactions { + let batch::Transactions { commit_tx, reveal_tx, .. - } = Batch { + } = batch::Plan { satpoint, parent_info: None, inscriptions: vec![inscription], @@ -470,7 +470,7 @@ mod tests { no_limit: false, reinscribe: false, postages: vec![TARGET_POSTAGE], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -544,11 +544,11 @@ mod tests { let reveal_address = recipient(); let fee_rate = 4.0; - let BatchTransactions { + let batch::Transactions { commit_tx, reveal_tx, .. - } = Batch { + } = batch::Plan { satpoint: None, parent_info: Some(parent_info.clone()), inscriptions: vec![child_inscription], @@ -558,7 +558,7 @@ mod tests { no_limit: false, reinscribe: false, postages: vec![TARGET_POSTAGE], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -631,11 +631,11 @@ mod tests { let commit_fee_rate = 3.3; let fee_rate = 1.0; - let BatchTransactions { + let batch::Transactions { commit_tx, reveal_tx, .. - } = Batch { + } = batch::Plan { satpoint, parent_info: None, inscriptions: vec![inscription], @@ -645,7 +645,7 @@ mod tests { no_limit: false, reinscribe: false, postages: vec![TARGET_POSTAGE], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -694,7 +694,7 @@ mod tests { let commit_address = change(0); let reveal_address = recipient(); - let error = Batch { + let error = batch::Plan { satpoint, parent_info: None, inscriptions: vec![inscription], @@ -704,7 +704,7 @@ mod tests { no_limit: false, reinscribe: false, postages: vec![TARGET_POSTAGE], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -735,7 +735,7 @@ mod tests { let commit_address = change(0); let reveal_address = recipient(); - let BatchTransactions { reveal_tx, .. } = Batch { + let batch::Transactions { reveal_tx, .. } = batch::Plan { satpoint, parent_info: None, inscriptions: vec![inscription], @@ -745,7 +745,7 @@ mod tests { no_limit: true, reinscribe: false, postages: vec![TARGET_POSTAGE], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -823,15 +823,15 @@ inscriptions: metadata.insert(Value::String("description".to_string()), Value::String("Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tristique, massa nec condimentum venenatis, ante massa tempor velit, et accumsan ipsum ligula a massa. Nunc quis orci ante.".to_string())); assert_eq!( - Batchfile::load(&batch_path).unwrap(), - Batchfile { + batch::File::load(&batch_path).unwrap(), + batch::File { inscriptions: vec![ - BatchEntry { + batch::Entry { file: inscription_path, metadata: Some(Value::Mapping(metadata)), ..Default::default() }, - BatchEntry { + batch::Entry { file: brc20_path, metaprotocol: Some("brc-20".to_string()), ..Default::default() @@ -853,7 +853,7 @@ inscriptions: ) .unwrap(); - assert!(Batchfile::load(&batch_path) + assert!(batch::File::load(&batch_path) .unwrap_err() .to_string() .contains("unknown field `unknown`")); @@ -905,15 +905,15 @@ inscriptions: .into(), ]; - let mode = Mode::SharedOutput; + let mode = batch::Mode::SharedOutput; let fee_rate = 4.0.try_into().unwrap(); - let BatchTransactions { + let batch::Transactions { commit_tx, reveal_tx, .. - } = Batch { + } = batch::Plan { satpoint: None, parent_info: Some(parent_info.clone()), inscriptions, @@ -1032,15 +1032,15 @@ inscriptions: }) .collect::>(); - let mode = Mode::SatPoints; + let mode = batch::Mode::SatPoints; let fee_rate = 1.0.try_into().unwrap(); - let BatchTransactions { + let batch::Transactions { commit_tx, reveal_tx, .. - } = Batch { + } = batch::Plan { reveal_satpoints: reveal_satpoints.clone(), parent_info: Some(parent_info.clone()), inscriptions, @@ -1142,7 +1142,7 @@ inscriptions: let commit_address = change(1); let reveal_addresses = vec![recipient()]; - let error = Batch { + let error = batch::Plan { satpoint: None, parent_info: Some(parent_info.clone()), inscriptions, @@ -1152,7 +1152,7 @@ inscriptions: no_limit: false, reinscribe: false, postages: vec![Amount::from_sat(10_000); 3], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -1219,7 +1219,7 @@ inscriptions: let commit_address = change(1); let reveal_addresses = vec![recipient(), recipient()]; - let _ = Batch { + let _ = batch::Plan { satpoint: None, parent_info: Some(parent_info.clone()), inscriptions, @@ -1229,7 +1229,7 @@ inscriptions: no_limit: false, reinscribe: false, postages: vec![Amount::from_sat(10_000)], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -1258,7 +1258,7 @@ inscriptions: let commit_address = change(1); let reveal_addresses = vec![recipient()]; - let error = Batch { + let error = batch::Plan { satpoint: None, parent_info: None, inscriptions, @@ -1268,7 +1268,7 @@ inscriptions: no_limit: false, reinscribe: false, postages: vec![Amount::from_sat(30_000); 3], - mode: Mode::SharedOutput, + mode: batch::Mode::SharedOutput, ..Default::default() } .create_batch_transactions( @@ -1308,11 +1308,11 @@ inscriptions: inscription("text/plain", [b'O'; 222]), ]; - let mode = Mode::SeparateOutputs; + let mode = batch::Mode::SeparateOutputs; let fee_rate = 4.0.try_into().unwrap(); - let BatchTransactions { reveal_tx, .. } = Batch { + let batch::Transactions { reveal_tx, .. } = batch::Plan { satpoint: None, parent_info: None, inscriptions, @@ -1389,15 +1389,15 @@ inscriptions: .into(), ]; - let mode = Mode::SeparateOutputs; + let mode = batch::Mode::SeparateOutputs; let fee_rate = 4.0.try_into().unwrap(); - let BatchTransactions { + let batch::Transactions { commit_tx, reveal_tx, .. - } = Batch { + } = batch::Plan { satpoint: None, parent_info: Some(parent_info.clone()), inscriptions, @@ -1463,7 +1463,7 @@ inscriptions: #[test] fn example_batchfile_deserializes_successfully() { - Batchfile::load(Path::new("batch.yaml")).unwrap(); + batch::File::load(Path::new("batch.yaml")).unwrap(); } #[test] diff --git a/src/wallet.rs b/src/wallet.rs index d22c404973..add17ba29c 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -1,6 +1,7 @@ use { super::*, base64::{self, Engine}, + batch::ParentInfo, bitcoin::secp256k1::{All, Secp256k1}, bitcoin::{ bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, Fingerprint}, @@ -13,13 +14,12 @@ use { future::{self, FutureExt}, try_join, TryFutureExt, }, - inscribe::ParentInfo, miniscript::descriptor::{DescriptorSecretKey, DescriptorXKey, Wildcard}, reqwest::{header, Url}, transaction_builder::TransactionBuilder, }; -pub mod inscribe; +pub mod batch; pub mod transaction_builder; #[derive(Clone)] diff --git a/src/wallet/inscribe.rs b/src/wallet/batch.rs similarity index 70% rename from src/wallet/inscribe.rs rename to src/wallet/batch.rs index b27fa3ee64..b5f4fe7051 100644 --- a/src/wallet/inscribe.rs +++ b/src/wallet/batch.rs @@ -14,29 +14,28 @@ use { wallet::transaction_builder::Target, }; -pub use {batch::Batch, batch_entry::BatchEntry, batchfile::Batchfile, etch::Etch, mode::Mode}; +pub(crate) use transactions::Transactions; -pub mod batch; -pub mod batch_entry; -pub mod batchfile; -mod etch; -pub mod mode; +pub use {entry::Entry, etching::Etching, file::File, mint::Mint, mode::Mode, plan::Plan}; -#[derive(Debug)] -pub(crate) struct BatchTransactions { - pub(crate) rune: Option, - pub(crate) commit_tx: Transaction, - pub(crate) recovery_key_pair: TweakedKeyPair, - pub(crate) reveal_tx: Transaction, - pub(crate) total_fees: u64, -} +pub mod entry; +mod etching; +pub mod file; +mod mint; +pub mod mode; +pub mod plan; +mod transactions; -#[derive(Serialize, Deserialize, PartialEq, Debug, Copy, Clone, Default)] -#[serde(deny_unknown_fields)] -pub struct BatchMint { - pub deadline: Option, - pub limit: Decimal, - pub term: Option, +#[derive(Debug, Serialize, Deserialize)] +pub struct Output { + pub commit: Txid, + pub commit_psbt: Option, + pub inscriptions: Vec, + pub parent: Option, + pub reveal: Txid, + pub reveal_psbt: Option, + pub rune: Option, + pub total_fees: u64, } #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] @@ -53,18 +52,6 @@ pub struct RuneInfo { pub rune: SpacedRune, } -#[derive(Debug, Serialize, Deserialize)] -pub struct Output { - pub commit: Txid, - pub commit_psbt: Option, - pub inscriptions: Vec, - pub parent: Option, - pub reveal: Txid, - pub reveal_psbt: Option, - pub rune: Option, - pub total_fees: u64, -} - #[derive(Clone, Debug)] pub struct ParentInfo { pub destination: Address, diff --git a/src/wallet/inscribe/batch_entry.rs b/src/wallet/batch/entry.rs similarity index 93% rename from src/wallet/inscribe/batch_entry.rs rename to src/wallet/batch/entry.rs index 7e24b11d06..cba1bb537b 100644 --- a/src/wallet/inscribe/batch_entry.rs +++ b/src/wallet/batch/entry.rs @@ -2,7 +2,7 @@ use super::*; #[derive(Serialize, Deserialize, Default, PartialEq, Debug, Clone)] #[serde(deny_unknown_fields)] -pub struct BatchEntry { +pub struct Entry { pub delegate: Option, pub destination: Option>, pub file: PathBuf, @@ -11,7 +11,7 @@ pub struct BatchEntry { pub satpoint: Option, } -impl BatchEntry { +impl Entry { pub(crate) fn metadata(&self) -> Result>> { Ok(match &self.metadata { None => None, diff --git a/src/wallet/inscribe/etch.rs b/src/wallet/batch/etching.rs similarity index 81% rename from src/wallet/inscribe/etch.rs rename to src/wallet/batch/etching.rs index 5741bb29b6..f7d2683a9d 100644 --- a/src/wallet/inscribe/etch.rs +++ b/src/wallet/batch/etching.rs @@ -2,9 +2,9 @@ use super::*; #[derive(Serialize, Deserialize, PartialEq, Debug, Copy, Clone, Default)] #[serde(deny_unknown_fields)] -pub struct Etch { +pub struct Etching { pub divisibility: u8, - pub mint: Option, + pub mint: Option, pub premine: Decimal, pub rune: SpacedRune, pub symbol: char, diff --git a/src/wallet/inscribe/batchfile.rs b/src/wallet/batch/file.rs similarity index 94% rename from src/wallet/inscribe/batchfile.rs rename to src/wallet/batch/file.rs index 76607a0072..dc659bfee4 100644 --- a/src/wallet/inscribe/batchfile.rs +++ b/src/wallet/batch/file.rs @@ -2,21 +2,21 @@ use super::*; #[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Default)] #[serde(deny_unknown_fields)] -pub struct Batchfile { - pub inscriptions: Vec, +pub struct File { + pub inscriptions: Vec, pub mode: Mode, pub parent: Option, pub postage: Option, #[serde(default)] pub reinscribe: bool, - pub etch: Option, + pub etching: Option, pub sat: Option, pub satpoint: Option, } -impl Batchfile { - pub(crate) fn load(path: &Path) -> Result { - let batchfile: Batchfile = serde_yaml::from_reader(File::open(path)?)?; +impl File { + pub(crate) fn load(path: &Path) -> Result { + let batchfile: Self = serde_yaml::from_reader(fs::File::open(path)?)?; ensure!( !batchfile.inscriptions.is_empty(), @@ -139,7 +139,7 @@ impl Batchfile { &entry.file, Some(pointer), self - .etch + .etching .and_then(|etch| (i == 0).then_some(etch.rune.rune)), )?); @@ -218,9 +218,7 @@ inscriptions: .unwrap(); assert_eq!( - Batchfile::load(batch_file.as_path()) - .unwrap_err() - .to_string(), + File::load(batch_file.as_path()).unwrap_err().to_string(), "batchfile cannot set both `sat` and `satpoint`" ); } @@ -245,7 +243,7 @@ inscriptions: .unwrap(); assert_eq!( - Batchfile::load(batch_file.as_path()) + batch::File::load(batch_file.as_path()) .unwrap_err() .to_string(), "specifying `satpoint` in an inscription only works in `satpoints` mode" @@ -271,7 +269,7 @@ inscriptions: .unwrap(); assert_eq!( - Batchfile::load(batch_file.as_path()) + batch::File::load(batch_file.as_path()) .unwrap_err() .to_string(), "if `satpoint` is set for any inscription, then all inscriptions need to specify a satpoint" @@ -298,7 +296,7 @@ inscriptions: .unwrap(); assert_eq!( - Batchfile::load(batch_file.as_path()) + batch::File::load(batch_file.as_path()) .unwrap_err() .to_string(), "`satpoint` can only be specified for first sat of an output" @@ -326,7 +324,7 @@ inscriptions: .unwrap(); assert_eq!( - Batchfile::load(batch_file.as_path()) + batch::File::load(batch_file.as_path()) .unwrap_err() .to_string(), "`postage` cannot be set if in `satpoints` mode" @@ -355,7 +353,7 @@ inscriptions: .unwrap(); assert_eq!( - Batchfile::load(batch_file.as_path()) + batch::File::load(batch_file.as_path()) .unwrap_err() .to_string(), "duplicate satpoint bc4c30829a9564c0d58e6287195622b53ced54a25711d1b86be7cd3a70ef61ed:0:0" diff --git a/src/wallet/batch/mint.rs b/src/wallet/batch/mint.rs new file mode 100644 index 0000000000..a55c95ad9c --- /dev/null +++ b/src/wallet/batch/mint.rs @@ -0,0 +1,9 @@ +use super::*; + +#[derive(Serialize, Deserialize, PartialEq, Debug, Copy, Clone, Default)] +#[serde(deny_unknown_fields)] +pub struct Mint { + pub deadline: Option, + pub limit: Decimal, + pub term: Option, +} diff --git a/src/wallet/inscribe/mode.rs b/src/wallet/batch/mode.rs similarity index 100% rename from src/wallet/inscribe/mode.rs rename to src/wallet/batch/mode.rs diff --git a/src/wallet/inscribe/batch.rs b/src/wallet/batch/plan.rs similarity index 96% rename from src/wallet/inscribe/batch.rs rename to src/wallet/batch/plan.rs index 619b0dcc04..88bf8f57fc 100644 --- a/src/wallet/inscribe/batch.rs +++ b/src/wallet/batch/plan.rs @@ -1,10 +1,10 @@ use super::*; -pub struct Batch { +pub struct Plan { pub(crate) commit_fee_rate: FeeRate, pub(crate) destinations: Vec
, pub(crate) dry_run: bool, - pub(crate) etch: Option, + pub(crate) etching: Option, pub(crate) inscriptions: Vec, pub(crate) mode: Mode, pub(crate) no_backup: bool, @@ -17,13 +17,13 @@ pub struct Batch { pub(crate) satpoint: Option, } -impl Default for Batch { +impl Default for Plan { fn default() -> Self { Self { commit_fee_rate: 1.0.try_into().unwrap(), destinations: Vec::new(), dry_run: false, - etch: None, + etching: None, inscriptions: Vec::new(), mode: Mode::SharedOutput, no_backup: false, @@ -38,7 +38,7 @@ impl Default for Batch { } } -impl Batch { +impl Plan { pub(crate) fn inscribe( &self, locked_utxos: &BTreeSet, @@ -46,7 +46,7 @@ impl Batch { utxos: &BTreeMap, wallet: &Wallet, ) -> SubcommandResult { - let BatchTransactions { + let Transactions { commit_tx, reveal_tx, recovery_key_pair, @@ -126,7 +126,7 @@ impl Batch { .bitcoin_client() .send_raw_transaction(&signed_commit_tx)?; - if self.etch.is_some() { + if self.etching.is_some() { eprintln!("Waiting for rune commitment to mature…"); loop { @@ -266,7 +266,7 @@ impl Batch { mut utxos: BTreeMap, commit_change: [Address; 2], reveal_change: Address, - ) -> Result { + ) -> Result { if let Some(parent_info) = &self.parent_info { for inscription in &self.inscriptions { assert_eq!(inscription.parents(), vec![parent_info.id]); @@ -428,12 +428,12 @@ impl Batch { let premine; let runestone; - if let Some(etch) = self.etch { + if let Some(etching) = self.etching { let mut edicts = Vec::new(); let vout; let destination; - premine = etch.premine.to_amount(etch.divisibility)?; + premine = etching.premine.to_amount(etching.divisibility)?; if premine > 0 { let output = u32::try_from(reveal_outputs.len()).unwrap(); @@ -461,21 +461,21 @@ impl Batch { claim: None, default_output: None, edicts, - etching: Some(Etching { - divisibility: etch.divisibility, - mint: etch + etching: Some(runes::Etching { + divisibility: etching.divisibility, + mint: etching .mint .map(|mint| -> Result { Ok(runes::Mint { deadline: mint.deadline, term: mint.term, - limit: Some(mint.limit.to_amount(etch.divisibility)?), + limit: Some(mint.limit.to_amount(etching.divisibility)?), }) }) .transpose()?, - rune: Some(etch.rune.rune), - spacers: etch.rune.spacers, - symbol: Some(etch.symbol), + rune: Some(etching.rune.rune), + spacers: etching.rune.spacers, + symbol: Some(etching.symbol), }), }; @@ -494,7 +494,7 @@ impl Batch { value: 0, }); - rune = Some((destination, etch.rune, vout)); + rune = Some((destination, etching.rune, vout)); } else { premine = 0; rune = None; @@ -658,7 +658,7 @@ impl Batch { rune, }); - Ok(BatchTransactions { + Ok(Transactions { commit_tx: unsigned_commit_tx, recovery_key_pair, reveal_tx, diff --git a/src/wallet/batch/transactions.rs b/src/wallet/batch/transactions.rs new file mode 100644 index 0000000000..72f1416b67 --- /dev/null +++ b/src/wallet/batch/transactions.rs @@ -0,0 +1,10 @@ +use super::*; + +#[derive(Debug)] +pub(crate) struct Transactions { + pub(crate) rune: Option, + pub(crate) commit_tx: Transaction, + pub(crate) recovery_key_pair: TweakedKeyPair, + pub(crate) reveal_tx: Transaction, + pub(crate) total_fees: u64, +} diff --git a/tests/lib.rs b/tests/lib.rs index ccf7d1c6d4..778ebfd7c6 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -11,12 +11,8 @@ use { chrono::{DateTime, Utc}, executable_path::executable_path, ord::{ - api, - chain::Chain, - outgoing::Outgoing, - subcommand::runes::RuneInfo, - wallet::inscribe::{BatchEntry, Batchfile, Etch}, - Edict, InscriptionId, Pile, Rune, RuneEntry, RuneId, Runestone, SpacedRune, + api, chain::Chain, outgoing::Outgoing, subcommand::runes::RuneInfo, wallet::batch, Edict, + InscriptionId, Pile, Rune, RuneEntry, RuneId, Runestone, SpacedRune, }, ordinals::{Charm, Rarity, Sat, SatPoint}, pretty_assertions::assert_eq as pretty_assert_eq, @@ -78,7 +74,7 @@ const RUNE: u128 = 99246114928149462; type Balance = ord::subcommand::wallet::balance::Output; type Create = ord::subcommand::wallet::create::Output; -type Inscribe = ord::wallet::inscribe::Output; +type Inscribe = ord::wallet::batch::Output; type Inscriptions = Vec; type Send = ord::subcommand::wallet::send::Output; type Supply = ord::subcommand::supply::Output; @@ -190,15 +186,15 @@ fn etch( batch( bitcoin_rpc_server, ord_rpc_server, - Batchfile { - etch: Some(Etch { + batch::File { + etching: Some(batch::Etching { divisibility: 0, mint: None, premine: "1000".parse().unwrap(), rune: SpacedRune { rune, spacers: 0 }, symbol: '¢', }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.jpeg".into(), ..Default::default() }], @@ -210,7 +206,7 @@ fn etch( fn batch( bitcoin_rpc_server: &test_bitcoincore_rpc::Handle, ord_rpc_server: &TestServer, - batchfile: Batchfile, + batchfile: batch::File, ) -> Etched { bitcoin_rpc_server.mine_blocks(1); @@ -252,13 +248,13 @@ fn batch( let reveal = inscribe.reveal; let parent = inscribe.inscriptions[0].id; - let Etch { + let batch::Etching { divisibility, premine, rune, symbol, mint, - } = batchfile.etch.unwrap(); + } = batchfile.etching.unwrap(); let mut mint_definition = Vec::::new(); @@ -344,7 +340,7 @@ fn batch( ), ); - let ord::wallet::inscribe::RuneInfo { + let batch::RuneInfo { destination, location, rune, diff --git a/tests/wallet/balance.rs b/tests/wallet/balance.rs index 90b2019ea4..bfc8e7ddc3 100644 --- a/tests/wallet/balance.rs +++ b/tests/wallet/balance.rs @@ -103,15 +103,15 @@ fn runic_utxos_are_deducted_from_cardinal() { batch( &bitcoin_rpc_server, &ord_rpc_server, - Batchfile { - etch: Some(Etch { + batch::File { + etching: Some(batch::Etching { divisibility: 0, mint: None, premine: "1000".parse().unwrap(), rune: SpacedRune { rune, spacers: 1 }, symbol: '¢', }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.jpeg".into(), ..Default::default() }], diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index c6c10d9c84..de9a505442 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -2633,8 +2633,8 @@ fn batch_inscribe_can_etch_rune() { let batch = batch( &bitcoin_rpc_server, &ord_rpc_server, - Batchfile { - etch: Some(Etch { + batch::File { + etching: Some(batch::Etching { divisibility: 0, rune: SpacedRune { rune: Rune(RUNE), @@ -2644,7 +2644,7 @@ fn batch_inscribe_can_etch_rune() { symbol: '¢', mint: None, }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.jpeg".into(), ..Default::default() }], @@ -2701,8 +2701,8 @@ fn etch_existing_rune_error() { .write("inscription.txt", "foo") .write( "batch.yaml", - serde_yaml::to_string(&Batchfile { - etch: Some(Etch { + serde_yaml::to_string(&batch::File { + etching: Some(batch::Etching { divisibility: 0, rune: SpacedRune { rune: Rune(RUNE), @@ -2712,7 +2712,7 @@ fn etch_existing_rune_error() { symbol: '¢', mint: None, }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.txt".into(), ..Default::default() }], @@ -2744,8 +2744,8 @@ fn etch_reserved_rune_error() { .write("inscription.txt", "foo") .write( "batch.yaml", - serde_yaml::to_string(&Batchfile { - etch: Some(Etch { + serde_yaml::to_string(&batch::File { + etching: Some(batch::Etching { divisibility: 0, rune: SpacedRune { rune: Rune::reserved(0), @@ -2755,7 +2755,7 @@ fn etch_reserved_rune_error() { symbol: '¢', mint: None, }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.txt".into(), ..Default::default() }], @@ -2787,8 +2787,8 @@ fn etch_sub_minimum_rune_error() { .write("inscription.txt", "foo") .write( "batch.yaml", - serde_yaml::to_string(&Batchfile { - etch: Some(Etch { + serde_yaml::to_string(&batch::File { + etching: Some(batch::Etching { divisibility: 0, rune: SpacedRune { rune: Rune(0), @@ -2798,7 +2798,7 @@ fn etch_sub_minimum_rune_error() { symbol: '¢', mint: None, }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.txt".into(), ..Default::default() }], @@ -2829,8 +2829,8 @@ fn etch_requires_rune_index() { .write("inscription.txt", "foo") .write( "batch.yaml", - serde_yaml::to_string(&Batchfile { - etch: Some(Etch { + serde_yaml::to_string(&batch::File { + etching: Some(batch::Etching { divisibility: 0, rune: SpacedRune { rune: Rune(RUNE), @@ -2840,7 +2840,7 @@ fn etch_requires_rune_index() { symbol: '¢', mint: None, }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.txt".into(), ..Default::default() }], @@ -2872,8 +2872,8 @@ fn etch_divisibility_over_maximum_error() { .write("inscription.txt", "foo") .write( "batch.yaml", - serde_yaml::to_string(&Batchfile { - etch: Some(Etch { + serde_yaml::to_string(&batch::File { + etching: Some(batch::Etching { divisibility: 39, rune: SpacedRune { rune: Rune(RUNE), @@ -2883,7 +2883,7 @@ fn etch_divisibility_over_maximum_error() { symbol: '¢', mint: None, }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.txt".into(), ..Default::default() }], diff --git a/tests/wallet/mint.rs b/tests/wallet/mint.rs index 83b15cbfd7..055c21404e 100644 --- a/tests/wallet/mint.rs +++ b/tests/wallet/mint.rs @@ -19,8 +19,8 @@ fn minting_rune_and_fails_if_after_end() { batch( &bitcoin_rpc_server, &ord_rpc_server, - Batchfile { - etch: Some(Etch { + batch::File { + etching: Some(batch::Etching { divisibility: 1, rune: SpacedRune { rune: Rune(RUNE), @@ -28,13 +28,13 @@ fn minting_rune_and_fails_if_after_end() { }, premine: "0".parse().unwrap(), symbol: '¢', - mint: Some(ord::wallet::inscribe::BatchMint { + mint: Some(batch::Mint { term: Some(2), limit: "111.1".parse().unwrap(), deadline: None, }), }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.jpeg".into(), ..Default::default() }], @@ -113,8 +113,8 @@ fn minting_rune_fails_if_not_mintable() { batch( &bitcoin_rpc_server, &ord_rpc_server, - Batchfile { - etch: Some(Etch { + batch::File { + etching: Some(batch::Etching { divisibility: 1, rune: SpacedRune { rune: Rune(RUNE), @@ -124,7 +124,7 @@ fn minting_rune_fails_if_not_mintable() { symbol: '¢', mint: None, }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.jpeg".into(), ..Default::default() }], @@ -160,19 +160,19 @@ fn minting_rune_fails_if_after_deadline() { batch( &bitcoin_rpc_server, &ord_rpc_server, - Batchfile { - etch: Some(Etch { + batch::File { + etching: Some(batch::Etching { divisibility: 1, rune: SpacedRune { rune, spacers: 0 }, premine: "0".parse().unwrap(), symbol: '¢', - mint: Some(ord::wallet::inscribe::BatchMint { + mint: Some(batch::Mint { term: Some(2), limit: "111.1".parse().unwrap(), deadline: Some(deadline), }), }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.jpeg".into(), ..Default::default() }], @@ -238,8 +238,8 @@ fn minting_rune_and_then_sending_works() { batch( &bitcoin_rpc_server, &ord_rpc_server, - Batchfile { - etch: Some(Etch { + batch::File { + etching: Some(batch::Etching { divisibility: 0, rune: SpacedRune { rune: Rune(RUNE), @@ -247,13 +247,13 @@ fn minting_rune_and_then_sending_works() { }, premine: "111".parse().unwrap(), symbol: '¢', - mint: Some(ord::wallet::inscribe::BatchMint { + mint: Some(batch::Mint { term: Some(10), limit: "21".parse().unwrap(), deadline: None, }), }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.jpeg".into(), ..Default::default() }], diff --git a/tests/wallet/selection.rs b/tests/wallet/selection.rs index d937995bc3..0a370524ea 100644 --- a/tests/wallet/selection.rs +++ b/tests/wallet/selection.rs @@ -120,8 +120,8 @@ fn mint_does_not_select_inscription() { batch( &bitcoin_rpc_server, &ord_rpc_server, - Batchfile { - etch: Some(Etch { + batch::File { + etching: Some(batch::Etching { divisibility: 1, rune: SpacedRune { rune: Rune(RUNE), @@ -129,13 +129,13 @@ fn mint_does_not_select_inscription() { }, premine: "1000".parse().unwrap(), symbol: '¢', - mint: Some(ord::wallet::inscribe::BatchMint { + mint: Some(batch::Mint { deadline: None, limit: "1000".parse().unwrap(), term: None, }), }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.jpeg".into(), ..Default::default() }], diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index d2bd42c837..bb4bee5708 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -881,15 +881,15 @@ fn sending_rune_with_divisibility_works() { batch( &bitcoin_rpc_server, &ord_rpc_server, - Batchfile { - etch: Some(Etch { + batch::File { + etching: Some(batch::Etching { divisibility: 1, rune: SpacedRune { rune, spacers: 0 }, premine: "1000".parse().unwrap(), symbol: '¢', mint: None, }), - inscriptions: vec![BatchEntry { + inscriptions: vec![batch::Entry { file: "inscription.jpeg".into(), ..Default::default() }],