]> Untitled Git - bdk/commitdiff
Make bdk no_std
authorLLFourn <lloyd.fourn@gmail.com>
Tue, 10 Jan 2023 04:10:02 +0000 (15:10 +1100)
committerDaniela Brozzoni <danielabrozzoni@protonmail.com>
Thu, 2 Mar 2023 09:55:09 +0000 (10:55 +0100)
20 files changed:
Cargo.toml
bdk_test_client/src/lib.rs
src/descriptor/checksum.rs
src/descriptor/dsl.rs
src/descriptor/error.rs
src/descriptor/mod.rs
src/descriptor/policy.rs
src/descriptor/template.rs
src/error.rs
src/keys/bip39.rs
src/keys/mod.rs
src/lib.rs
src/psbt/mod.rs
src/types.rs
src/wallet/coin_selection.rs
src/wallet/export.rs
src/wallet/mod.rs
src/wallet/signer.rs
src/wallet/tx_builder.rs
src/wallet/utils.rs

index bda2d3ebcb93335ca45573bb0bf92ff806d700ea..22a42590f65f31d9b53bbdcd7669b67adb99e10e 100644 (file)
@@ -35,6 +35,8 @@ getrandom = "0.2"
 js-sys = "0.3"
 
 [features]
+default = ["std"]
+std = []
 compiler = ["miniscript/compiler"]
 all-keys = ["keys-bip39"]
 keys-bip39 = ["bip39"]
@@ -66,6 +68,7 @@ required-features = ["compiler"]
 [[example]]
 name = "policy"
 path = "examples/policy.rs"
+required-features = ["std"]
 
 [[example]]
 name = "mnemonic_to_descriptors"
index aebcb4577884946f68085830506ddcc277c1058e..6ae446bf2f792b99eae245ec8292287044f168ca 100644 (file)
@@ -5,15 +5,15 @@ use bitcoin::{Address, PackedLockTime, Script, Sequence, Transaction, Txid, Witn
 pub use bitcoincore_rpc::bitcoincore_rpc_json::AddressType;
 use bitcoincore_rpc::jsonrpc::serde_json::{self, json};
 pub use bitcoincore_rpc::{Auth, Client as RpcClient, Error as RpcError, RpcApi};
+use core::ops::Deref;
 use core::str::FromStr;
+use core::time::Duration;
 use electrsd::bitcoind::BitcoinD;
 use electrsd::{bitcoind, ElectrsD};
 pub use electrum_client::{Client as ElectrumClient, ElectrumApi};
 #[allow(unused_imports)]
 use log::{debug, error, info, log_enabled, trace, Level};
 use std::env;
-use std::ops::Deref;
-use std::time::Duration;
 
 pub struct TestClient {
     pub bitcoind: BitcoinD,
index b4ba0e8ff78a8ea7e9c71d05d8226d0c8cf372a1..07120ab7d443808cdf4ca0f8f492e8260bc040ea 100644 (file)
@@ -15,6 +15,7 @@
 //! checksum of a descriptor
 
 use crate::descriptor::DescriptorError;
+use alloc::string::String;
 
 const INPUT_CHARSET: &[u8] = b"0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ";
 const CHECKSUM_CHARSET: &[u8] = b"qpzry9x8gf2tvdw0s3jn54khce6mua7l";
@@ -170,7 +171,7 @@ mod test {
 
     #[test]
     fn test_calc_checksum_invalid_character() {
-        let sparkle_heart = unsafe { std::str::from_utf8_unchecked(&[240, 159, 146, 150]) };
+        let sparkle_heart = unsafe { core::str::from_utf8_unchecked(&[240, 159, 146, 150]) };
         let invalid_desc = format!("wpkh(tprv8ZgxMBicQKsPdpkqS7Eair4YxjcuuvDPNYmKX3sCniCf16tHEVrjjiSXEkFRnUH77yXc6ZcwHHcL{}fjdi5qUvw3VDfgYiH5mNsj5izuiu2N/1/2/*)", sparkle_heart);
 
         assert_matches!(
index 67ef67057ffee7cbdf48e18030b7fbf72828b867..fdd78a46d4f7d117163a88c945d7a9661d69d362 100644 (file)
@@ -23,7 +23,7 @@ macro_rules! impl_top_level_sh {
     };
 
     ( $inner_struct:ident, $constructor:ident, $sortedmulti_constructor:ident, $ctx:ident, sortedmulti $( $inner:tt )* ) => {{
-        use std::marker::PhantomData;
+        use core::marker::PhantomData;
 
         use $crate::miniscript::descriptor::{$inner_struct, Descriptor, DescriptorPublicKey};
         use $crate::miniscript::$ctx;
@@ -35,7 +35,7 @@ macro_rules! impl_top_level_sh {
         $crate::impl_sortedmulti!(build_desc, sortedmulti $( $inner )*)
     }};
     ( $inner_struct:ident, $constructor:ident, $sortedmulti_constructor:ident, $ctx:ident, sortedmulti_vec $( $inner:tt )* ) => {{
-        use std::marker::PhantomData;
+        use core::marker::PhantomData;
 
         use $crate::miniscript::descriptor::{$inner_struct, Descriptor, DescriptorPublicKey};
         use $crate::miniscript::$ctx;
@@ -203,8 +203,8 @@ macro_rules! impl_node_opcode_two {
                 a_keymap.extend(b_keymap.into_iter());
 
                 let minisc = $crate::miniscript::Miniscript::from_ast($crate::miniscript::miniscript::decode::Terminal::$terminal_variant(
-                    std::sync::Arc::new(a_minisc),
-                    std::sync::Arc::new(b_minisc),
+                    alloc::sync::Arc::new(a_minisc),
+                    alloc::sync::Arc::new(b_minisc),
                 ))?;
 
                 minisc.check_miniscript()?;
@@ -234,9 +234,9 @@ macro_rules! impl_node_opcode_three {
                 let networks = $crate::keys::merge_networks(&networks, &c_networks);
 
                 let minisc = $crate::miniscript::Miniscript::from_ast($crate::miniscript::miniscript::decode::Terminal::$terminal_variant(
-                    std::sync::Arc::new(a_minisc),
-                    std::sync::Arc::new(b_minisc),
-                    std::sync::Arc::new(c_minisc),
+                    alloc::sync::Arc::new(a_minisc),
+                    alloc::sync::Arc::new(b_minisc),
+                    alloc::sync::Arc::new(c_minisc),
                 ))?;
 
                 minisc.check_miniscript()?;
@@ -263,7 +263,7 @@ macro_rules! impl_sortedmulti {
             )*
         ];
 
-        keys.into_iter().collect::<Result<Vec<_>, _>>()
+        keys.into_iter().collect::<Result<alloc::vec::Vec<_>, _>>()
             .map_err($crate::descriptor::DescriptorError::Key)
             .and_then(|keys| $crate::keys::make_sortedmulti($thresh, keys, $build_desc, &secp))
     });
@@ -274,7 +274,7 @@ macro_rules! impl_sortedmulti {
 #[macro_export]
 macro_rules! parse_tap_tree {
     ( @merge $tree_a:expr, $tree_b:expr) => {{
-        use std::sync::Arc;
+        use alloc::sync::Arc;
         use $crate::miniscript::descriptor::TapTree;
 
         $tree_a
@@ -318,7 +318,7 @@ macro_rules! parse_tap_tree {
 
     // Single leaf
     ( $op:ident ( $( $minisc:tt )* ) ) => {{
-        use std::sync::Arc;
+        use alloc::sync::Arc;
         use $crate::miniscript::descriptor::TapTree;
 
         $crate::fragment!( $op ( $( $minisc )* ) )
@@ -337,7 +337,7 @@ macro_rules! apply_modifier {
             .and_then(|(minisc, keymap, networks)| {
                 let minisc = $crate::miniscript::Miniscript::from_ast(
                     $crate::miniscript::miniscript::decode::Terminal::$terminal_variant(
-                        std::sync::Arc::new(minisc),
+                        alloc::sync::Arc::new(minisc),
                     ),
                 )?;
 
@@ -374,8 +374,8 @@ macro_rules! apply_modifier {
         $inner.and_then(|(a_minisc, a_keymap, a_networks)| {
             $crate::impl_leaf_opcode_value_two!(
                 AndV,
-                std::sync::Arc::new(a_minisc),
-                std::sync::Arc::new($crate::fragment!(true).unwrap().0)
+                alloc::sync::Arc::new(a_minisc),
+                alloc::sync::Arc::new($crate::fragment!(true).unwrap().0)
             )
             .map(|(minisc, _, _)| (minisc, a_keymap, a_networks))
         })
@@ -384,8 +384,8 @@ macro_rules! apply_modifier {
         $inner.and_then(|(a_minisc, a_keymap, a_networks)| {
             $crate::impl_leaf_opcode_value_two!(
                 OrI,
-                std::sync::Arc::new($crate::fragment!(false).unwrap().0),
-                std::sync::Arc::new(a_minisc)
+                alloc::sync::Arc::new($crate::fragment!(false).unwrap().0),
+                alloc::sync::Arc::new(a_minisc)
             )
             .map(|(minisc, _, _)| (minisc, a_keymap, a_networks))
         })
@@ -394,8 +394,8 @@ macro_rules! apply_modifier {
         $inner.and_then(|(a_minisc, a_keymap, a_networks)| {
             $crate::impl_leaf_opcode_value_two!(
                 OrI,
-                std::sync::Arc::new(a_minisc),
-                std::sync::Arc::new($crate::fragment!(false).unwrap().0)
+                alloc::sync::Arc::new(a_minisc),
+                alloc::sync::Arc::new($crate::fragment!(false).unwrap().0)
             )
             .map(|(minisc, _, _)| (minisc, a_keymap, a_networks))
         })
@@ -599,7 +599,7 @@ macro_rules! group_multi_keys {
             )*
         ];
 
-        keys.into_iter().collect::<Result<Vec<_>, _>>()
+        keys.into_iter().collect::<Result<alloc::vec::Vec<_>, _>>()
             .map_err($crate::descriptor::DescriptorError::Key)
     }};
 }
@@ -744,8 +744,8 @@ macro_rules! fragment {
     ( thresh_vec ( $thresh:expr, $items:expr ) ) => ({
         use $crate::miniscript::descriptor::KeyMap;
 
-        let (items, key_maps_networks): (Vec<_>, Vec<_>) = $items.into_iter().map(|(a, b, c)| (a, (b, c))).unzip();
-        let items = items.into_iter().map(std::sync::Arc::new).collect();
+        let (items, key_maps_networks): (alloc::vec::Vec<_>, alloc::vec::Vec<_>) = $items.into_iter().map(|(a, b, c)| (a, (b, c))).unzip();
+        let items = items.into_iter().map(alloc::sync::Arc::new).collect();
 
         let (key_maps, valid_networks) = key_maps_networks.into_iter().fold((KeyMap::default(), $crate::keys::any_network()), |(mut keys_acc, net_acc), (key, net)| {
             keys_acc.extend(key.into_iter());
@@ -760,7 +760,7 @@ macro_rules! fragment {
     ( thresh ( $thresh:expr, $( $inner:tt )* ) ) => ({
         let items = $crate::fragment_internal!( @v $( $inner )* );
 
-        items.into_iter().collect::<Result<Vec<_>, _>>()
+        items.into_iter().collect::<Result<alloc::vec::Vec<_>, _>>()
             .and_then(|items| $crate::fragment!(thresh_vec($thresh, items)))
     });
     ( multi_vec ( $thresh:expr, $keys:expr ) ) => ({
@@ -793,12 +793,13 @@ macro_rules! fragment {
 
 #[cfg(test)]
 mod test {
+    use alloc::string::ToString;
     use bitcoin::hashes::hex::ToHex;
     use bitcoin::secp256k1::Secp256k1;
     use miniscript::descriptor::{DescriptorPublicKey, KeyMap};
     use miniscript::{Descriptor, Legacy, Segwitv0};
 
-    use std::str::FromStr;
+    use core::str::FromStr;
 
     use crate::descriptor::{DescriptorError, DescriptorMeta};
     use crate::keys::{DescriptorKey, IntoDescriptorKey, ValidNetworks};
index d558c926c19e20946b53abce312fa0f544edb8d6..83efb01a3b8aa674a08f87ab7ae60027dbff2c47 100644 (file)
@@ -76,6 +76,7 @@ impl std::fmt::Display for Error {
     }
 }
 
+#[cfg(feature = "std")]
 impl std::error::Error for Error {}
 
 impl_error!(bitcoin::util::bip32::Error, Bip32);
index dd53f9f910ca3ded91b65ace459c7a4df3a1a93c..295135f600e299c76ec478f00e7819732e5a699e 100644 (file)
@@ -14,7 +14,9 @@
 //! This module contains generic utilities to work with descriptors, plus some re-exported types
 //! from [`miniscript`].
 
-use std::collections::BTreeMap;
+use crate::collections::BTreeMap;
+use alloc::string::String;
+use alloc::vec::Vec;
 
 use bitcoin::util::bip32::{ChildNumber, DerivationPath, ExtendedPubKey, Fingerprint, KeySource};
 use bitcoin::util::{psbt, taproot};
@@ -581,7 +583,8 @@ impl DescriptorMeta for ExtendedDescriptor {
 
 #[cfg(test)]
 mod test {
-    use std::str::FromStr;
+    use alloc::string::ToString;
+    use core::str::FromStr;
 
     use assert_matches::assert_matches;
     use bitcoin::consensus::encode::deserialize;
index 6923ce3fb50c06f64d0c733cf664f89acb62f3d3..96889ffa0be9adf95082be7c0246762d989670c3 100644 (file)
 //! # Ok::<(), bdk::Error>(())
 //! ```
 
-use std::cmp::max;
-use std::collections::{BTreeMap, HashSet, VecDeque};
-use std::fmt;
+use crate::collections::{BTreeMap, HashSet, VecDeque};
+use alloc::string::String;
+use alloc::vec::Vec;
+use core::cmp::max;
+use core::fmt;
 
 use serde::ser::SerializeMap;
 use serde::{Serialize, Serializer};
@@ -523,6 +525,7 @@ impl fmt::Display for PolicyError {
     }
 }
 
+#[cfg(feature = "std")]
 impl std::error::Error for PolicyError {}
 
 impl Policy {
@@ -1146,12 +1149,12 @@ mod test {
     use crate::descriptor::policy::SatisfiableItem::{EcdsaSignature, Multisig, Thresh};
     use crate::keys::{DescriptorKey, IntoDescriptorKey};
     use crate::wallet::signer::SignersContainer;
+    use alloc::{string::ToString, sync::Arc};
     use assert_matches::assert_matches;
     use bitcoin::secp256k1::Secp256k1;
     use bitcoin::util::bip32;
     use bitcoin::Network;
-    use std::str::FromStr;
-    use std::sync::Arc;
+    use core::str::FromStr;
 
     const TPRV0_STR:&str = "tprv8ZgxMBicQKsPdZXrcHNLf5JAJWFAoJ2TrstMRdSKtEggz6PddbuSkvHKM9oKJyFgZV1B7rw8oChspxyYbtmEXYyg1AjfWbL3ho3XHDpHRZf";
     const TPRV1_STR:&str = "tprv8ZgxMBicQKsPdpkqS7Eair4YxjcuuvDPNYmKX3sCniCf16tHEVrjjiSXEkFRnUH77yXc6ZcwHHcLNfjdi5qUvw3VDfgYiH5mNsj5izuiu2N";
@@ -1444,12 +1447,12 @@ mod test {
             .into_wallet_descriptor(&secp, Network::Testnet)
             .unwrap();
         let signers_container = Arc::new(SignersContainer::build(keymap, &wallet_desc, &secp));
-        let policy = wallet_desc
+        let _policy = wallet_desc
             .extract_policy(&signers_container, BuildSatisfaction::None, &secp)
             .unwrap()
             .unwrap();
-        println!("desc policy = {:?}", policy); // TODO remove
-                                                // TODO how should this fail with mixed timelocks?
+        // println!("desc policy = {:?}", policy); // TODO remove
+        // TODO how should this fail with mixed timelocks?
     }
 
     // - multiple timelocks of the same type should be correctly merged together
@@ -1469,12 +1472,12 @@ mod test {
             .into_wallet_descriptor(&secp, Network::Testnet)
             .unwrap();
         let signers_container = Arc::new(SignersContainer::build(keymap, &wallet_desc, &secp));
-        let policy = wallet_desc
+        let _policy = wallet_desc
             .extract_policy(&signers_container, BuildSatisfaction::None, &secp)
             .unwrap()
             .unwrap();
-        println!("desc policy = {:?}", policy); // TODO remove
-                                                // TODO how should this merge timelocks?
+        // println!("desc policy = {:?}", policy); // TODO remove
+        // TODO how should this merge timelocks?
         let (prvkey1, _pubkey1, _fingerprint1) = setup_keys(TPRV0_STR, PATH, &secp);
         let locktime_seconds0 = 500000100;
         let locktime_seconds1 = 500000200;
@@ -1487,12 +1490,12 @@ mod test {
             .into_wallet_descriptor(&secp, Network::Testnet)
             .unwrap();
         let signers_container = Arc::new(SignersContainer::build(keymap, &wallet_desc, &secp));
-        let policy = wallet_desc
+        let _policy = wallet_desc
             .extract_policy(&signers_container, BuildSatisfaction::None, &secp)
             .unwrap()
             .unwrap();
 
-        println!("desc policy = {:?}", policy); // TODO remove
+        // println!("desc policy = {:?}", policy); // TODO remove
 
         // TODO how should this merge timelocks?
     }
index 996c357aec1345409a9fad87623abb2db5c507f6..d6697becc0b07fec1f169ef5ecb6cd29a60e47c4 100644 (file)
@@ -418,7 +418,7 @@ macro_rules! expand_make_bipxx {
                 keychain: KeychainKind,
                 network: Network,
             ) -> Result<impl IntoDescriptorKey<$ctx>, DescriptorError> {
-                let mut derivation_path = Vec::with_capacity(4);
+                let mut derivation_path = alloc::vec::Vec::with_capacity(4);
                 derivation_path.push(bip32::ChildNumber::from_hardened_idx(bip)?);
 
                 match network {
@@ -478,7 +478,8 @@ expand_make_bipxx!(segwit_v0, Segwitv0);
 mod test {
     // test existing descriptor templates, make sure they are expanded to the right descriptors
 
-    use std::str::FromStr;
+    use alloc::{string::ToString, vec::Vec};
+    use core::str::FromStr;
 
     use super::*;
     use crate::descriptor::{DescriptorError, DescriptorMeta};
index 707a04333e1f712df85927c316b3e86bcbc393ee..8cb349a5b3608b2cc2547867e878d0f79b7972dc 100644 (file)
@@ -9,11 +9,11 @@
 // You may not use this file except in accordance with one or both of these
 // licenses.
 
-use std::fmt;
-
 use crate::bitcoin::Network;
 use crate::{descriptor, wallet};
+use alloc::{string::String, vec::Vec};
 use bitcoin::{OutPoint, Txid};
+use core::fmt;
 
 /// Errors that can be thrown by the [`Wallet`](crate::wallet::Wallet)
 #[derive(Debug)]
@@ -249,6 +249,7 @@ impl fmt::Display for Error {
     }
 }
 
+#[cfg(feature = "std")]
 impl std::error::Error for Error {}
 
 macro_rules! impl_error {
@@ -256,7 +257,7 @@ macro_rules! impl_error {
         impl_error!($from, $to, Error);
     };
     ( $from:ty, $to:ident, $impl_for:ty ) => {
-        impl std::convert::From<$from> for $impl_for {
+        impl core::convert::From<$from> for $impl_for {
             fn from(err: $from) -> Self {
                 <$impl_for>::$to(err)
             }
index c79683acf04d1bd810e383cf9120494ceff05cd3..78f544934ffe035d8b7759cbfa87f58f69747af2 100644 (file)
@@ -14,6 +14,7 @@
 // TODO: maybe write our own implementation of bip39? Seems stupid to have an extra dependency for
 // something that should be fairly simple to re-implement.
 
+use alloc::string::String;
 use bitcoin::util::bip32;
 use bitcoin::Network;
 
@@ -150,7 +151,8 @@ impl<Ctx: ScriptContext> GeneratableKey<Ctx> for Mnemonic {
 
 #[cfg(test)]
 mod test {
-    use std::str::FromStr;
+    use alloc::string::ToString;
+    use core::str::FromStr;
 
     use bitcoin::util::bip32;
 
index 84c447fe07ebfee1a10745d02c0510130fe04665..0f5e386e74cfeca445e4bf8a83d404c0aefc0777 100644 (file)
 
 //! Key formats
 
-use std::any::TypeId;
-use std::collections::HashSet;
-use std::marker::PhantomData;
-use std::ops::Deref;
-use std::str::FromStr;
+use crate::collections::HashSet;
+use alloc::string::{String, ToString};
+use alloc::vec::Vec;
+use core::any::TypeId;
+use core::marker::PhantomData;
+use core::ops::Deref;
+use core::str::FromStr;
 
 use bitcoin::secp256k1::{self, Secp256k1, Signing};
 
@@ -277,7 +279,7 @@ impl<Ctx: ScriptContext + 'static> ExtScriptContext for Ctx {
 ///
 /// ```compile_fail
 /// use bdk::bitcoin::PublicKey;
-/// use std::str::FromStr;
+/// use core::str::FromStr;
 ///
 /// use bdk::keys::{DescriptorKey, IntoDescriptorKey, KeyError};
 ///
@@ -619,7 +621,7 @@ pub trait GeneratableKey<Ctx: ScriptContext>: Sized {
     /// Extra options required by the `generate_with_entropy`
     type Options;
     /// Returned error in case of failure
-    type Error: std::fmt::Debug;
+    type Error: core::fmt::Debug;
 
     /// Generate a key given the extra options and the entropy
     fn generate_with_entropy(
@@ -946,6 +948,7 @@ impl std::fmt::Display for KeyError {
     }
 }
 
+#[cfg(feature = "std")]
 impl std::error::Error for KeyError {}
 
 #[cfg(test)]
index 280001fc5bcfb07d98f01f007af138fd77c7341d..6a208919c0ddb3424ea9b7fc64182d28722e77e9 100644 (file)
@@ -8,7 +8,7 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
 // You may not use this file except in accordance with one or both of these
 // licenses.
-
+//
 // rustdoc will warn if there are missing docs
 #![warn(missing_docs)]
 // only enables the `doc_cfg` feature when
@@ -147,7 +147,7 @@ fn main() -> Result<(), bdk::Error> {
 //! ## Sign a transaction
 //!
 //! ```no_run
-//! use std::str::FromStr;
+//! use core::str::FromStr;
 //!
 //! use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
 //!
@@ -188,6 +188,14 @@ fn main() -> Result<(), bdk::Error> {
 //! * `keys-bip39`: [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic codes for generating deterministic keys
 //!
 
+#![no_std]
+#[cfg(feature = "std")]
+#[macro_use]
+extern crate std;
+
+#[macro_use]
+extern crate alloc;
+
 pub extern crate bitcoin;
 #[cfg(feature = "hardware-signer")]
 pub extern crate hwi;
@@ -225,3 +233,4 @@ pub fn version() -> &'static str {
 }
 
 pub use bdk_chain as chain;
+pub(crate) use bdk_chain::collections;
index 6f9860567e5558cc2fec263fda569226f740e080..62ef0a7937c43d9310663614c36aac1f38c9274e 100644 (file)
@@ -12,6 +12,7 @@
 //! Additional functions on the `rust-bitcoin` `PartiallySignedTransaction` structure.
 
 use crate::FeeRate;
+use alloc::vec::Vec;
 use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
 use bitcoin::TxOut;
 
@@ -85,7 +86,7 @@ mod test {
     use crate::wallet::AddressIndex;
     use crate::wallet::AddressIndex::New;
     use crate::{psbt, FeeRate, SignOptions};
-    use std::str::FromStr;
+    use core::str::FromStr;
 
     // from bip 174
     const PSBT_STR: &str = "cHNidP8BAKACAAAAAqsJSaCMWvfEm4IS9Bfi8Vqz9cM9zxU4IagTn4d6W3vkAAAAAAD+////qwlJoIxa98SbghL0F+LxWrP1wz3PFTghqBOfh3pbe+QBAAAAAP7///8CYDvqCwAAAAAZdqkUdopAu9dAy+gdmI5x3ipNXHE5ax2IrI4kAAAAAAAAGXapFG9GILVT+glechue4O/p+gOcykWXiKwAAAAAAAEHakcwRAIgR1lmF5fAGwNrJZKJSGhiGDR9iYZLcZ4ff89X0eURZYcCIFMJ6r9Wqk2Ikf/REf3xM286KdqGbX+EhtdVRs7tr5MZASEDXNxh/HupccC1AaZGoqg7ECy0OIEhfKaC3Ibi1z+ogpIAAQEgAOH1BQAAAAAXqRQ1RebjO4MsRwUPJNPuuTycA5SLx4cBBBYAFIXRNTfy4mVAWjTbr6nj3aAfuCMIAAAA";
index 47d1c2b8e3366d10cc292d723fdb819420e882c6..db33ed2243c7753132a29b93ddfe1f0fc3cfe828 100644 (file)
@@ -9,8 +9,9 @@
 // You may not use this file except in accordance with one or both of these
 // licenses.
 
-use std::convert::AsRef;
-use std::ops::Sub;
+use alloc::boxed::Box;
+use core::convert::AsRef;
+use core::ops::Sub;
 
 use bdk_chain::ConfirmationTime;
 use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxOut};
@@ -124,7 +125,7 @@ impl FeeRate {
     }
 }
 
-impl std::default::Default for FeeRate {
+impl Default for FeeRate {
     fn default() -> Self {
         FeeRate::default_min_relay_fee()
     }
@@ -249,13 +250,13 @@ pub struct TransactionDetails {
 }
 
 impl PartialOrd for TransactionDetails {
-    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
+    fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
         Some(self.cmp(other))
     }
 }
 
 impl Ord for TransactionDetails {
-    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+    fn cmp(&self, other: &Self) -> core::cmp::Ordering {
         self.confirmation_time
             .cmp(&other.confirmation_time)
             .then_with(|| self.txid.cmp(&other.txid))
@@ -287,8 +288,8 @@ impl Balance {
     }
 }
 
-impl std::fmt::Display for Balance {
-    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+impl core::fmt::Display for Balance {
+    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
         write!(
             f,
             "{{ immature: {}, trusted_pending: {}, untrusted_pending: {}, confirmed: {} }}",
@@ -297,7 +298,7 @@ impl std::fmt::Display for Balance {
     }
 }
 
-impl std::ops::Add for Balance {
+impl core::ops::Add for Balance {
     type Output = Self;
 
     fn add(self, other: Self) -> Self {
@@ -310,7 +311,7 @@ impl std::ops::Add for Balance {
     }
 }
 
-impl std::iter::Sum for Balance {
+impl core::iter::Sum for Balance {
     fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
         iter.fold(
             Balance {
index 7f2861cbac40c193b73260c7e576430930497e93..bfd1fe57992550a7a82651dbbae1225475ed7e3f 100644 (file)
@@ -99,16 +99,16 @@ use crate::wallet::utils::IsDust;
 use crate::WeightedUtxo;
 use crate::{error::Error, Utxo};
 
+use alloc::vec::Vec;
 use bitcoin::consensus::encode::serialize;
 use bitcoin::Script;
 
 #[cfg(test)]
 use assert_matches::assert_matches;
+use core::convert::TryInto;
 use rand::seq::SliceRandom;
 #[cfg(not(test))]
 use rand::thread_rng;
-#[cfg(test)]
-use std::convert::TryInto;
 
 /// Default coin selection algorithm used by [`TxBuilder`](super::tx_builder::TxBuilder) if not
 /// overridden
@@ -177,7 +177,7 @@ impl CoinSelectionResult {
 /// selection algorithm when it creates transactions.
 ///
 /// For an example see [this module](crate::wallet::coin_selection)'s documentation.
-pub trait CoinSelectionAlgorithm: std::fmt::Debug {
+pub trait CoinSelectionAlgorithm: core::fmt::Debug {
     /// Perform the coin selection
     ///
     /// - `database`: a reference to the wallet's database that can be used to lookup additional
@@ -695,7 +695,7 @@ impl BranchAndBoundCoinSelection {
 
 #[cfg(test)]
 mod test {
-    use std::str::FromStr;
+    use core::str::FromStr;
 
     use bdk_chain::ConfirmationTime;
     use bitcoin::{OutPoint, Script, TxOut};
index f5d552b2641a50591c7ed20555246c25b90e70d0..9db268eb9b4282dabbc2f5bd24b25e3f830fce92 100644 (file)
@@ -59,8 +59,9 @@
 //! # Ok::<_, bdk::Error>(())
 //! ```
 
-use std::str::FromStr;
+use core::str::FromStr;
 
+use alloc::string::{String, ToString};
 use bdk_chain::sparse_chain::ChainPosition;
 use serde::{Deserialize, Serialize};
 
@@ -217,7 +218,7 @@ impl FullyNodedExport {
 
 #[cfg(test)]
 mod test {
-    use std::str::FromStr;
+    use core::str::FromStr;
 
     use bdk_chain::{BlockId, ConfirmationTime};
     use bitcoin::hashes::Hash;
index 8e7e1198cf48aa82f06ddfa00a1a83763f508752..8884553efd419c25724ea687dfe7c5343e6215f8 100644 (file)
 //! Wallet
 //!
 //! This module defines the [`Wallet`] structure.
-use bdk_chain::chain_graph;
-use bdk_chain::{keychain::KeychainTracker, sparse_chain, BlockId, ConfirmationTime};
+use crate::collections::{BTreeMap, HashMap, HashSet};
+use alloc::{
+    boxed::Box,
+    string::{String, ToString},
+    sync::Arc,
+    vec::Vec,
+};
+use bdk_chain::{keychain::KeychainTracker, sparse_chain, BlockId, ConfirmationTime, chain_graph};
 use bitcoin::secp256k1::Secp256k1;
+use core::fmt;
+use core::ops::Deref;
 use core::convert::TryInto;
-use std::collections::{BTreeMap, HashMap, HashSet};
-use std::fmt;
-use std::ops::Deref;
-use std::sync::Arc;
 
 use bitcoin::consensus::encode::serialize;
 use bitcoin::util::psbt;
@@ -551,7 +555,7 @@ impl Wallet {
     /// [`TxBuilder`]: crate::TxBuilder
     pub fn build_tx(&mut self) -> TxBuilder<'_, DefaultCoinSelectionAlgorithm, CreateTx> {
         TxBuilder {
-            wallet: std::rc::Rc::new(core::cell::RefCell::new(self)),
+            wallet: alloc::rc::Rc::new(core::cell::RefCell::new(self)),
             params: TxParams::default(),
             coin_selection: DefaultCoinSelectionAlgorithm::default(),
             phantom: core::marker::PhantomData,
@@ -1067,7 +1071,7 @@ impl Wallet {
         };
 
         Ok(TxBuilder {
-            wallet: std::rc::Rc::new(std::cell::RefCell::new(self)),
+            wallet: alloc::rc::Rc::new(core::cell::RefCell::new(self)),
             params,
             coin_selection: DefaultCoinSelectionAlgorithm::default(),
             phantom: core::marker::PhantomData,
@@ -1846,7 +1850,7 @@ pub(crate) mod test {
 
     macro_rules! from_str {
         ($e:expr, $t:ty) => {{
-            use std::str::FromStr;
+            use core::str::FromStr;
             <$t>::from_str($e).unwrap()
         }};
 
@@ -2344,7 +2348,7 @@ pub(crate) mod test {
     #[test]
     fn test_create_tx_input_hd_keypaths() {
         use bitcoin::util::bip32::{DerivationPath, Fingerprint};
-        use std::str::FromStr;
+        use core::str::FromStr;
 
         let (mut wallet, _) = get_funded_wallet("wpkh([d34db33f/44'/0'/0']tpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)");
         let addr = wallet.get_address(New);
@@ -2365,7 +2369,7 @@ pub(crate) mod test {
     #[test]
     fn test_create_tx_output_hd_keypaths() {
         use bitcoin::util::bip32::{DerivationPath, Fingerprint};
-        use std::str::FromStr;
+        use core::str::FromStr;
 
         let (mut wallet, _) = get_funded_wallet("wpkh([d34db33f/44'/0'/0']tpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)");
 
@@ -4118,8 +4122,8 @@ pub(crate) mod test {
 
     #[test]
     fn test_get_address_no_reuse_single_descriptor() {
+        use crate::collections::HashSet;
         use crate::descriptor::template::Bip84;
-        use std::collections::HashSet;
 
         let key = bitcoin::util::bip32::ExtendedPrivKey::from_str("tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy").unwrap();
         let mut wallet =
index ff54cfa8a770f34b11ff0342fe39da4954716cae..51106d02e2896f9abb76348e9eb080e199d7b0f0 100644 (file)
@@ -15,8 +15,8 @@
 //! through the [`Wallet::add_signer`](super::Wallet::add_signer) function.
 //!
 //! ```
-//! # use std::sync::Arc;
-//! # use std::str::FromStr;
+//! # use alloc::sync::Arc;
+//! # use core::str::FromStr;
 //! # use bitcoin::secp256k1::{Secp256k1, All};
 //! # use bitcoin::*;
 //! # use bitcoin::util::psbt;
 //! # Ok::<_, bdk::Error>(())
 //! ```
 
-use std::cmp::Ordering;
-use std::collections::BTreeMap;
-use std::fmt;
-use std::ops::{Bound::Included, Deref};
-use std::sync::Arc;
+use crate::collections::BTreeMap;
+use alloc::sync::Arc;
+use alloc::vec::Vec;
+use core::cmp::Ordering;
+use core::fmt;
+use core::ops::{Bound::Included, Deref};
 
 use bitcoin::blockdata::opcodes;
 use bitcoin::blockdata::script::Builder as ScriptBuilder;
@@ -199,6 +200,7 @@ impl fmt::Display for SignerError {
     }
 }
 
+#[cfg(feature = "std")]
 impl std::error::Error for SignerError {}
 
 /// Signing context
@@ -560,7 +562,7 @@ fn sign_psbt_schnorr(
 #[derive(Debug, Clone, PartialOrd, PartialEq, Ord, Eq)]
 pub struct SignerOrdering(pub usize);
 
-impl std::default::Default for SignerOrdering {
+impl Default for SignerOrdering {
     fn default() -> Self {
         SignerOrdering(100)
     }
@@ -1017,8 +1019,8 @@ mod signers_container_tests {
     use bitcoin::secp256k1::{All, Secp256k1};
     use bitcoin::util::bip32;
     use bitcoin::Network;
+    use core::str::FromStr;
     use miniscript::ScriptContext;
-    use std::str::FromStr;
 
     fn is_equal(this: &Arc<dyn TransactionSigner>, that: &Arc<DummySigner>) -> bool {
         let secp = Secp256k1::new();
index 048336820d216ea54b9a2a49cd7ebc2907077c31..64212db84b4460e441d39dc7d84f6101aace517d 100644 (file)
 //! # Ok::<(), bdk::Error>(())
 //! ```
 
-use std::cell::RefCell;
-use std::collections::BTreeMap;
-use std::collections::HashSet;
-use std::default::Default;
-use std::marker::PhantomData;
-use std::rc::Rc;
+use crate::collections::BTreeMap;
+use crate::collections::HashSet;
+use alloc::{boxed::Box, rc::Rc, string::String, vec::Vec};
+use core::cell::RefCell;
+use core::marker::PhantomData;
 
 use bitcoin::util::psbt::{self, PartiallySignedTransaction as Psbt};
 use bitcoin::{LockTime, OutPoint, Script, Sequence, Transaction};
@@ -53,7 +52,7 @@ use crate::{
 };
 use crate::{Error, Utxo, Wallet};
 /// Context in which the [`TxBuilder`] is valid
-pub trait TxBuilderContext: std::fmt::Debug + Default + Clone {}
+pub trait TxBuilderContext: core::fmt::Debug + Default + Clone {}
 
 /// Marker type to indicate the [`TxBuilder`] is being used to create a new transaction (as opposed
 /// to bumping the fee of an existing one).
@@ -163,7 +162,7 @@ pub(crate) enum FeePolicy {
     FeeAmount(u64),
 }
 
-impl std::default::Default for FeePolicy {
+impl Default for FeePolicy {
     fn default() -> Self {
         FeePolicy::FeeRate(FeeRate::default_min_relay_fee())
     }
@@ -827,7 +826,7 @@ mod test {
 
     #[test]
     fn test_output_ordering_bip69() {
-        use std::str::FromStr;
+        use core::str::FromStr;
 
         let original_tx = ordering_test_tx!();
         let mut tx = original_tx;
index 163d417eef27fd5afe282376fd8c36e636150c0e..86f7d2fe42bb23999ebaad4c0c5e178ac0186a24 100644 (file)
@@ -120,7 +120,7 @@ mod test {
 
     use super::{check_nsequence_rbf, IsDust};
     use crate::bitcoin::{Address, Sequence};
-    use std::str::FromStr;
+    use core::str::FromStr;
 
     #[test]
     fn test_is_dust() {