From 7b75c684068e8a4781e03dfbd5a48b95c2ceba0a Mon Sep 17 00:00:00 2001 From: Illia Kripaka Date: Wed, 18 Mar 2026 17:01:00 +0200 Subject: [PATCH 1/2] Add cargo clippy ci entry --- .github/workflows/ci.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23971f4..d13cd8d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -113,6 +113,30 @@ jobs: with: command: check bans licenses sources + clippy: + runs-on: ubuntu-latest + timeout-minutes: 30 + permissions: + contents: read + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + persist-credentials: false + submodules: true + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + components: clippy + - uses: Swatinem/rust-cache@v2 + + - name: Run clippy checks + run: cargo clippy --workspace --all-targets --all-features + env: + RUSTFLAGS: -Dwarnings + ci-success: runs-on: ubuntu-latest if: always() @@ -120,6 +144,7 @@ jobs: - rust-tests - rustfmt - crate-checks + - clippy - deny timeout-minutes: 30 steps: From 92e7a182b92026309f17a99205d9b4133f67d599 Mon Sep 17 00:00:00 2001 From: Illia Kripaka Date: Wed, 18 Mar 2026 19:09:07 +0200 Subject: [PATCH 2/2] Minor code fixes --- crates/build/src/generator.rs | 10 ++- .../build/src/macros/{macros.rs => core.rs} | 0 crates/build/src/macros/mod.rs | 4 +- crates/build/src/resolver.rs | 7 +- crates/cli/src/cli.rs | 2 +- .../cli/src/commands/{commands.rs => core.rs} | 0 crates/cli/src/commands/mod.rs | 4 +- crates/cli/src/commands/regtest.rs | 2 +- crates/cli/src/commands/test.rs | 6 +- crates/cli/src/config/{config.rs => core.rs} | 0 crates/cli/src/config/mod.rs | 4 +- crates/regtest/src/client.rs | 10 ++- crates/regtest/src/regtest.rs | 2 +- .../sdk/src/program/{program.rs => core.rs} | 10 +-- crates/sdk/src/program/mod.rs | 4 +- .../sdk/src/provider/{provider.rs => core.rs} | 0 crates/sdk/src/provider/esplora.rs | 23 +++---- crates/sdk/src/provider/mod.rs | 4 +- crates/sdk/src/provider/rpc/elements.rs | 6 +- crates/sdk/src/provider/simplex.rs | 12 ++-- crates/sdk/src/signer/{signer.rs => core.rs} | 55 +++++++-------- crates/sdk/src/signer/mod.rs | 4 +- .../sdk/src/transaction/final_transaction.rs | 68 ++++++++----------- crates/sdk/src/transaction/partial_input.rs | 51 +++++++------- crates/sdk/src/transaction/partial_output.rs | 6 +- crates/simplex/tests/compile_test.rs | 2 +- crates/test/src/config.rs | 4 +- crates/test/src/context.rs | 12 ++-- crates/test/src/macros/{macros.rs => core.rs} | 0 crates/test/src/macros/mod.rs | 4 +- 30 files changed, 143 insertions(+), 173 deletions(-) rename crates/build/src/macros/{macros.rs => core.rs} (100%) rename crates/cli/src/commands/{commands.rs => core.rs} (100%) rename crates/cli/src/config/{config.rs => core.rs} (100%) rename crates/sdk/src/program/{program.rs => core.rs} (96%) rename crates/sdk/src/provider/{provider.rs => core.rs} (100%) rename crates/sdk/src/signer/{signer.rs => core.rs} (90%) rename crates/test/src/macros/{macros.rs => core.rs} (100%) diff --git a/crates/build/src/generator.rs b/crates/build/src/generator.rs index 484d57b..317fcac 100644 --- a/crates/build/src/generator.rs +++ b/crates/build/src/generator.rs @@ -79,14 +79,14 @@ impl ArtifactsGenerator { fn generate_bindings(out_dir: &Path, path_tree: TreeNode) -> Result, BuildError> { fs::create_dir_all(out_dir)?; - let mut mod_filenames = Self::generate_simfs(&out_dir, &path_tree.files)?; + let mut mod_filenames = Self::generate_simfs(out_dir, &path_tree.files)?; for (dir_name, tree_node) in path_tree.dirs.into_iter() { Self::generate_bindings(&out_dir.join(&dir_name), tree_node)?; mod_filenames.push(dir_name); } - Self::generate_mod_rs(&out_dir, &mod_filenames)?; + Self::generate_mod_rs(out_dir, &mod_filenames)?; Ok(mod_filenames) } @@ -156,10 +156,8 @@ impl ArtifactsGenerator { let include_simf_source_const = convert_contract_name_to_contract_source_const(contract_name); let include_simf_module = convert_contract_name_to_contract_module(contract_name); - let pathdiff = pathdiff::diff_paths(&simf_file, &cwd).ok_or(BuildError::FailedToFindCorrectRelativePath { - cwd: cwd, - simf_file: simf_file, - })?; + let pathdiff = pathdiff::diff_paths(&simf_file, &cwd) + .ok_or(BuildError::FailedToFindCorrectRelativePath { cwd, simf_file })?; let pathdiff = pathdiff.to_string_lossy().into_owned(); let code = quote! { diff --git a/crates/build/src/macros/macros.rs b/crates/build/src/macros/core.rs similarity index 100% rename from crates/build/src/macros/macros.rs rename to crates/build/src/macros/core.rs diff --git a/crates/build/src/macros/mod.rs b/crates/build/src/macros/mod.rs index 62e9c9f..c22c745 100644 --- a/crates/build/src/macros/mod.rs +++ b/crates/build/src/macros/mod.rs @@ -1,7 +1,7 @@ pub mod codegen; -pub mod macros; +mod core; pub mod parse; pub mod program; pub mod types; -pub use macros::expand; +pub use core::expand; diff --git a/crates/build/src/resolver.rs b/crates/build/src/resolver.rs index 4051d0d..18c9286 100644 --- a/crates/build/src/resolver.rs +++ b/crates/build/src/resolver.rs @@ -8,17 +8,16 @@ use super::error::BuildError; pub struct ArtifactsResolver {} impl ArtifactsResolver { - pub fn resolve_files_to_build(src_dir: &String, simfs: &Vec) -> Result, BuildError> { + pub fn resolve_files_to_build(src_dir: &String, simfs: &[String]) -> Result, BuildError> { let cwd = env::current_dir()?; let base = cwd.join(src_dir); let mut paths = Vec::new(); - let walker = globwalk::GlobWalkerBuilder::from_patterns(base, &simfs) + let walker = globwalk::GlobWalkerBuilder::from_patterns(base, simfs) .follow_links(true) .file_type(FileType::FILE) .build()? - .into_iter() .filter_map(Result::ok); for img in walker { @@ -34,7 +33,7 @@ impl ArtifactsResolver { if !path_outer.is_absolute() { let manifest_dir = env::current_dir()?; - let mut path_local = PathBuf::from(manifest_dir); + let mut path_local = manifest_dir; path_local.push(path_outer); path_outer = path_local; diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index 7194c75..09a98a5 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -2,8 +2,8 @@ use std::path::PathBuf; use clap::Parser; +use crate::commands::Command; use crate::commands::build::Build; -use crate::commands::commands::Command; use crate::commands::regtest::Regtest; use crate::commands::test::Test; use crate::config::{Config, INIT_CONFIG}; diff --git a/crates/cli/src/commands/commands.rs b/crates/cli/src/commands/core.rs similarity index 100% rename from crates/cli/src/commands/commands.rs rename to crates/cli/src/commands/core.rs diff --git a/crates/cli/src/commands/mod.rs b/crates/cli/src/commands/mod.rs index c8bc2d7..ff3c5ed 100644 --- a/crates/cli/src/commands/mod.rs +++ b/crates/cli/src/commands/mod.rs @@ -1,5 +1,7 @@ pub mod build; -pub mod commands; +mod core; pub mod error; pub mod regtest; pub mod test; + +pub use core::*; diff --git a/crates/cli/src/commands/regtest.rs b/crates/cli/src/commands/regtest.rs index 5e01c1b..4c44eea 100644 --- a/crates/cli/src/commands/regtest.rs +++ b/crates/cli/src/commands/regtest.rs @@ -10,7 +10,7 @@ pub struct Regtest {} impl Regtest { pub fn run(config: RegtestConfig) -> Result<(), CommandError> { - let (mut client, signer) = RegtestRunner::new(config)?; + let (mut client, signer) = RegtestRunner::from_config(config)?; let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); diff --git a/crates/cli/src/commands/test.rs b/crates/cli/src/commands/test.rs index 2fdbe35..05adaf5 100644 --- a/crates/cli/src/commands/test.rs +++ b/crates/cli/src/commands/test.rs @@ -3,7 +3,7 @@ use std::process::Stdio; use smplx_test::TestConfig; -use super::commands::{TestCommand, TestFlags}; +use super::core::{TestCommand, TestFlags}; use super::error::CommandError; pub struct Test {} @@ -40,7 +40,7 @@ impl Test { TestCommand::Integration { additional_flags } => { command_as_arg.push_str("cargo test --tests"); - let flag_args = Self::build_test_flags(&additional_flags); + let flag_args = Self::build_test_flags(additional_flags); if !flag_args.is_empty() { command_as_arg.push_str(" --"); @@ -64,7 +64,7 @@ impl Test { command_as_arg.push_str(&arg); } - let flag_args = Self::build_test_flags(&additional_flags); + let flag_args = Self::build_test_flags(additional_flags); if !flag_args.is_empty() { command_as_arg.push_str(" --"); diff --git a/crates/cli/src/config/config.rs b/crates/cli/src/config/core.rs similarity index 100% rename from crates/cli/src/config/config.rs rename to crates/cli/src/config/core.rs diff --git a/crates/cli/src/config/mod.rs b/crates/cli/src/config/mod.rs index 8557703..067f356 100644 --- a/crates/cli/src/config/mod.rs +++ b/crates/cli/src/config/mod.rs @@ -1,4 +1,4 @@ -pub mod config; +mod core; pub mod error; -pub use config::{Config, INIT_CONFIG}; +pub use core::{CONFIG_FILENAME, Config, INIT_CONFIG}; diff --git a/crates/regtest/src/client.rs b/crates/regtest/src/client.rs index af4589b..79bc003 100644 --- a/crates/regtest/src/client.rs +++ b/crates/regtest/src/client.rs @@ -15,17 +15,15 @@ pub struct RegtestClient { } impl RegtestClient { - // TODO: pass custom config + // TODO: pass custom config, remove clippy tag + #[allow(clippy::new_without_default)] pub fn new() -> Self { let (electrs_path, elementsd_path) = Self::default_bin_paths(); let zmq_addr = Self::get_zmq_addr(); let elements = Self::create_bitcoind_node(elementsd_path, &zmq_addr); let electrs = Self::create_electrs_node(electrs_path, &elements, &zmq_addr); - Self { - electrs: electrs, - elements: elements, - } + Self { electrs, elements } } pub fn default_bin_paths() -> (PathBuf, PathBuf) { @@ -97,6 +95,6 @@ impl RegtestClient { conf.http_enabled = true; conf.network = "liquidregtest"; - ElectrsD::with_conf(bin_path.as_ref(), &elementsd, &conf).unwrap() + ElectrsD::with_conf(bin_path.as_ref(), elementsd, &conf).unwrap() } } diff --git a/crates/regtest/src/regtest.rs b/crates/regtest/src/regtest.rs index 789945d..e53dfc3 100644 --- a/crates/regtest/src/regtest.rs +++ b/crates/regtest/src/regtest.rs @@ -12,7 +12,7 @@ use super::error::RegtestError; pub struct Regtest {} impl Regtest { - pub fn new(config: RegtestConfig) -> Result<(RegtestClient, Signer), RegtestError> { + pub fn from_config(config: RegtestConfig) -> Result<(RegtestClient, Signer), RegtestError> { let client = RegtestClient::new(); let provider = Box::new(SimplexProvider::new( diff --git a/crates/sdk/src/program/program.rs b/crates/sdk/src/program/core.rs similarity index 96% rename from crates/sdk/src/program/program.rs rename to crates/sdk/src/program/core.rs index 24b2daa..9aea929 100644 --- a/crates/sdk/src/program/program.rs +++ b/crates/sdk/src/program/core.rs @@ -71,7 +71,7 @@ impl ProgramTrait for Program { } let target_utxo = &utxos[input_index]; - let script_pubkey = self.get_tr_address(&network)?.script_pubkey(); + let script_pubkey = self.get_tr_address(network)?.script_pubkey(); if target_utxo.script_pubkey != script_pubkey { return Err(ProgramError::ScriptPubkeyMismatch { @@ -129,7 +129,7 @@ impl ProgramTrait for Program { input_index: usize, network: &SimplicityNetwork, ) -> Result>, ProgramError> { - let pruned = self.execute(&pst, witness, input_index, network)?.0; + let pruned = self.execute(pst, witness, input_index, network)?.0; let (simplicity_program_bytes, simplicity_witness_bytes) = pruned.to_vec_with_witness(); let cmr = pruned.cmr(); @@ -146,9 +146,9 @@ impl ProgramTrait for Program { impl Program { pub fn new(source: &'static str, pub_key: XOnlyPublicKey, arguments: Box) -> Self { Self { - source: source, - pub_key: pub_key, - arguments: arguments, + source, + pub_key, + arguments, } } diff --git a/crates/sdk/src/program/mod.rs b/crates/sdk/src/program/mod.rs index 7d924e5..ca596cd 100644 --- a/crates/sdk/src/program/mod.rs +++ b/crates/sdk/src/program/mod.rs @@ -1,9 +1,9 @@ pub mod arguments; +mod core; pub mod error; -pub mod program; pub mod witness; pub use arguments::ArgumentsTrait; +pub use core::{Program, ProgramTrait}; pub use error::ProgramError; -pub use program::{Program, ProgramTrait}; pub use witness::WitnessTrait; diff --git a/crates/sdk/src/provider/provider.rs b/crates/sdk/src/provider/core.rs similarity index 100% rename from crates/sdk/src/provider/provider.rs rename to crates/sdk/src/provider/core.rs diff --git a/crates/sdk/src/provider/esplora.rs b/crates/sdk/src/provider/esplora.rs index fbe640d..856e67e 100644 --- a/crates/sdk/src/provider/esplora.rs +++ b/crates/sdk/src/provider/esplora.rs @@ -12,8 +12,8 @@ use serde::Deserialize; use crate::provider::SimplicityNetwork; +use super::core::{DEFAULT_ESPLORA_TIMEOUT_SECS, ProviderTrait}; use super::error::ProviderError; -use super::provider::{DEFAULT_ESPLORA_TIMEOUT_SECS, ProviderTrait}; pub struct EsploraProvider { pub esplora_url: String, @@ -53,7 +53,7 @@ impl EsploraProvider { pub fn new(url: String, network: SimplicityNetwork) -> Self { Self { esplora_url: url, - network: network, + network, timeout: Duration::from_secs(DEFAULT_ESPLORA_TIMEOUT_SECS), } } @@ -64,11 +64,8 @@ impl EsploraProvider { Ok(OutPoint::new(txid, utxo.vout)) } - fn populate_txouts_from_outpoints( - &self, - outpoints: &Vec, - ) -> Result, ProviderError> { - let set: HashSet<_> = outpoints.into_iter().collect(); + fn populate_txouts_from_outpoints(&self, outpoints: &[OutPoint]) -> Result, ProviderError> { + let set: HashSet<_> = outpoints.iter().collect(); let mut map = HashMap::new(); // filter unique transactions @@ -117,14 +114,14 @@ impl ProviderTrait for EsploraProvider { }); } - Ok(Txid::from_str(&body).map_err(|e| ProviderError::InvalidTxid(e.to_string()))?) + Txid::from_str(&body).map_err(|e| ProviderError::InvalidTxid(e.to_string())) } fn wait(&self, txid: &Txid) -> Result<(), ProviderError> { let url = format!("{}/tx/{}/status", self.esplora_url, txid); let timeout_secs = self.timeout.as_secs(); - let confirmation_poll = match self.network.clone() { + let confirmation_poll = match self.network { SimplicityNetwork::ElementsRegtest { .. } => Duration::from_millis(100), _ => Duration::from_secs(10), }; @@ -194,10 +191,10 @@ impl ProviderTrait for EsploraProvider { let utxos: Vec = response.json().map_err(|e| ProviderError::Deserialize(e.to_string()))?; let outpoints = utxos .iter() - .map(|utxo| Ok(self.esplora_utxo_to_outpoint(&utxo)?)) + .map(|utxo| self.esplora_utxo_to_outpoint(utxo)) .collect::, ProviderError>>()?; - Ok(self.populate_txouts_from_outpoints(&outpoints)?) + self.populate_txouts_from_outpoints(&outpoints) } fn fetch_scripthash_utxos(&self, script: &Script) -> Result, ProviderError> { @@ -223,10 +220,10 @@ impl ProviderTrait for EsploraProvider { let utxos: Vec = response.json().map_err(|e| ProviderError::Deserialize(e.to_string()))?; let outpoints = utxos .iter() - .map(|utxo| Ok(self.esplora_utxo_to_outpoint(&utxo)?)) + .map(|utxo| self.esplora_utxo_to_outpoint(utxo)) .collect::, ProviderError>>()?; - Ok(self.populate_txouts_from_outpoints(&outpoints)?) + self.populate_txouts_from_outpoints(&outpoints) } fn fetch_fee_estimates(&self) -> Result, ProviderError> { diff --git a/crates/sdk/src/provider/mod.rs b/crates/sdk/src/provider/mod.rs index b369c8c..85838e4 100644 --- a/crates/sdk/src/provider/mod.rs +++ b/crates/sdk/src/provider/mod.rs @@ -1,12 +1,12 @@ +mod core; pub mod error; pub mod esplora; pub mod network; -pub mod provider; pub mod rpc; pub mod simplex; +pub use core::ProviderTrait; pub use esplora::EsploraProvider; -pub use provider::ProviderTrait; pub use rpc::elements::ElementsRpc; pub use simplex::SimplexProvider; diff --git a/crates/sdk/src/provider/rpc/elements.rs b/crates/sdk/src/provider/rpc/elements.rs index 1a7437e..93140e2 100644 --- a/crates/sdk/src/provider/rpc/elements.rs +++ b/crates/sdk/src/provider/rpc/elements.rs @@ -21,11 +21,7 @@ impl ElementsRpc { let inner = Client::new(url.as_str(), auth.clone())?; inner.ping()?; - Ok(Self { - inner: inner, - auth: auth, - url: url, - }) + Ok(Self { inner, auth, url }) } pub fn height(&self) -> Result { diff --git a/crates/sdk/src/provider/simplex.rs b/crates/sdk/src/provider/simplex.rs index 2fab759..52e8b8d 100644 --- a/crates/sdk/src/provider/simplex.rs +++ b/crates/sdk/src/provider/simplex.rs @@ -6,8 +6,8 @@ use simplicityhl::elements::{Address, OutPoint, Script, Transaction, TxOut, Txid use crate::provider::SimplicityNetwork; +use super::core::ProviderTrait; use super::error::ProviderError; -use super::provider::ProviderTrait; use super::{ElementsRpc, EsploraProvider}; @@ -44,22 +44,22 @@ impl ProviderTrait for SimplexProvider { } fn wait(&self, txid: &Txid) -> Result<(), ProviderError> { - Ok(self.esplora.wait(txid)?) + self.esplora.wait(txid) } fn fetch_transaction(&self, txid: &Txid) -> Result { - Ok(self.esplora.fetch_transaction(txid)?) + self.esplora.fetch_transaction(txid) } fn fetch_address_utxos(&self, address: &Address) -> Result, ProviderError> { - Ok(self.esplora.fetch_address_utxos(address)?) + self.esplora.fetch_address_utxos(address) } fn fetch_scripthash_utxos(&self, script: &Script) -> Result, ProviderError> { - Ok(self.esplora.fetch_scripthash_utxos(script)?) + self.esplora.fetch_scripthash_utxos(script) } fn fetch_fee_estimates(&self) -> Result, ProviderError> { - Ok(self.esplora.fetch_fee_estimates()?) + self.esplora.fetch_fee_estimates() } } diff --git a/crates/sdk/src/signer/signer.rs b/crates/sdk/src/signer/core.rs similarity index 90% rename from crates/sdk/src/signer/signer.rs rename to crates/sdk/src/signer/core.rs index 532854b..427f6b2 100644 --- a/crates/sdk/src/signer/signer.rs +++ b/crates/sdk/src/signer/core.rs @@ -44,7 +44,7 @@ pub trait SignerTrait { fn sign_program( &self, pst: &PartiallySignedTransaction, - program: &Box, + program: &dyn ProgramTrait, input_index: usize, network: &SimplicityNetwork, ) -> Result; @@ -67,11 +67,11 @@ impl SignerTrait for Signer { fn sign_program( &self, pst: &PartiallySignedTransaction, - program: &Box, + program: &dyn ProgramTrait, input_index: usize, network: &SimplicityNetwork, ) -> Result { - let env = program.get_env(&pst, input_index, network)?; + let env = program.get_env(pst, input_index, network)?; let msg = Message::from_digest(env.c_tx_env().sighash_all().to_byte_array()); let private_key = self.get_private_key()?; @@ -117,13 +117,13 @@ impl Signer { let seed = mnemonic.to_seed(""); let xprv = Xpriv::new_master(NetworkKind::Test, &seed)?; - let network = provider.get_network().clone(); + let network = *provider.get_network(); Ok(Self { xprv, - provider: provider, - network: network, - secp: secp, + provider, + network, + secp, }) } @@ -133,7 +133,7 @@ impl Signer { for input in tx.inputs() { set.insert(OutPoint { - txid: input.partial_input.witness_txid.clone(), + txid: input.partial_input.witness_txid, vout: input.partial_input.witness_output_index, }); } @@ -192,8 +192,8 @@ impl Signer { } } - pub fn get_provider(&self) -> &Box { - &self.provider + pub fn get_provider(&self) -> &dyn ProviderTrait { + self.provider.as_ref() } pub fn get_wpkh_address(&self) -> Result { @@ -291,32 +291,29 @@ impl Signer { // finalize the tx with fee and without the change let final_tx = self.sign_tx(&fee_tx)?; - return Ok(Estimate::Success(final_tx, fee)); + Ok(Estimate::Success(final_tx, fee)) } fn sign_tx(&self, tx: &FinalTransaction) -> Result { let mut pst = tx.extract_pst(); let inputs = tx.inputs(); - for index in 0..inputs.len() { - let input = inputs[index].clone(); - + for (index, input_i) in inputs.iter().enumerate() { // we need to prune the program - if input.program_input.is_some() { - let program = input.program_input.unwrap(); - let signed_witness: Result = match input.required_sig { + if let Some(program_input) = &input_i.program_input { + let signed_witness: Result = match &input_i.required_sig { // sign the program and insert the signature into the witness RequiredSignature::Witness(witness_name) => Ok(self.get_signed_program_witness( &pst, - &program.program, - &program.witness.build_witness(), - &witness_name, + program_input.program.as_ref(), + &program_input.witness.build_witness(), + witness_name, index, )?), // just build the passed witness - _ => Ok(program.witness.build_witness()), + _ => Ok(program_input.witness.build_witness()), }; - let pruned_witness = program + let pruned_witness = program_input .program .finalize(&pst, &signed_witness.unwrap(), index, &self.network) .unwrap(); @@ -338,9 +335,9 @@ impl Signer { fn get_signed_program_witness( &self, pst: &PartiallySignedTransaction, - program: &Box, + program: &dyn ProgramTrait, witness: &WitnessValues, - witness_name: &String, + witness_name: &str, index: usize, ) -> Result { let signature = self.sign_program(pst, program, index, &self.network)?; @@ -352,7 +349,7 @@ impl Signer { }); hm.insert( - WitnessName::from_str_unchecked(witness_name.as_str()), + WitnessName::from_str_unchecked(witness_name), Value::byte_array(signature.serialize()), ); @@ -364,7 +361,7 @@ impl Signer { } fn master_xpriv(&self) -> Result { - Ok(self.derive_xpriv(&DerivationPath::master())?) + self.derive_xpriv(&DerivationPath::master()) } fn derive_xpub(&self, path: &DerivationPath) -> Result { @@ -374,7 +371,7 @@ impl Signer { } fn master_xpub(&self) -> Result { - Ok(self.derive_xpub(&DerivationPath::master())?) + self.derive_xpub(&DerivationPath::master()) } fn fingerprint(&self) -> Result { @@ -385,7 +382,7 @@ impl Signer { let coin_type = if self.network.is_mainnet() { 1776 } else { 1 }; let path = format!("84h/{coin_type}h/0h"); - Ok(DerivationPath::from_str(&format!("m/{path}")).map_err(|e| SignerError::DerivationPath(e.to_string()))?) + DerivationPath::from_str(&format!("m/{path}")).map_err(|e| SignerError::DerivationPath(e.to_string())) } } @@ -402,7 +399,7 @@ mod tests { let signer = Signer::new( "exist carry drive collect lend cereal occur much tiger just involve mean", - Box::new(EsploraProvider::new(url, network.clone())), + Box::new(EsploraProvider::new(url, network)), ) .unwrap(); diff --git a/crates/sdk/src/signer/mod.rs b/crates/sdk/src/signer/mod.rs index ae3f09a..e93c3a4 100644 --- a/crates/sdk/src/signer/mod.rs +++ b/crates/sdk/src/signer/mod.rs @@ -1,5 +1,5 @@ +mod core; pub mod error; -pub mod signer; +pub use core::{Signer, SignerTrait}; pub use error::SignerError; -pub use signer::{Signer, SignerTrait}; diff --git a/crates/sdk/src/transaction/final_transaction.rs b/crates/sdk/src/transaction/final_transaction.rs index 2680bce..5150ccd 100644 --- a/crates/sdk/src/transaction/final_transaction.rs +++ b/crates/sdk/src/transaction/final_transaction.rs @@ -28,7 +28,7 @@ pub struct FinalTransaction { impl FinalTransaction { pub fn new(network: SimplicityNetwork) -> Self { Self { - network: network, + network, inputs: Vec::new(), outputs: Vec::new(), } @@ -39,20 +39,17 @@ impl FinalTransaction { partial_input: PartialInput, required_sig: RequiredSignature, ) -> Result<(), TransactionError> { - match required_sig { - RequiredSignature::Witness(_) => { - return Err(TransactionError::SignatureRequest( - "Requested signature is not NativeEcdsa or None".to_string(), - )); - } - _ => {} + if let RequiredSignature::Witness(_) = required_sig { + return Err(TransactionError::SignatureRequest( + "Requested signature is not NativeEcdsa or None".to_string(), + )); } self.inputs.push(FinalInput { - partial_input: partial_input, + partial_input, program_input: None, issuance_input: None, - required_sig: required_sig, + required_sig, }); Ok(()) @@ -64,20 +61,17 @@ impl FinalTransaction { program_input: ProgramInput, required_sig: RequiredSignature, ) -> Result<(), TransactionError> { - match required_sig { - RequiredSignature::NativeEcdsa => { - return Err(TransactionError::SignatureRequest( - "Requested signature is not Witness or None".to_string(), - )); - } - _ => {} + if let RequiredSignature::NativeEcdsa = required_sig { + return Err(TransactionError::SignatureRequest( + "Requested signature is not Witness or None".to_string(), + )); } self.inputs.push(FinalInput { - partial_input: partial_input, + partial_input, program_input: Some(program_input), issuance_input: None, - required_sig: required_sig, + required_sig, }); Ok(()) @@ -89,22 +83,19 @@ impl FinalTransaction { issuance_input: IssuanceInput, required_sig: RequiredSignature, ) -> Result { - match required_sig { - RequiredSignature::Witness(_) => { - return Err(TransactionError::SignatureRequest( - "Requested signature is not NativeEcdsa or None".to_string(), - )); - } - _ => {} + if let RequiredSignature::Witness(_) = required_sig { + return Err(TransactionError::SignatureRequest( + "Requested signature is not NativeEcdsa or None".to_string(), + )); } let asset_id = AssetId::from_entropy(asset_entropy(&partial_input.outpoint(), issuance_input.asset_entropy)); self.inputs.push(FinalInput { - partial_input: partial_input, + partial_input, program_input: None, issuance_input: Some(issuance_input), - required_sig: required_sig, + required_sig, }); Ok(asset_id) @@ -117,22 +108,19 @@ impl FinalTransaction { issuance_input: IssuanceInput, required_sig: RequiredSignature, ) -> Result { - match required_sig { - RequiredSignature::NativeEcdsa => { - return Err(TransactionError::SignatureRequest( - "Requested signature is not Witness or None".to_string(), - )); - } - _ => {} + if let RequiredSignature::NativeEcdsa = required_sig { + return Err(TransactionError::SignatureRequest( + "Requested signature is not Witness or None".to_string(), + )); } let asset_id = AssetId::from_entropy(asset_entropy(&partial_input.outpoint(), issuance_input.asset_entropy)); self.inputs.push(FinalInput { - partial_input: partial_input, + partial_input, program_input: Some(program_input), issuance_input: Some(issuance_input), - required_sig: required_sig, + required_sig, }); Ok(asset_id) @@ -186,14 +174,14 @@ impl FinalTransaction { let available_amount = self .inputs .iter() - .filter(|input| input.partial_input.asset.clone().unwrap() == self.network.policy_asset()) - .fold(0 as u64, |acc, input| acc + input.partial_input.amount.clone().unwrap()); + .filter(|input| input.partial_input.asset.unwrap() == self.network.policy_asset()) + .fold(0_u64, |acc, input| acc + input.partial_input.amount.unwrap()); let consumed_amount = self .outputs .iter() .filter(|output| output.asset == self.network.policy_asset()) - .fold(0 as u64, |acc, output| acc + output.amount); + .fold(0_u64, |acc, output| acc + output.amount); available_amount as i64 - consumed_amount as i64 } diff --git a/crates/sdk/src/transaction/partial_input.rs b/crates/sdk/src/transaction/partial_input.rs index 7eed8b5..5f58324 100644 --- a/crates/sdk/src/transaction/partial_input.rs +++ b/crates/sdk/src/transaction/partial_input.rs @@ -53,58 +53,53 @@ impl PartialInput { witness_txid: outpoint.txid, witness_output_index: outpoint.vout, witness_utxo: txout, - sequence: sequence, - amount: amount, - asset: asset, + sequence, + amount, + asset, } } pub fn outpoint(&self) -> OutPoint { OutPoint { - txid: self.witness_txid.clone(), + txid: self.witness_txid, vout: self.witness_output_index, } } pub fn input(&self) -> Input { - let mut input = Input::default(); - - input.previous_txid = self.witness_txid.clone(); - input.previous_output_index = self.witness_output_index; - input.witness_utxo = Some(self.witness_utxo.clone()); - input.sequence = Some(self.sequence.clone()); - input.amount = self.amount.clone(); - input.asset = self.asset.clone(); - - input + Input { + previous_txid: self.witness_txid, + previous_output_index: self.witness_output_index, + witness_utxo: Some(self.witness_utxo.clone()), + sequence: Some(self.sequence), + amount: self.amount, + asset: self.asset, + ..Default::default() + } } } impl ProgramInput { pub fn new(program: Box, witness: Box) -> Self { - Self { - program: program, - witness: witness, - } + Self { program, witness } } } impl IssuanceInput { pub fn new(issuance_amount: u64, asset_entropy: [u8; 32]) -> Self { Self { - issuance_amount: issuance_amount, - asset_entropy: asset_entropy, + issuance_amount, + asset_entropy, } } pub fn input(&self) -> Input { - let mut input = Input::default(); - - input.issuance_value_amount = Some(self.issuance_amount); - input.issuance_asset_entropy = Some(self.asset_entropy); - input.issuance_inflation_keys = None; - input.blinded_issuance = Some(0x00); - - input + Input { + issuance_value_amount: Some(self.issuance_amount), + issuance_asset_entropy: Some(self.asset_entropy), + issuance_inflation_keys: None, + blinded_issuance: Some(0x00), + ..Default::default() + } } } diff --git a/crates/sdk/src/transaction/partial_output.rs b/crates/sdk/src/transaction/partial_output.rs index 27235bb..3335963 100644 --- a/crates/sdk/src/transaction/partial_output.rs +++ b/crates/sdk/src/transaction/partial_output.rs @@ -12,12 +12,12 @@ impl PartialOutput { pub fn new(script: Script, amount: u64, asset: AssetId) -> Self { Self { script_pubkey: script, - amount: amount, - asset: asset, + amount, + asset, } } pub fn to_output(&self) -> Output { - Output::new_explicit(self.script_pubkey.clone(), self.amount, self.asset.clone(), None) + Output::new_explicit(self.script_pubkey.clone(), self.amount, self.asset, None) } } diff --git a/crates/simplex/tests/compile_test.rs b/crates/simplex/tests/compile_test.rs index 01ebee1..8469a55 100644 --- a/crates/simplex/tests/compile_test.rs +++ b/crates/simplex/tests/compile_test.rs @@ -2,7 +2,7 @@ const SLOW_TEST_ENV: &str = "RUN_UI_TESTS"; #[test] fn ui() { - if let Err(_) = std::env::var(SLOW_TEST_ENV) { + if std::env::var(SLOW_TEST_ENV).is_err() { eprintln!("Set '{SLOW_TEST_ENV}' to true in order to run a test"); return; } diff --git a/crates/test/src/config.rs b/crates/test/src/config.rs index be6c30a..2c84360 100644 --- a/crates/test/src/config.rs +++ b/crates/test/src/config.rs @@ -56,9 +56,9 @@ impl TestConfig { fs::create_dir_all(parent_dir)?; } - let mut file = OpenOptions::new().create(true).write(true).truncate(true).open(&path)?; + let mut file = OpenOptions::new().create(true).write(true).truncate(true).open(path)?; - file.write(toml::to_string_pretty(&self).unwrap().as_bytes())?; + file.write_all(toml::to_string_pretty(&self).unwrap().as_bytes())?; file.flush()?; Ok(()) diff --git a/crates/test/src/context.rs b/crates/test/src/context.rs index e64dc88..1f61942 100644 --- a/crates/test/src/context.rs +++ b/crates/test/src/context.rs @@ -26,13 +26,13 @@ impl TestContext { Ok(Self { _client: client, - config: config, - signer: signer, + config, + signer, }) } - pub fn get_provider(&self) -> &Box { - &self.signer.get_provider() + pub fn get_provider(&self) -> &dyn ProviderTrait { + self.signer.get_provider() } pub fn get_config(&self) -> &TestConfig { @@ -40,7 +40,7 @@ impl TestContext { } pub fn get_network(&self) -> &SimplicityNetwork { - &self.signer.get_provider().get_network() + self.signer.get_provider().get_network() } pub fn get_signer(&self) -> &Signer { @@ -81,7 +81,7 @@ impl TestContext { }, None => { // simplex inner network - let (regtest_client, regtest_signer) = Regtest::new(config.to_regtest_config())?; + let (regtest_client, regtest_signer) = Regtest::from_config(config.to_regtest_config())?; client = Some(regtest_client); signer = regtest_signer; diff --git a/crates/test/src/macros/macros.rs b/crates/test/src/macros/core.rs similarity index 100% rename from crates/test/src/macros/macros.rs rename to crates/test/src/macros/core.rs diff --git a/crates/test/src/macros/mod.rs b/crates/test/src/macros/mod.rs index eb7bb1d..97e0d08 100644 --- a/crates/test/src/macros/mod.rs +++ b/crates/test/src/macros/mod.rs @@ -1,3 +1,3 @@ -pub mod macros; +mod core; -pub use macros::expand; +pub use core::expand;