From 7d4947efd9cad8179a507be086611ca21e1da99a Mon Sep 17 00:00:00 2001 From: onchainguy-eth <1436535+onchainguy-eth@users.noreply.github.com> Date: Mon, 1 Apr 2024 23:53:45 +0200 Subject: [PATCH] Do some cleanups --- src/index/updater/inscription_updater.rs | 2 - src/wallet/batch.rs | 44 ++++++++++++------- src/wallet/recipient.rs | 56 ------------------------ tests/wallet/send.rs | 24 +++++----- 4 files changed, 40 insertions(+), 86 deletions(-) delete mode 100644 src/wallet/recipient.rs diff --git a/src/index/updater/inscription_updater.rs b/src/index/updater/inscription_updater.rs index 60ba869a0c..9e62083c9a 100644 --- a/src/index/updater/inscription_updater.rs +++ b/src/index/updater/inscription_updater.rs @@ -409,8 +409,6 @@ impl<'a, 'tx> InscriptionUpdater<'a, 'tx> { .unwrap() .value(); - println!("is_burned {}", is_burned); - if is_burned { let entry = InscriptionEntry::load( self.sequence_number_to_entry diff --git a/src/wallet/batch.rs b/src/wallet/batch.rs index 9e8e71dc9a..7a8a18213f 100644 --- a/src/wallet/batch.rs +++ b/src/wallet/batch.rs @@ -77,7 +77,7 @@ mod tests { let utxos = vec![(outpoint(1), tx_out(20000, address()))]; let inscription = inscription("text/plain", "ord"); let commit_address = change(0); - let reveal_address = recipient(); + let reveal_address = recipient_as_address(); let reveal_change = [commit_address, change(1)]; let batch::Transactions { @@ -123,7 +123,7 @@ mod tests { let utxos = vec![(outpoint(1), tx_out(20000, address()))]; let inscription = inscription("text/plain", "ord"); let commit_address = change(0); - let reveal_address = recipient(); + let reveal_address = recipient_as_address(); let reveal_change = [commit_address, change(1)]; let batch::Transactions { @@ -173,7 +173,7 @@ mod tests { let inscription = inscription("text/plain", "ord"); let satpoint = None; let commit_address = change(0); - let reveal_address = recipient(); + let reveal_address = recipient_as_address(); let error = batch::Plan { satpoint, @@ -225,7 +225,7 @@ mod tests { let inscription = inscription("text/plain", "ord"); let satpoint = None; let commit_address = change(0); - let reveal_address = recipient(); + let reveal_address = recipient_as_address(); assert!(batch::Plan { satpoint, @@ -270,7 +270,7 @@ mod tests { let inscription = inscription("text/plain", "ord"); let satpoint = None; let commit_address = change(0); - let reveal_address = recipient(); + let reveal_address = recipient_as_address(); let fee_rate = 3.3; let batch::Transactions { @@ -358,7 +358,7 @@ mod tests { .into(); let commit_address = change(1); - let reveal_address = recipient(); + let reveal_address = recipient_as_address(); let fee_rate = 4.0; let batch::Transactions { @@ -444,7 +444,7 @@ mod tests { let inscription = inscription("text/plain", "ord"); let satpoint = None; let commit_address = change(0); - let reveal_address = recipient(); + let reveal_address = recipient_as_address(); let commit_fee_rate = 3.3; let fee_rate = 1.0; @@ -509,7 +509,7 @@ mod tests { let inscription = inscription("text/plain", [0; MAX_STANDARD_TX_WEIGHT as usize]); let satpoint = None; let commit_address = change(0); - let reveal_address = recipient(); + let reveal_address = recipient_as_address(); let error = batch::Plan { satpoint, @@ -550,7 +550,7 @@ mod tests { let inscription = inscription("text/plain", [0; MAX_STANDARD_TX_WEIGHT as usize]); let satpoint = None; let commit_address = change(0); - let reveal_address = recipient(); + let reveal_address = recipient_as_address(); let batch::Transactions { reveal_tx, .. } = batch::Plan { satpoint, @@ -605,7 +605,7 @@ mod tests { wallet_inscriptions.insert(parent_info.location, vec![parent]); let commit_address = change(1); - let reveal_addresses = vec![recipient()]; + let reveal_addresses = vec![recipient_as_address()]; let inscriptions = vec![ InscriptionTemplate { @@ -718,7 +718,11 @@ mod tests { wallet_inscriptions.insert(parent_info.location, vec![parent]); let commit_address = change(1); - let reveal_addresses = vec![recipient(), recipient(), recipient()]; + let reveal_addresses = vec![ + recipient_as_address(), + recipient_as_address(), + recipient_as_address() + ]; let inscriptions = vec![ InscriptionTemplate { @@ -860,7 +864,7 @@ mod tests { ]; let commit_address = change(1); - let reveal_addresses = vec![recipient()]; + let reveal_addresses = vec![recipient_as_address()]; let error = batch::Plan { satpoint: None, @@ -937,7 +941,7 @@ mod tests { ]; let commit_address = change(1); - let reveal_addresses = vec![recipient(), recipient()]; + let reveal_addresses = vec![recipient_as_address(), recipient_as_address()]; let _ = batch::Plan { satpoint: None, @@ -976,7 +980,7 @@ mod tests { ]; let commit_address = change(1); - let reveal_addresses = vec![recipient()]; + let reveal_addresses = vec![recipient_as_address()]; let error = batch::Plan { satpoint: None, @@ -1020,7 +1024,11 @@ mod tests { let wallet_inscriptions = BTreeMap::new(); let commit_address = change(1); - let reveal_addresses = vec![recipient(), recipient(), recipient()]; + let reveal_addresses = vec![ + recipient_as_address(), + recipient_as_address(), + recipient_as_address() + ]; let inscriptions = vec![ inscription("text/plain", [b'O'; 100]), @@ -1089,7 +1097,11 @@ mod tests { wallet_inscriptions.insert(parent_info.location, vec![parent]); let commit_address = change(1); - let reveal_addresses = vec![recipient(), recipient(), recipient()]; + let reveal_addresses = vec![ + recipient_as_address(), + recipient_as_address(), + recipient_as_address() + ]; let inscriptions = vec![ InscriptionTemplate { diff --git a/src/wallet/recipient.rs b/src/wallet/recipient.rs deleted file mode 100644 index 2a960ae810..0000000000 --- a/src/wallet/recipient.rs +++ /dev/null @@ -1,56 +0,0 @@ -use rustls_acme::acme::AuthStatus::Invalid; -use super::*; - -#[derive(Debug, PartialEq)] -pub(crate) enum RecipientError { - InvalidRecipient -} - -impl Display for RecipientError { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - match self { - RecipientError::InvalidRecipient => { - write!(f, "Invalid recipient") - } - } - } -} - -impl std::error::Error for RecipientError {} - -#[derive(Clone, Debug, PartialEq)] -pub(crate) enum Recipient { - Address(Address), - ScriptBuf(ScriptBuf), -} - -trait ScriptPubkey { - fn script_pubkey(&self) -> ScriptBuf; -} - -impl ScriptPubkey for Address { - fn script_pubkey(&self) -> ScriptBuf { - self.script_pubkey() - } -} - -impl ScriptPubkey for ScriptBuf { - fn script_pubkey(&self) -> ScriptBuf { - self.clone() - } -} - -impl Recipient { - pub fn to_address(&self) -> Result
{ - match self { - Recipient::Address(address) => Ok(address.clone()), - _ => Err(anyhow!(RecipientError::InvalidRecipient)), - } - } - pub fn script_pubkey(&self) -> ScriptBuf { - match self { - Recipient::Address(address) => address.script_pubkey(), - Recipient::ScriptBuf(script_buf) => script_buf.script_pubkey(), - } - } -} \ No newline at end of file diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index ec192d1520..59d80f194c 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -49,34 +49,34 @@ fn inscriptions_can_be_sent() { #[test] fn inscriptions_can_be_burned() { - let bitcoin_rpc_server = test_bitcoincore_rpc::spawn(); + let core = mockcore::spawn(); - let ord_rpc_server = TestServer::spawn_with_server_args(&bitcoin_rpc_server, &[], &[]); + let ord = TestServer::spawn_with_server_args(&core, &[], &[]); - create_wallet(&bitcoin_rpc_server, &ord_rpc_server); + create_wallet(&core, &ord); - bitcoin_rpc_server.mine_blocks(1); + core.mine_blocks(1); - let (inscription, _) = inscribe(&bitcoin_rpc_server, &ord_rpc_server); + let (inscription, _) = inscribe(&core, &ord); - bitcoin_rpc_server.mine_blocks(1); + core.mine_blocks(1); let output = CommandBuilder::new(format!( "wallet send --fee-rate 1 burn {inscription}", )) - .bitcoin_rpc_server(&bitcoin_rpc_server) - .ord_rpc_server(&ord_rpc_server) + .core(&core) + .ord(&ord) .stdout_regex(r".*") - .run_and_deserialize_output::(); + .run_and_deserialize_output::(); - let txid = bitcoin_rpc_server.mempool()[0].txid(); + let txid = core.mempool()[0].txid(); assert_eq!(txid, output.txid); - bitcoin_rpc_server.mine_blocks(1); + core.mine_blocks(1); let send_txid = output.txid; - ord_rpc_server.assert_response_regex( + ord.assert_response_regex( format!("/inscription/{inscription}"), format!( ".*

Inscription 0

.*
.*