From f84be614f695ebb572165e0abf89ea1c6cf50a70 Mon Sep 17 00:00:00 2001 From: Artem Chystiakov Date: Tue, 10 Mar 2026 13:53:21 +0200 Subject: [PATCH 1/3] regtest signer --- Cargo.lock | 2 + README.md | 9 +- crates/build/src/error.rs | 2 +- crates/cli/Simplex.default.toml | 15 ++-- crates/cli/src/cli.rs | 10 +-- crates/cli/src/commands/error.rs | 9 +- crates/cli/src/commands/regtest.rs | 22 +++-- crates/cli/src/config/config.rs | 23 +++-- crates/regtest/Cargo.toml | 2 + crates/regtest/src/client.rs | 10 +-- crates/regtest/src/config.rs | 34 ++++++++ crates/regtest/src/error.rs | 23 ++++- crates/regtest/src/lib.rs | 5 +- crates/regtest/src/regtest.rs | 62 ++++++++++++++ crates/test/src/config.rs | 35 +++++--- crates/test/src/context.rs | 83 ++++--------------- crates/test/src/error.rs | 19 +++-- examples/basic/Cargo.lock | 2 + examples/basic/Simplex.toml | 15 ++-- .../another_module/bytes32_tr_storage.rs | 24 ------ .../another_module/dual_currency_deposit.rs | 24 ------ .../another_dir/another_module/mod.rs | 2 - .../artifacts/another_dir/array_tr_storage.rs | 24 ------ .../basic/src/artifacts/another_dir/mod.rs | 2 - examples/basic/src/artifacts/mod.rs | 4 - examples/basic/src/artifacts/module/mod.rs | 1 - .../src/artifacts/module/option_offer.rs | 24 ------ examples/basic/src/artifacts/options.rs | 24 ------ examples/basic/src/artifacts/p2pk.rs | 24 ------ 29 files changed, 244 insertions(+), 291 deletions(-) create mode 100644 crates/regtest/src/config.rs create mode 100644 crates/regtest/src/regtest.rs delete mode 100644 examples/basic/src/artifacts/another_dir/another_module/bytes32_tr_storage.rs delete mode 100644 examples/basic/src/artifacts/another_dir/another_module/dual_currency_deposit.rs delete mode 100644 examples/basic/src/artifacts/another_dir/another_module/mod.rs delete mode 100644 examples/basic/src/artifacts/another_dir/array_tr_storage.rs delete mode 100644 examples/basic/src/artifacts/another_dir/mod.rs delete mode 100644 examples/basic/src/artifacts/mod.rs delete mode 100644 examples/basic/src/artifacts/module/mod.rs delete mode 100644 examples/basic/src/artifacts/module/option_offer.rs delete mode 100644 examples/basic/src/artifacts/options.rs delete mode 100644 examples/basic/src/artifacts/p2pk.rs diff --git a/Cargo.lock b/Cargo.lock index b9bd328..a921d0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1328,8 +1328,10 @@ name = "simplex-regtest" version = "0.1.0" dependencies = [ "electrsd", + "serde", "simplex-sdk", "thiserror", + "toml 0.9.12+spec-1.1.0", ] [[package]] diff --git a/README.md b/README.md index 493ca4c..ec0b763 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,15 @@ src_dir = "./simf" simf_files = ["*.simf"] out_dir = "./src/artifacts" +[regtest] +mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean" + [test] mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean" [test.esplora] url = "" -network = "" +network = "" [test.rpc] url = "" @@ -60,7 +63,7 @@ Where: - `test` (`simplex test` config) - `esplora` - `url` - Esplora API endpoint url - - `network` - Esplora network type (`Liquid`, `LiquidTestnet`, `LiquidRegtest`). + - `network` - Esplora network type (`Liquid`, `LiquidTestnet`, `ElementsRegtest`). - `rpc` - `url` - Elements RPC endpoint url - `username` - Elements RPC username @@ -90,7 +93,7 @@ Check out the complete project examples in the `examples` directory to learn mor ## Future work - [ ] Custom signer setup with `simplex regtest`. -- [ ] SDK support for confidential assets. +- [ ] SDK support for confidential assets, taproot signer, and custom witness signatures. - [ ] `simplex init` and `simplex clean` tasks. - [ ] Proper installation scripts. - [ ] Simplicity dependencies management once the language adds [support for modules](https://github.com/BlockstreamResearch/SimplicityHL/issues/155). diff --git a/crates/build/src/error.rs b/crates/build/src/error.rs index 7659748..140b89a 100644 --- a/crates/build/src/error.rs +++ b/crates/build/src/error.rs @@ -11,7 +11,7 @@ pub enum BuildError { #[error("Glob error: {0}")] Glob(#[from] GlobError), - #[error("Occurred config deserialization error: '{0}'")] + #[error("Failed to deserialize config: '{0}'")] ConfigDeserialize(#[from] toml::de::Error), #[error("Invalid generation path: '{0}'")] diff --git a/crates/cli/Simplex.default.toml b/crates/cli/Simplex.default.toml index b63c7a5..b571f40 100644 --- a/crates/cli/Simplex.default.toml +++ b/crates/cli/Simplex.default.toml @@ -1,18 +1,21 @@ # TEST CONFIG # [build] +# src_dir = "./simf" # simf_files = ["*.simf"] # out_dir = "./src/artifacts" -# src_dir = "./simf" + +# [regtest] +# mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean" # [test] # mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean" # [test.esplora] -# url = "https://blockstream.info/liquidtestnet/api" -# network = "LiquidTestnet" +# url = "" +# network = "" # [test.rpc] -# url = "" -# username = "" -# password = "" +# url = "" +# username = "" +# password = "" diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index 3c8d1e6..547c0d9 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -42,13 +42,13 @@ impl Cli { let config_path = Config::get_default_path()?; let loaded_config = Config::load(config_path)?; - let test_config = loaded_config.test.unwrap_or_default(); - - Ok(Test::run(test_config, command)?) + Ok(Test::run(loaded_config.test, command)?) } Command::Regtest => { - // TODO: pass config - Ok(Regtest::run()?) + let config_path = Config::get_default_path()?; + let loaded_config = Config::load(config_path)?; + + Ok(Regtest::run(loaded_config.regtest)?) } Command::Build => { let config_path = Config::get_default_path()?; diff --git a/crates/cli/src/commands/error.rs b/crates/cli/src/commands/error.rs index 03e2f40..7a2b7f8 100644 --- a/crates/cli/src/commands/error.rs +++ b/crates/cli/src/commands/error.rs @@ -1,14 +1,17 @@ #[derive(thiserror::Error, Debug)] pub enum CommandError { - #[error("IO error: {0}")] - Io(#[from] std::io::Error), + #[error(transparent)] + Signer(#[from] simplex_sdk::signer::SignerError), #[error(transparent)] - Client(#[from] simplex_regtest::error::ClientError), + Regtest(#[from] simplex_regtest::error::RegtestError), #[error(transparent)] Test(#[from] simplex_test::error::TestError), #[error(transparent)] Build(#[from] simplex_build::error::BuildError), + + #[error("IO error: {0}")] + Io(#[from] std::io::Error), } diff --git a/crates/cli/src/commands/regtest.rs b/crates/cli/src/commands/regtest.rs index d6afe2a..017490e 100644 --- a/crates/cli/src/commands/regtest.rs +++ b/crates/cli/src/commands/regtest.rs @@ -1,15 +1,16 @@ use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; -use simplex_regtest::TestClient; +use simplex_regtest::Regtest as RegtestRunner; +use simplex_regtest::RegtestConfig; use crate::commands::error::CommandError; pub struct Regtest {} impl Regtest { - pub fn run() -> Result<(), CommandError> { - let mut client = TestClient::new(); + pub fn run(config: RegtestConfig) -> Result<(), CommandError> { + let (mut client, signer) = RegtestRunner::new(config)?; let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); @@ -19,12 +20,19 @@ impl Regtest { }) .expect("Error setting Ctrl-C handler"); + let auth = client.auth().get_user_pass().unwrap(); + println!("======================================"); println!("Waiting for Ctrl-C..."); - println!("rpc: {}", client.rpc_url()); - println!("esplora: {}", client.esplora_url()); - let auth = client.auth().get_user_pass().unwrap(); - println!("user: {:?}, password: {:?}", auth.0.unwrap(), auth.1.unwrap()); + println!("RPC: {}", client.rpc_url()); + println!("Esplora: {}", client.esplora_url()); + println!("User: {:?}, Password: {:?}", auth.0.unwrap(), auth.1.unwrap()); + println!(); + println!( + "Signer: {:?}, Private Key: {:?}", + signer.get_wpkh_address()?, + signer.get_private_key()? + ); println!("======================================"); while running.load(Ordering::SeqCst) {} diff --git a/crates/cli/src/config/config.rs b/crates/cli/src/config/config.rs index 168ca69..9e9479e 100644 --- a/crates/cli/src/config/config.rs +++ b/crates/cli/src/config/config.rs @@ -2,6 +2,7 @@ use serde::Deserialize; use std::path::{Path, PathBuf}; use simplex_build::BuildConfig; +use simplex_regtest::RegtestConfig; use simplex_test::TestConfig; use super::error::ConfigError; @@ -12,8 +13,9 @@ pub const CONFIG_FILENAME: &str = "Simplex.toml"; #[derive(Debug, Default, Clone, Deserialize)] #[serde(default)] pub struct Config { - pub test: Option, pub build: BuildConfig, + pub regtest: RegtestConfig, + pub test: TestConfig, } impl Config { @@ -43,19 +45,16 @@ impl Config { } fn validate(config: &Config) -> Result<(), ConfigError> { - match config.test.clone() { - Some(test_config) => match test_config.esplora { - Some(esplora_config) => { - Self::validate_network(&esplora_config.network)?; + match config.test.esplora.clone() { + Some(esplora_config) => { + Self::validate_network(&esplora_config.network)?; - if test_config.rpc.is_some() && esplora_config.network != "ElementsRegtest" { - return Err(ConfigError::NetworkNameUnmatched(esplora_config.network.clone())); - } - - Ok(()) + if config.test.rpc.is_some() && esplora_config.network != "ElementsRegtest" { + return Err(ConfigError::NetworkNameUnmatched(esplora_config.network.clone())); } - None => Ok(()), - }, + + Ok(()) + } None => Ok(()), } } diff --git a/crates/regtest/Cargo.toml b/crates/regtest/Cargo.toml index cddb69c..4af11d0 100644 --- a/crates/regtest/Cargo.toml +++ b/crates/regtest/Cargo.toml @@ -13,3 +13,5 @@ simplex-sdk = { workspace = true } thiserror = { workspace = true } electrsd = { workspace = true } +serde = { workspace = true } +toml = { workspace = true } diff --git a/crates/regtest/src/client.rs b/crates/regtest/src/client.rs index a5ab4bb..a2caee1 100644 --- a/crates/regtest/src/client.rs +++ b/crates/regtest/src/client.rs @@ -6,15 +6,15 @@ use electrsd::bitcoind; use electrsd::bitcoind::bitcoincore_rpc::Auth; use electrsd::bitcoind::{BitcoinD, Conf}; -use super::error::ClientError; +use super::error::RegtestError; use crate::args::{get_electrs_bin_args, get_elementsd_bin_args}; -pub struct TestClient { +pub struct RegtestClient { pub electrs: ElectrsD, pub elements: BitcoinD, } -impl TestClient { +impl RegtestClient { // TODO: pass custom config pub fn new() -> Self { let (electrs_path, elementsd_path) = Self::default_bin_paths(); @@ -57,9 +57,9 @@ impl TestClient { Auth::UserPass(cookie.user, cookie.password) } - pub fn kill(&mut self) -> Result<(), ClientError> { + pub fn kill(&mut self) -> Result<(), RegtestError> { // electrs stops elements automatically - self.electrs.kill().map_err(|_| ClientError::ElectrsTermination())?; + self.electrs.kill().map_err(|_| RegtestError::ElectrsTermination())?; Ok(()) } diff --git a/crates/regtest/src/config.rs b/crates/regtest/src/config.rs new file mode 100644 index 0000000..64e3a0c --- /dev/null +++ b/crates/regtest/src/config.rs @@ -0,0 +1,34 @@ +use std::fs::OpenOptions; +use std::io::Read; +use std::path::Path; + +use serde::Deserialize; + +use super::error::RegtestError; + +pub const DEFAULT_REGTEST_MNEMONIC: &str = "exist carry drive collect lend cereal occur much tiger just involve mean"; + +#[derive(Debug, Clone, Deserialize)] +#[serde(default)] +pub struct RegtestConfig { + pub mnemonic: String, +} + +impl RegtestConfig { + pub fn from_file(path: impl AsRef) -> Result { + let mut content = String::new(); + let mut file = OpenOptions::new().read(true).open(path)?; + + file.read_to_string(&mut content)?; + + Ok(toml::from_str(&content)?) + } +} + +impl Default for RegtestConfig { + fn default() -> Self { + Self { + mnemonic: DEFAULT_REGTEST_MNEMONIC.to_string(), + } + } +} diff --git a/crates/regtest/src/error.rs b/crates/regtest/src/error.rs index 966185e..ec05bae 100644 --- a/crates/regtest/src/error.rs +++ b/crates/regtest/src/error.rs @@ -1,8 +1,29 @@ +use std::io; + +use simplex_sdk::provider::ProviderError; +use simplex_sdk::provider::RpcError; +use simplex_sdk::signer::SignerError; + #[derive(thiserror::Error, Debug)] -pub enum ClientError { +pub enum RegtestError { + #[error(transparent)] + Provider(#[from] ProviderError), + + #[error(transparent)] + Rpc(#[from] RpcError), + + #[error(transparent)] + Signer(#[from] SignerError), + #[error("Failed to terminate elements")] ElementsTermination(), #[error("Failed to terminate electrs")] ElectrsTermination(), + + #[error("Failed to deserialize config: '{0}'")] + ConfigDeserialize(#[from] toml::de::Error), + + #[error("io error occurred: '{0}'")] + Io(#[from] io::Error), } diff --git a/crates/regtest/src/lib.rs b/crates/regtest/src/lib.rs index 7a0cd31..b7c3e04 100644 --- a/crates/regtest/src/lib.rs +++ b/crates/regtest/src/lib.rs @@ -1,5 +1,8 @@ mod args; pub mod client; pub mod error; +pub mod config; +pub mod regtest; -pub use client::TestClient; +pub use regtest::Regtest; +pub use config::RegtestConfig; diff --git a/crates/regtest/src/regtest.rs b/crates/regtest/src/regtest.rs new file mode 100644 index 0000000..27d9e3c --- /dev/null +++ b/crates/regtest/src/regtest.rs @@ -0,0 +1,62 @@ +use std::time::Duration; + +use simplex_sdk::provider::ElementsRpc; +use simplex_sdk::provider::SimplexProvider; +use simplex_sdk::provider::SimplicityNetwork; +use simplex_sdk::signer::Signer; + +use super::client::RegtestClient; +use super::RegtestConfig; +use super::error::RegtestError; + +pub struct Regtest {} + +impl Regtest { + pub fn new(config: RegtestConfig) -> Result<(RegtestClient, Signer), RegtestError> { + let client = RegtestClient::new(); + + let provider = Box::new(SimplexProvider::new( + client.esplora_url(), + client.rpc_url(), + client.auth(), + SimplicityNetwork::default_regtest(), + )?); + + let signer = Signer::new(config.mnemonic.as_str(), provider)?; + + Self::prepare_signer(&client, &signer)?; + + Ok((client, signer)) + } + + fn prepare_signer(client: &RegtestClient, signer: &Signer) -> Result<(), RegtestError> { + let rpc_provider = ElementsRpc::new(client.rpc_url(), client.auth())?; + + rpc_provider.generate_blocks(1)?; + rpc_provider.rescanblockchain(None, None)?; + rpc_provider.sweep_initialfreecoins()?; + rpc_provider.generate_blocks(100)?; + + // 20 million BTC + rpc_provider.sendtoaddress(&signer.get_wpkh_address()?, 20_000_000 * u64::pow(10, 8), None)?; + + // wait for electrs to index + let mut attempts = 0; + + loop { + if !(signer.get_wpkh_utxos()?).is_empty() { + break; + } + + attempts += 1; + + if attempts > 100 { + panic!("Electrs failed to index the sweep after 10 seconds"); + } + + std::thread::sleep(Duration::from_millis(100)); + } + + Ok(()) + } +} diff --git a/crates/test/src/config.rs b/crates/test/src/config.rs index 301e6ac..5048592 100644 --- a/crates/test/src/config.rs +++ b/crates/test/src/config.rs @@ -6,12 +6,15 @@ use std::path::Path; use serde::{Deserialize, Serialize}; +use simplex_regtest::RegtestConfig; + use super::error::TestError; pub const TEST_ENV_NAME: &str = "SIMPLEX_TEST_ENV"; -pub const TEST_MNEMONIC: &str = "exist carry drive collect lend cereal occur much tiger just involve mean"; +pub const DEFAULT_TEST_MNEMONIC: &str = "exist carry drive collect lend cereal occur much tiger just involve mean"; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(default)] pub struct TestConfig { pub mnemonic: String, pub esplora: Option, @@ -32,34 +35,40 @@ pub struct RpcConfig { } impl TestConfig { + pub fn from_file(path: impl AsRef) -> Result { + let mut content = String::new(); + let mut file = OpenOptions::new().read(true).open(path)?; + + file.read_to_string(&mut content)?; + + // TODO: check that network name is correct + Ok(toml::from_str(&content)?) + } + + pub fn to_regtest_config(&self) -> RegtestConfig { + RegtestConfig { + mnemonic: self.mnemonic.clone(), + } + } + pub fn to_file(&self, path: &impl AsRef) -> Result<(), TestError> { if let Some(parent_dir) = path.as_ref().parent() { fs::create_dir_all(parent_dir)?; } - let mut file = OpenOptions::new().create(true).write(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.flush()?; Ok(()) } - - pub fn from_file(path: impl AsRef) -> Result { - let mut content = String::new(); - let mut file = OpenOptions::new().read(true).open(path)?; - - file.read_to_string(&mut content)?; - - // TODO: check that network name is correct - Ok(toml::from_str(&content)?) - } } impl Default for TestConfig { fn default() -> Self { Self { - mnemonic: TEST_MNEMONIC.to_string(), + mnemonic: DEFAULT_TEST_MNEMONIC.to_string(), esplora: None, rpc: None, } diff --git a/crates/test/src/context.rs b/crates/test/src/context.rs index 5ece65d..a373998 100644 --- a/crates/test/src/context.rs +++ b/crates/test/src/context.rs @@ -1,10 +1,10 @@ use std::path::PathBuf; -use std::time::Duration; use electrsd::bitcoind::bitcoincore_rpc::Auth; -use simplex_regtest::TestClient; -use simplex_sdk::provider::ElementsRpc; +use simplex_regtest::Regtest; +use simplex_regtest::client::RegtestClient; + use simplex_sdk::provider::{EsploraProvider, ProviderTrait, SimplexProvider, SimplicityNetwork}; use simplex_sdk::signer::Signer; @@ -13,7 +13,7 @@ use crate::error::TestError; #[allow(dead_code)] pub struct TestContext { - _client: Option, + _client: Option, config: TestConfig, signer: Signer, } @@ -22,8 +22,7 @@ impl TestContext { pub fn new(config_path: PathBuf) -> Result { let config = TestConfig::from_file(&config_path)?; - let (provider, client) = Self::setup_provider(&config)?; - let signer = Self::setup_signer(provider, &client, &config.mnemonic)?; + let (signer, client) = Self::setup(&config)?; Ok(Self { _client: client, @@ -48,22 +47,23 @@ impl TestContext { &self.signer } - fn setup_provider(config: &TestConfig) -> Result<(Box, Option), TestError> { - let provider: Box; - let client: Option; + fn setup(config: &TestConfig) -> Result<(Signer, Option), TestError> { + let client: Option; + let signer: Signer; match config.esplora.clone() { Some(esplora) => match config.rpc.clone() { Some(rpc) => { // custom regtest case let auth = Auth::UserPass(rpc.username, rpc.password); - - provider = Box::new(SimplexProvider::new( + let provider = Box::new(SimplexProvider::new( esplora.url, rpc.url, auth, SimplicityNetwork::default_regtest(), )?); + + signer = Signer::new(config.mnemonic.as_str(), provider)?; client = None; } None => { @@ -73,70 +73,21 @@ impl TestContext { "LiquidTestnet" => SimplicityNetwork::LiquidTestnet, _ => panic!("Impossible branch reached, please report a bug"), }; + let provider = Box::new(EsploraProvider::new(esplora.url, network)); - provider = Box::new(EsploraProvider::new(esplora.url, network)); + signer = Signer::new(config.mnemonic.as_str(), provider)?; client = None; } }, None => { // simplex inner network - let client_inner = TestClient::new(); + let (regtest_client, regtest_signer) = Regtest::new(config.to_regtest_config())?; - provider = Box::new(SimplexProvider::new( - client_inner.esplora_url(), - client_inner.rpc_url(), - client_inner.auth(), - SimplicityNetwork::default_regtest(), - )?); - - // need to save the client so that rust doesn't kill it - client = Some(client_inner); + client = Some(regtest_client); + signer = regtest_signer; } } - Ok((provider, client)) - } - - fn setup_signer( - provider: Box, - client: &Option, - mnemonic: &String, - ) -> Result { - let signer = Signer::new(mnemonic, provider)?; - - match client { - // if client exists, we are using inner simplex network - Some(client_inner) => { - let rpc_provider = ElementsRpc::new(client_inner.rpc_url(), client_inner.auth())?; - - rpc_provider.generate_blocks(1)?; - rpc_provider.rescanblockchain(None, None)?; - rpc_provider.sweep_initialfreecoins()?; - rpc_provider.generate_blocks(100)?; - - // 20 million BTC - rpc_provider.sendtoaddress(&signer.get_wpkh_address()?, 20_000_000 * u64::pow(10, 8), None)?; - - // wait for electrs to index - let mut attempts = 0; - - loop { - if !(signer.get_wpkh_utxos()?).is_empty() { - break; - } - - attempts += 1; - - if attempts > 100 { - panic!("Electrs failed to index the sweep after 10 seconds"); - } - - std::thread::sleep(Duration::from_millis(100)); - } - } - None => {} - }; - - Ok(signer) + Ok((signer, client)) } } diff --git a/crates/test/src/error.rs b/crates/test/src/error.rs index bcabf1e..2486a46 100644 --- a/crates/test/src/error.rs +++ b/crates/test/src/error.rs @@ -1,23 +1,24 @@ use std::io; use simplex_sdk::provider::ProviderError; -use simplex_sdk::provider::RpcError; use simplex_sdk::signer::SignerError; +use simplex_regtest::error::RegtestError; + #[derive(thiserror::Error, Debug)] pub enum TestError { - #[error("Occurred io error: '{0}'")] - Io(#[from] io::Error), - #[error(transparent)] - Provider(#[from] ProviderError), - + Regtest(#[from] RegtestError), + #[error(transparent)] - Rpc(#[from] RpcError), + Provider(#[from] ProviderError), #[error(transparent)] Signer(#[from] SignerError), - - #[error("Occurred config deserialization error: '{0}'")] + + #[error("Failed to deserialize config: '{0}'")] ConfigDeserialize(#[from] toml::de::Error), + + #[error("io error occurred: '{0}'")] + Io(#[from] io::Error), } diff --git a/examples/basic/Cargo.lock b/examples/basic/Cargo.lock index c82e810..9a4600d 100644 --- a/examples/basic/Cargo.lock +++ b/examples/basic/Cargo.lock @@ -1226,8 +1226,10 @@ name = "simplex-regtest" version = "0.1.0" dependencies = [ "electrsd", + "serde", "simplex-sdk", "thiserror", + "toml", ] [[package]] diff --git a/examples/basic/Simplex.toml b/examples/basic/Simplex.toml index b63c7a5..b571f40 100644 --- a/examples/basic/Simplex.toml +++ b/examples/basic/Simplex.toml @@ -1,18 +1,21 @@ # TEST CONFIG # [build] +# src_dir = "./simf" # simf_files = ["*.simf"] # out_dir = "./src/artifacts" -# src_dir = "./simf" + +# [regtest] +# mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean" # [test] # mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean" # [test.esplora] -# url = "https://blockstream.info/liquidtestnet/api" -# network = "LiquidTestnet" +# url = "" +# network = "" # [test.rpc] -# url = "" -# username = "" -# password = "" +# url = "" +# username = "" +# password = "" diff --git a/examples/basic/src/artifacts/another_dir/another_module/bytes32_tr_storage.rs b/examples/basic/src/artifacts/another_dir/another_module/bytes32_tr_storage.rs deleted file mode 100644 index 70abfcf..0000000 --- a/examples/basic/src/artifacts/another_dir/another_module/bytes32_tr_storage.rs +++ /dev/null @@ -1,24 +0,0 @@ -use simplex::include_simf; -use simplex::simplex_sdk::program::{ArgumentsTrait, Program}; -use simplicityhl::elements::secp256k1_zkp::XOnlyPublicKey; -pub struct Bytes32TrStorageProgram { - program: Program, -} -impl Bytes32TrStorageProgram { - pub const SOURCE: &'static str = derived_bytes32_tr_storage::BYTES32_TR_STORAGE_CONTRACT_SOURCE; - pub fn new( - public_key: XOnlyPublicKey, - arguments: impl ArgumentsTrait + 'static, - ) -> Self { - Self { - program: Program::new(Self::SOURCE, public_key, Box::new(arguments)), - } - } - pub fn get_program(&self) -> &Program { - &self.program - } - pub fn get_program_mut(&mut self) -> &mut Program { - &mut self.program - } -} -include_simf!("simf/another_dir/another_module/bytes32_tr_storage.simf"); diff --git a/examples/basic/src/artifacts/another_dir/another_module/dual_currency_deposit.rs b/examples/basic/src/artifacts/another_dir/another_module/dual_currency_deposit.rs deleted file mode 100644 index 4a2c288..0000000 --- a/examples/basic/src/artifacts/another_dir/another_module/dual_currency_deposit.rs +++ /dev/null @@ -1,24 +0,0 @@ -use simplex::include_simf; -use simplex::simplex_sdk::program::{ArgumentsTrait, Program}; -use simplicityhl::elements::secp256k1_zkp::XOnlyPublicKey; -pub struct DualCurrencyDepositProgram { - program: Program, -} -impl DualCurrencyDepositProgram { - pub const SOURCE: &'static str = derived_dual_currency_deposit::DUAL_CURRENCY_DEPOSIT_CONTRACT_SOURCE; - pub fn new( - public_key: XOnlyPublicKey, - arguments: impl ArgumentsTrait + 'static, - ) -> Self { - Self { - program: Program::new(Self::SOURCE, public_key, Box::new(arguments)), - } - } - pub fn get_program(&self) -> &Program { - &self.program - } - pub fn get_program_mut(&mut self) -> &mut Program { - &mut self.program - } -} -include_simf!("simf/another_dir/another_module/dual_currency_deposit.simf"); diff --git a/examples/basic/src/artifacts/another_dir/another_module/mod.rs b/examples/basic/src/artifacts/another_dir/another_module/mod.rs deleted file mode 100644 index 121de82..0000000 --- a/examples/basic/src/artifacts/another_dir/another_module/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod dual_currency_deposit; -pub mod bytes32_tr_storage; diff --git a/examples/basic/src/artifacts/another_dir/array_tr_storage.rs b/examples/basic/src/artifacts/another_dir/array_tr_storage.rs deleted file mode 100644 index 373f444..0000000 --- a/examples/basic/src/artifacts/another_dir/array_tr_storage.rs +++ /dev/null @@ -1,24 +0,0 @@ -use simplex::include_simf; -use simplex::simplex_sdk::program::{ArgumentsTrait, Program}; -use simplicityhl::elements::secp256k1_zkp::XOnlyPublicKey; -pub struct ArrayTrStorageProgram { - program: Program, -} -impl ArrayTrStorageProgram { - pub const SOURCE: &'static str = derived_array_tr_storage::ARRAY_TR_STORAGE_CONTRACT_SOURCE; - pub fn new( - public_key: XOnlyPublicKey, - arguments: impl ArgumentsTrait + 'static, - ) -> Self { - Self { - program: Program::new(Self::SOURCE, public_key, Box::new(arguments)), - } - } - pub fn get_program(&self) -> &Program { - &self.program - } - pub fn get_program_mut(&mut self) -> &mut Program { - &mut self.program - } -} -include_simf!("simf/another_dir/array_tr_storage.simf"); diff --git a/examples/basic/src/artifacts/another_dir/mod.rs b/examples/basic/src/artifacts/another_dir/mod.rs deleted file mode 100644 index f7bff3b..0000000 --- a/examples/basic/src/artifacts/another_dir/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod array_tr_storage; -pub mod another_module; diff --git a/examples/basic/src/artifacts/mod.rs b/examples/basic/src/artifacts/mod.rs deleted file mode 100644 index b78b75d..0000000 --- a/examples/basic/src/artifacts/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod p2pk; -pub mod options; -pub mod module; -pub mod another_dir; diff --git a/examples/basic/src/artifacts/module/mod.rs b/examples/basic/src/artifacts/module/mod.rs deleted file mode 100644 index 920b31d..0000000 --- a/examples/basic/src/artifacts/module/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod option_offer; diff --git a/examples/basic/src/artifacts/module/option_offer.rs b/examples/basic/src/artifacts/module/option_offer.rs deleted file mode 100644 index 603e7be..0000000 --- a/examples/basic/src/artifacts/module/option_offer.rs +++ /dev/null @@ -1,24 +0,0 @@ -use simplex::include_simf; -use simplex::simplex_sdk::program::{ArgumentsTrait, Program}; -use simplicityhl::elements::secp256k1_zkp::XOnlyPublicKey; -pub struct OptionOfferProgram { - program: Program, -} -impl OptionOfferProgram { - pub const SOURCE: &'static str = derived_option_offer::OPTION_OFFER_CONTRACT_SOURCE; - pub fn new( - public_key: XOnlyPublicKey, - arguments: impl ArgumentsTrait + 'static, - ) -> Self { - Self { - program: Program::new(Self::SOURCE, public_key, Box::new(arguments)), - } - } - pub fn get_program(&self) -> &Program { - &self.program - } - pub fn get_program_mut(&mut self) -> &mut Program { - &mut self.program - } -} -include_simf!("simf/module/option_offer.simf"); diff --git a/examples/basic/src/artifacts/options.rs b/examples/basic/src/artifacts/options.rs deleted file mode 100644 index 9631c0a..0000000 --- a/examples/basic/src/artifacts/options.rs +++ /dev/null @@ -1,24 +0,0 @@ -use simplex::include_simf; -use simplex::simplex_sdk::program::{ArgumentsTrait, Program}; -use simplicityhl::elements::secp256k1_zkp::XOnlyPublicKey; -pub struct OptionsProgram { - program: Program, -} -impl OptionsProgram { - pub const SOURCE: &'static str = derived_options::OPTIONS_CONTRACT_SOURCE; - pub fn new( - public_key: XOnlyPublicKey, - arguments: impl ArgumentsTrait + 'static, - ) -> Self { - Self { - program: Program::new(Self::SOURCE, public_key, Box::new(arguments)), - } - } - pub fn get_program(&self) -> &Program { - &self.program - } - pub fn get_program_mut(&mut self) -> &mut Program { - &mut self.program - } -} -include_simf!("simf/options.simf"); diff --git a/examples/basic/src/artifacts/p2pk.rs b/examples/basic/src/artifacts/p2pk.rs deleted file mode 100644 index 3cf11bf..0000000 --- a/examples/basic/src/artifacts/p2pk.rs +++ /dev/null @@ -1,24 +0,0 @@ -use simplex::include_simf; -use simplex::simplex_sdk::program::{ArgumentsTrait, Program}; -use simplicityhl::elements::secp256k1_zkp::XOnlyPublicKey; -pub struct P2pkProgram { - program: Program, -} -impl P2pkProgram { - pub const SOURCE: &'static str = derived_p2pk::P2PK_CONTRACT_SOURCE; - pub fn new( - public_key: XOnlyPublicKey, - arguments: impl ArgumentsTrait + 'static, - ) -> Self { - Self { - program: Program::new(Self::SOURCE, public_key, Box::new(arguments)), - } - } - pub fn get_program(&self) -> &Program { - &self.program - } - pub fn get_program_mut(&mut self) -> &mut Program { - &mut self.program - } -} -include_simf!("simf/p2pk.simf"); From 125148ef0cf7790b2c3a8eea43024940a3ca1ef6 Mon Sep 17 00:00:00 2001 From: Artem Chystiakov Date: Tue, 10 Mar 2026 14:06:08 +0200 Subject: [PATCH 2/3] quick display ux --- crates/cli/src/commands/regtest.rs | 7 ++----- examples/basic/.gitignore | 1 + 2 files changed, 3 insertions(+), 5 deletions(-) create mode 100644 examples/basic/.gitignore diff --git a/crates/cli/src/commands/regtest.rs b/crates/cli/src/commands/regtest.rs index 017490e..000664f 100644 --- a/crates/cli/src/commands/regtest.rs +++ b/crates/cli/src/commands/regtest.rs @@ -24,15 +24,12 @@ impl Regtest { println!("======================================"); println!("Waiting for Ctrl-C..."); + println!(); println!("RPC: {}", client.rpc_url()); println!("Esplora: {}", client.esplora_url()); println!("User: {:?}, Password: {:?}", auth.0.unwrap(), auth.1.unwrap()); println!(); - println!( - "Signer: {:?}, Private Key: {:?}", - signer.get_wpkh_address()?, - signer.get_private_key()? - ); + println!("Signer: {:?}", signer.get_wpkh_address()?); println!("======================================"); while running.load(Ordering::SeqCst) {} diff --git a/examples/basic/.gitignore b/examples/basic/.gitignore new file mode 100644 index 0000000..327555c --- /dev/null +++ b/examples/basic/.gitignore @@ -0,0 +1 @@ +src/artifacts From e3c2f52cfb9fed57d2e17fc4c999b5b68faa716e Mon Sep 17 00:00:00 2001 From: Artem Chystiakov Date: Tue, 10 Mar 2026 14:08:41 +0200 Subject: [PATCH 3/3] readme --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index ec0b763..29286f3 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,6 @@ Check out the complete project examples in the `examples` directory to learn mor ## Future work -- [ ] Custom signer setup with `simplex regtest`. - [ ] SDK support for confidential assets, taproot signer, and custom witness signatures. - [ ] `simplex init` and `simplex clean` tasks. - [ ] Proper installation scripts.