diff --git a/Cargo.toml b/Cargo.toml index 599e8072..bb24548f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "magical-bitcoin-wallet" +name = "magical" version = "0.1.0" edition = "2018" authors = ["Alekos Filini ", "Riccardo Casatta "] diff --git a/examples/address_validator.rs b/examples/address_validator.rs index 3e576c08..0b2c72d8 100644 --- a/examples/address_validator.rs +++ b/examples/address_validator.rs @@ -24,12 +24,12 @@ use std::sync::Arc; -use magical_bitcoin_wallet::bitcoin; -use magical_bitcoin_wallet::database::MemoryDatabase; -use magical_bitcoin_wallet::descriptor::HDKeyPaths; -use magical_bitcoin_wallet::wallet::address_validator::{AddressValidator, AddressValidatorError}; -use magical_bitcoin_wallet::ScriptType; -use magical_bitcoin_wallet::{OfflineWallet, Wallet}; +use magical::bitcoin; +use magical::database::MemoryDatabase; +use magical::descriptor::HDKeyPaths; +use magical::wallet::address_validator::{AddressValidator, AddressValidatorError}; +use magical::ScriptType; +use magical::{OfflineWallet, Wallet}; use bitcoin::hashes::hex::FromHex; use bitcoin::util::bip32::Fingerprint; @@ -57,7 +57,7 @@ impl AddressValidator for DummyValidator { } } -fn main() -> Result<(), magical_bitcoin_wallet::Error> { +fn main() -> Result<(), magical::Error> { let descriptor = "sh(and_v(v:pk(tpubDDpWvmUrPZrhSPmUzCMBHffvC3HyMAPnWDSAQNBTnj1iZeJa7BZQEttFiP4DS4GCcXQHezdXhn86Hj6LHX5EDstXPWrMaSneRWM8yUf6NFd/*),after(630000)))"; let mut wallet: OfflineWallet<_> = Wallet::new_offline(descriptor, None, Network::Regtest, MemoryDatabase::new())?; diff --git a/examples/compiler.rs b/examples/compiler.rs index 874fc4b9..d1f9c332 100644 --- a/examples/compiler.rs +++ b/examples/compiler.rs @@ -25,7 +25,7 @@ extern crate bitcoin; extern crate clap; extern crate log; -extern crate magical_bitcoin_wallet; +extern crate magical; extern crate miniscript; extern crate serde_json; @@ -39,8 +39,8 @@ use bitcoin::Network; use miniscript::policy::Concrete; use miniscript::Descriptor; -use magical_bitcoin_wallet::database::memory::MemoryDatabase; -use magical_bitcoin_wallet::{OfflineWallet, ScriptType, Wallet}; +use magical::database::memory::MemoryDatabase; +use magical::{OfflineWallet, ScriptType, Wallet}; fn main() { env_logger::init_from_env( diff --git a/examples/parse_descriptor.rs b/examples/parse_descriptor.rs index 9542a3d5..bd34de8b 100644 --- a/examples/parse_descriptor.rs +++ b/examples/parse_descriptor.rs @@ -22,14 +22,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -extern crate magical_bitcoin_wallet; +extern crate magical; extern crate serde_json; use std::sync::Arc; -use magical_bitcoin_wallet::bitcoin::util::bip32::ChildNumber; -use magical_bitcoin_wallet::bitcoin::*; -use magical_bitcoin_wallet::descriptor::*; +use magical::bitcoin::util::bip32::ChildNumber; +use magical::bitcoin::*; +use magical::descriptor::*; fn main() { let desc = "wsh(or_d(\ diff --git a/examples/repl.rs b/examples/repl.rs index 2756d2d4..3546fca9 100644 --- a/examples/repl.rs +++ b/examples/repl.rs @@ -36,11 +36,11 @@ use log::{debug, error, info, trace, LevelFilter}; use bitcoin::Network; -use magical_bitcoin_wallet::bitcoin; -use magical_bitcoin_wallet::blockchain::compact_filters::*; -use magical_bitcoin_wallet::cli; -use magical_bitcoin_wallet::sled; -use magical_bitcoin_wallet::Wallet; +use magical::bitcoin; +use magical::blockchain::compact_filters::*; +use magical::cli; +use magical::sled; +use magical::Wallet; fn prepare_home_dir() -> PathBuf { let mut dir = PathBuf::new(); diff --git a/src/blockchain/compact_filters/mod.rs b/src/blockchain/compact_filters/mod.rs index ab775198..e5561ee9 100644 --- a/src/blockchain/compact_filters/mod.rs +++ b/src/blockchain/compact_filters/mod.rs @@ -42,8 +42,8 @@ //! ```no_run //! # use std::sync::Arc; //! # use bitcoin::*; -//! # use magical_bitcoin_wallet::*; -//! # use magical_bitcoin_wallet::blockchain::compact_filters::*; +//! # use magical::*; +//! # use magical::blockchain::compact_filters::*; //! let num_threads = 4; //! //! let mempool = Arc::new(Mempool::default()); @@ -55,7 +55,7 @@ //! )) //! .collect::>()?; //! let blockchain = CompactFiltersBlockchain::new(peers, "./wallet-filters", Some(500_000))?; -//! # Ok::<(), magical_bitcoin_wallet::error::Error>(()) +//! # Ok::<(), magical::error::Error>(()) //! ``` use std::collections::HashSet; diff --git a/src/blockchain/electrum.rs b/src/blockchain/electrum.rs index a46c7f83..0f877467 100644 --- a/src/blockchain/electrum.rs +++ b/src/blockchain/electrum.rs @@ -31,10 +31,10 @@ //! ## Example //! //! ```no_run -//! # use magical_bitcoin_wallet::blockchain::electrum::ElectrumBlockchain; +//! # use magical::blockchain::electrum::ElectrumBlockchain; //! let client = electrum_client::Client::new("ssl://electrum.blockstream.info:50002", None)?; //! let blockchain = ElectrumBlockchain::from(client); -//! # Ok::<(), magical_bitcoin_wallet::Error>(()) +//! # Ok::<(), magical::Error>(()) //! ``` use std::collections::HashSet; diff --git a/src/blockchain/esplora.rs b/src/blockchain/esplora.rs index 999a131e..be83bbde 100644 --- a/src/blockchain/esplora.rs +++ b/src/blockchain/esplora.rs @@ -30,9 +30,9 @@ //! ## Example //! //! ```no_run -//! # use magical_bitcoin_wallet::blockchain::esplora::EsploraBlockchain; +//! # use magical::blockchain::esplora::EsploraBlockchain; //! let blockchain = EsploraBlockchain::new("https://blockstream.info/testnet/"); -//! # Ok::<(), magical_bitcoin_wallet::Error>(()) +//! # Ok::<(), magical::Error>(()) //! ``` use std::collections::{HashMap, HashSet}; diff --git a/src/descriptor/policy.rs b/src/descriptor/policy.rs index 7158701d..479454e6 100644 --- a/src/descriptor/policy.rs +++ b/src/descriptor/policy.rs @@ -31,7 +31,7 @@ //! //! ``` //! # use std::sync::Arc; -//! # use magical_bitcoin_wallet::descriptor::*; +//! # use magical::descriptor::*; //! let desc = "wsh(and_v(v:pk(cV3oCth6zxZ1UVsHLnGothsWNsaoxRhC6aeNi5VbSdFpwUkgkEci),or_d(pk(cVMTy7uebJgvFaSBwcgvwk8qn8xSLc97dKow4MBetjrrahZoimm2),older(12960))))"; //! //! let (extended_desc, key_map) = ExtendedDescriptor::parse_secret(desc)?; @@ -40,7 +40,7 @@ //! let signers = Arc::new(key_map.into()); //! let policy = extended_desc.extract_policy(signers)?; //! println!("policy: {}", serde_json::to_string(&policy)?); -//! # Ok::<(), magical_bitcoin_wallet::Error>(()) +//! # Ok::<(), magical::Error>(()) //! ``` use std::cmp::max; diff --git a/src/wallet/address_validator.rs b/src/wallet/address_validator.rs index d83699c2..a88feaed 100644 --- a/src/wallet/address_validator.rs +++ b/src/wallet/address_validator.rs @@ -42,9 +42,9 @@ //! ``` //! # use std::sync::Arc; //! # use bitcoin::*; -//! # use magical_bitcoin_wallet::address_validator::*; -//! # use magical_bitcoin_wallet::database::*; -//! # use magical_bitcoin_wallet::*; +//! # use magical::address_validator::*; +//! # use magical::database::*; +//! # use magical::*; //! struct PrintAddressAndContinue; //! //! impl AddressValidator for PrintAddressAndContinue { @@ -71,7 +71,7 @@ //! //! let address = wallet.get_new_address()?; //! println!("Address: {}", address); -//! # Ok::<(), magical_bitcoin_wallet::Error>(()) +//! # Ok::<(), magical::Error>(()) //! ``` use std::fmt; diff --git a/src/wallet/coin_selection.rs b/src/wallet/coin_selection.rs index ab294d6c..e37a5ef8 100644 --- a/src/wallet/coin_selection.rs +++ b/src/wallet/coin_selection.rs @@ -43,8 +43,8 @@ //! # use std::str::FromStr; //! # use bitcoin::*; //! # use bitcoin::consensus::serialize; -//! # use magical_bitcoin_wallet::wallet::coin_selection::*; -//! # use magical_bitcoin_wallet::*; +//! # use magical::wallet::coin_selection::*; +//! # use magical::*; //! #[derive(Debug)] //! struct AlwaysSpendEverything; //! @@ -57,7 +57,7 @@ //! amount_needed: u64, //! input_witness_weight: usize, //! fee_amount: f32, -//! ) -> Result { +//! ) -> Result { //! let selected_amount = utxos.iter().fold(0, |acc, utxo| acc + utxo.txout.value); //! let all_utxos_selected = utxos //! .into_iter() @@ -77,7 +77,7 @@ //! let additional_fees = additional_weight as f32 * fee_rate.as_sat_vb() / 4.0; //! //! if (fee_amount + additional_fees).ceil() as u64 + amount_needed > selected_amount { -//! return Err(magical_bitcoin_wallet::Error::InsufficientFunds); +//! return Err(magical::Error::InsufficientFunds); //! } //! //! Ok(CoinSelectionResult { @@ -88,7 +88,7 @@ //! } //! } //! -//! # let wallet: OfflineWallet<_> = Wallet::new_offline("", None, Network::Testnet, magical_bitcoin_wallet::database::MemoryDatabase::default())?; +//! # let wallet: OfflineWallet<_> = Wallet::new_offline("", None, Network::Testnet, magical::database::MemoryDatabase::default())?; //! // create wallet, sync, ... //! //! let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap(); @@ -99,7 +99,7 @@ //! //! // inspect, sign, broadcast, ... //! -//! # Ok::<(), magical_bitcoin_wallet::Error>(()) +//! # Ok::<(), magical::Error>(()) //! ``` use bitcoin::consensus::encode::serialize; diff --git a/src/wallet/export.rs b/src/wallet/export.rs index 7d3d48fa..2df89bbe 100644 --- a/src/wallet/export.rs +++ b/src/wallet/export.rs @@ -33,9 +33,9 @@ //! ``` //! # use std::str::FromStr; //! # use bitcoin::*; -//! # use magical_bitcoin_wallet::database::*; -//! # use magical_bitcoin_wallet::wallet::export::*; -//! # use magical_bitcoin_wallet::*; +//! # use magical::database::*; +//! # use magical::wallet::export::*; +//! # use magical::*; //! let import = r#"{ //! "descriptor": "wpkh([c258d2e4\/84h\/1h\/0h]tpubDD3ynpHgJQW8VvWRzQ5WFDCrs4jqVFGHB3vLC3r49XHJSqP8bHKdK4AriuUKLccK68zfzowx7YhmDN8SiSkgCDENUFx9qVw65YyqM78vyVe\/0\/*)", //! "blockheight":1782088, @@ -44,15 +44,15 @@ //! //! let import = WalletExport::from_str(import)?; //! let wallet: OfflineWallet<_> = Wallet::new_offline(&import.descriptor(), import.change_descriptor().as_deref(), Network::Testnet, MemoryDatabase::default())?; -//! # Ok::<_, magical_bitcoin_wallet::Error>(()) +//! # Ok::<_, magical::Error>(()) //! ``` //! //! ### Export a `Wallet` //! ``` //! # use bitcoin::*; -//! # use magical_bitcoin_wallet::database::*; -//! # use magical_bitcoin_wallet::wallet::export::*; -//! # use magical_bitcoin_wallet::*; +//! # use magical::database::*; +//! # use magical::wallet::export::*; +//! # use magical::*; //! let wallet: OfflineWallet<_> = Wallet::new_offline( //! "wpkh([c258d2e4/84h/1h/0h]tpubDD3ynpHgJQW8VvWRzQ5WFDCrs4jqVFGHB3vLC3r49XHJSqP8bHKdK4AriuUKLccK68zfzowx7YhmDN8SiSkgCDENUFx9qVw65YyqM78vyVe/0/*)", //! Some("wpkh([c258d2e4/84h/1h/0h]tpubDD3ynpHgJQW8VvWRzQ5WFDCrs4jqVFGHB3vLC3r49XHJSqP8bHKdK4AriuUKLccK68zfzowx7YhmDN8SiSkgCDENUFx9qVw65YyqM78vyVe/1/*)"), @@ -61,10 +61,10 @@ //! )?; //! let export = WalletExport::export_wallet(&wallet, "exported wallet", true) //! .map_err(ToString::to_string) -//! .map_err(magical_bitcoin_wallet::Error::Generic)?; +//! .map_err(magical::Error::Generic)?; //! //! println!("Exported: {}", export.to_string()); -//! # Ok::<_, magical_bitcoin_wallet::Error>(()) +//! # Ok::<_, magical::Error>(()) //! ``` use std::str::FromStr; diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 1dfe6018..48f5599f 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -229,8 +229,8 @@ where /// ```no_run /// # use std::str::FromStr; /// # use bitcoin::*; - /// # use magical_bitcoin_wallet::*; - /// # use magical_bitcoin_wallet::database::*; + /// # use magical::*; + /// # use magical::database::*; /// # let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)"; /// # let wallet: OfflineWallet<_> = Wallet::new_offline(descriptor, None, Network::Testnet, MemoryDatabase::default())?; /// # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap(); @@ -238,7 +238,7 @@ where /// TxBuilder::with_recipients(vec![(to_address.script_pubkey(), 50_000)]) /// )?; /// // sign and broadcast ... - /// # Ok::<(), magical_bitcoin_wallet::Error>(()) + /// # Ok::<(), magical::Error>(()) /// ``` pub fn create_tx( &self, @@ -453,8 +453,8 @@ where /// ```no_run /// # use std::str::FromStr; /// # use bitcoin::*; - /// # use magical_bitcoin_wallet::*; - /// # use magical_bitcoin_wallet::database::*; + /// # use magical::*; + /// # use magical::database::*; /// # let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)"; /// # let wallet: OfflineWallet<_> = Wallet::new_offline(descriptor, None, Network::Testnet, MemoryDatabase::default())?; /// let txid = Txid::from_str("faff0a466b70f5d5f92bd757a92c1371d4838bdd5bc53a06764e2488e51ce8f8").unwrap(); @@ -463,7 +463,7 @@ where /// TxBuilder::new().fee_rate(FeeRate::from_sat_per_vb(5.0)), /// )?; /// // sign and broadcast ... - /// # Ok::<(), magical_bitcoin_wallet::Error>(()) + /// # Ok::<(), magical::Error>(()) /// ``` // TODO: support for merging multiple transactions while bumping the fees // TODO: option to force addition of an extra output? seems bad for privacy to update the @@ -691,13 +691,13 @@ where /// ```no_run /// # use std::str::FromStr; /// # use bitcoin::*; - /// # use magical_bitcoin_wallet::*; - /// # use magical_bitcoin_wallet::database::*; + /// # use magical::*; + /// # use magical::database::*; /// # let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)"; /// # let wallet: OfflineWallet<_> = Wallet::new_offline(descriptor, None, Network::Testnet, MemoryDatabase::default())?; /// # let (psbt, _) = wallet.create_tx(TxBuilder::new())?; /// let (signed_psbt, finalized) = wallet.sign(psbt, None)?; - /// # Ok::<(), magical_bitcoin_wallet::Error>(()) + /// # Ok::<(), magical::Error>(()) pub fn sign(&self, mut psbt: PSBT, assume_height: Option) -> Result<(PSBT, bool), Error> { // this helps us doing our job later self.add_input_hd_keypaths(&mut psbt)?; diff --git a/src/wallet/signer.rs b/src/wallet/signer.rs index c90afafb..838fd74f 100644 --- a/src/wallet/signer.rs +++ b/src/wallet/signer.rs @@ -33,9 +33,9 @@ //! # use bitcoin::*; //! # use bitcoin::util::psbt; //! # use bitcoin::util::bip32::Fingerprint; -//! # use magical_bitcoin_wallet::signer::*; -//! # use magical_bitcoin_wallet::database::*; -//! # use magical_bitcoin_wallet::*; +//! # use magical::signer::*; +//! # use magical::database::*; +//! # use magical::*; //! # #[derive(Debug)] //! # struct CustomHSM; //! # impl CustomHSM { @@ -85,7 +85,7 @@ //! Arc::new(Box::new(custom_signer)) //! ); //! -//! # Ok::<_, magical_bitcoin_wallet::Error>(()) +//! # Ok::<_, magical::Error>(()) //! ``` use std::cmp::Ordering; diff --git a/src/wallet/tx_builder.rs b/src/wallet/tx_builder.rs index 1f3d421f..5dc88803 100644 --- a/src/wallet/tx_builder.rs +++ b/src/wallet/tx_builder.rs @@ -29,7 +29,7 @@ //! ``` //! # use std::str::FromStr; //! # use bitcoin::*; -//! # use magical_bitcoin_wallet::*; +//! # use magical::*; //! # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap(); //! // Create a transaction with one output to `to_address` of 50_000 satoshi, with a custom fee rate //! // of 5.0 satoshi/vbyte, only spending non-change outputs and with RBF signaling diff --git a/testutils-macros/src/lib.rs b/testutils-macros/src/lib.rs index 6242f760..cf8fe424 100644 --- a/testutils-macros/src/lib.rs +++ b/testutils-macros/src/lib.rs @@ -44,7 +44,7 @@ pub fn magical_blockchain_tests(attr: TokenStream, item: TokenStream) -> TokenSt } } } else { - parse2::(quote! { magical_bitcoin_wallet }).unwrap() + parse2::(quote! { magical }).unwrap() }; match parse::(item) {