Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,38 @@ 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()
needs:
- rust-tests
- rustfmt
- crate-checks
- clippy
- deny
timeout-minutes: 30
steps:
Expand Down
10 changes: 4 additions & 6 deletions crates/build/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ impl ArtifactsGenerator {
fn generate_bindings(out_dir: &Path, path_tree: TreeNode) -> Result<Vec<String>, 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)
}
Expand Down Expand Up @@ -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! {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions crates/build/src/macros/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 3 additions & 4 deletions crates/build/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ use super::error::BuildError;
pub struct ArtifactsResolver {}

impl ArtifactsResolver {
pub fn resolve_files_to_build(src_dir: &String, simfs: &Vec<String>) -> Result<Vec<PathBuf>, BuildError> {
pub fn resolve_files_to_build(src_dir: &String, simfs: &[String]) -> Result<Vec<PathBuf>, 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 {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion crates/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod build;
pub mod commands;
mod core;
pub mod error;
pub mod regtest;
pub mod test;

pub use core::*;
2 changes: 1 addition & 1 deletion crates/cli/src/commands/regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -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(" --");
Expand All @@ -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(" --");
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions crates/cli/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
10 changes: 4 additions & 6 deletions crates/regtest/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
}
}
2 changes: 1 addition & 1 deletion crates/regtest/src/regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -129,7 +129,7 @@ impl ProgramTrait for Program {
input_index: usize,
network: &SimplicityNetwork,
) -> Result<Vec<Vec<u8>>, 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();
Expand All @@ -146,9 +146,9 @@ impl ProgramTrait for Program {
impl Program {
pub fn new(source: &'static str, pub_key: XOnlyPublicKey, arguments: Box<dyn ArgumentsTrait>) -> Self {
Self {
source: source,
pub_key: pub_key,
arguments: arguments,
source,
pub_key,
arguments,
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/sdk/src/program/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
File renamed without changes.
23 changes: 10 additions & 13 deletions crates/sdk/src/provider/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
}
}
Expand All @@ -64,11 +64,8 @@ impl EsploraProvider {
Ok(OutPoint::new(txid, utxo.vout))
}

fn populate_txouts_from_outpoints(
&self,
outpoints: &Vec<OutPoint>,
) -> Result<Vec<(OutPoint, TxOut)>, ProviderError> {
let set: HashSet<_> = outpoints.into_iter().collect();
fn populate_txouts_from_outpoints(&self, outpoints: &[OutPoint]) -> Result<Vec<(OutPoint, TxOut)>, ProviderError> {
let set: HashSet<_> = outpoints.iter().collect();
let mut map = HashMap::new();

// filter unique transactions
Expand Down Expand Up @@ -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),
};
Expand Down Expand Up @@ -194,10 +191,10 @@ impl ProviderTrait for EsploraProvider {
let utxos: Vec<EsploraUtxo> = 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::<Result<Vec<OutPoint>, ProviderError>>()?;

Ok(self.populate_txouts_from_outpoints(&outpoints)?)
self.populate_txouts_from_outpoints(&outpoints)
}

fn fetch_scripthash_utxos(&self, script: &Script) -> Result<Vec<(OutPoint, TxOut)>, ProviderError> {
Expand All @@ -223,10 +220,10 @@ impl ProviderTrait for EsploraProvider {
let utxos: Vec<EsploraUtxo> = 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::<Result<Vec<OutPoint>, ProviderError>>()?;

Ok(self.populate_txouts_from_outpoints(&outpoints)?)
self.populate_txouts_from_outpoints(&outpoints)
}

fn fetch_fee_estimates(&self) -> Result<HashMap<String, f64>, ProviderError> {
Expand Down
4 changes: 2 additions & 2 deletions crates/sdk/src/provider/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 1 addition & 5 deletions crates/sdk/src/provider/rpc/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64, RpcError> {
Expand Down
12 changes: 6 additions & 6 deletions crates/sdk/src/provider/simplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<Transaction, ProviderError> {
Ok(self.esplora.fetch_transaction(txid)?)
self.esplora.fetch_transaction(txid)
}

fn fetch_address_utxos(&self, address: &Address) -> Result<Vec<(OutPoint, TxOut)>, ProviderError> {
Ok(self.esplora.fetch_address_utxos(address)?)
self.esplora.fetch_address_utxos(address)
}

fn fetch_scripthash_utxos(&self, script: &Script) -> Result<Vec<(OutPoint, TxOut)>, ProviderError> {
Ok(self.esplora.fetch_scripthash_utxos(script)?)
self.esplora.fetch_scripthash_utxos(script)
}

fn fetch_fee_estimates(&self) -> Result<HashMap<String, f64>, ProviderError> {
Ok(self.esplora.fetch_fee_estimates()?)
self.esplora.fetch_fee_estimates()
}
}
Loading