Skip to content
Closed
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
17 changes: 8 additions & 9 deletions examples/address_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@

use std::sync::Arc;

use bdk::bitcoin;
use bdk::database::MemoryDatabase;
use bdk::descriptor::HDKeyPaths;
use bdk::wallet::address_validator::{AddressValidator, AddressValidatorError};
use bdk::KeychainKind;
use bdk::Wallet;
use bdk::{
bitcoin,
database::MemoryDatabase,
descriptor::HDKeyPaths,
wallet::address_validator::{AddressValidator, AddressValidatorError},
KeychainKind, Wallet,
};

use bitcoin::hashes::hex::FromHex;
use bitcoin::util::bip32::Fingerprint;
use bitcoin::{Network, Script};
use bitcoin::{hashes::hex::FromHex, util::bip32::Fingerprint, Network, Script};

#[derive(Debug)]
struct DummyValidator;
Expand Down
12 changes: 6 additions & 6 deletions examples/compact_filters_balance.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use bdk::blockchain::compact_filters::*;
use bdk::blockchain::noop_progress;
use bdk::database::MemoryDatabase;
use bdk::*;
use bdk::{
blockchain::{compact_filters::*, noop_progress},
database::MemoryDatabase,
*,
};
use bitcoin::*;
use blockchain::compact_filters::CompactFiltersBlockchain;
use blockchain::compact_filters::CompactFiltersError;
use blockchain::compact_filters::{CompactFiltersBlockchain, CompactFiltersError};
use log::info;
use std::sync::Arc;

Expand Down
9 changes: 3 additions & 6 deletions examples/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,16 @@ extern crate log;
extern crate miniscript;
extern crate serde_json;

use std::error::Error;
use std::str::FromStr;
use std::{error::Error, str::FromStr};

use log::info;

use clap::{App, Arg};

use bitcoin::Network;
use miniscript::policy::Concrete;
use miniscript::Descriptor;
use miniscript::{policy::Concrete, Descriptor};

use bdk::database::memory::MemoryDatabase;
use bdk::{KeychainKind, Wallet};
use bdk::{database::memory::MemoryDatabase, KeychainKind, Wallet};

fn main() -> Result<(), Box<dyn Error>> {
env_logger::init_from_env(
Expand Down
3 changes: 1 addition & 2 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ extern crate quote;

use proc_macro::TokenStream;

use syn::spanned::Spanned;
use syn::{parse, ImplItemMethod, ItemImpl, ItemTrait, Token};
use syn::{parse, spanned::Spanned, ImplItemMethod, ItemImpl, ItemTrait, Token};

fn add_async_trait(mut parsed: ItemTrait) -> TokenStream {
let output = quote! {
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
edition = "2018"
merge_imports = true
27 changes: 16 additions & 11 deletions src/blockchain/compact_filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,20 @@
//! # Ok::<(), CompactFiltersError>(())
//! ```

use std::collections::HashSet;
use std::fmt;
use std::path::Path;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
use std::{
collections::HashSet,
fmt,
path::Path,
sync::{
atomic::{AtomicUsize, Ordering},
Arc, Mutex,
},
};

#[allow(unused_imports)]
use log::{debug, error, info, trace};

use bitcoin::network::message_blockdata::Inventory;
use bitcoin::{Network, OutPoint, Transaction, Txid};
use bitcoin::{network::message_blockdata::Inventory, Network, OutPoint, Transaction, Txid};

use rocksdb::{Options, SliceTransform, DB};

Expand All @@ -81,10 +84,12 @@ mod store;
mod sync;

use super::{Blockchain, Capability, ConfigurableBlockchain, Progress};
use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils};
use crate::error::Error;
use crate::types::{KeychainKind, TransactionDetails, UTXO};
use crate::FeeRate;
use crate::{
database::{BatchDatabase, BatchOperations, DatabaseUtils},
error::Error,
types::{KeychainKind, TransactionDetails, UTXO},
FeeRate,
};

use peer::*;
use store::*;
Expand Down
36 changes: 21 additions & 15 deletions src/blockchain/compact_filters/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,32 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use std::collections::HashMap;
use std::net::{TcpStream, ToSocketAddrs};
use std::sync::{Arc, Condvar, Mutex, RwLock};
use std::thread;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use std::{
collections::HashMap,
net::{TcpStream, ToSocketAddrs},
sync::{Arc, Condvar, Mutex, RwLock},
thread,
time::{Duration, SystemTime, UNIX_EPOCH},
};

use socks::{Socks5Stream, ToTargetAddr};

use rand::{thread_rng, Rng};

use bitcoin::consensus::Encodable;
use bitcoin::hash_types::BlockHash;
use bitcoin::network::constants::ServiceFlags;
use bitcoin::network::message::{NetworkMessage, RawNetworkMessage};
use bitcoin::network::message_blockdata::*;
use bitcoin::network::message_filter::*;
use bitcoin::network::message_network::VersionMessage;
use bitcoin::network::stream_reader::StreamReader;
use bitcoin::network::Address;
use bitcoin::{Block, Network, Transaction, Txid, Wtxid};
use bitcoin::{
consensus::Encodable,
hash_types::BlockHash,
network::{
constants::ServiceFlags,
message::{NetworkMessage, RawNetworkMessage},
message_blockdata::*,
message_filter::*,
message_network::VersionMessage,
stream_reader::StreamReader,
Address,
},
Block, Network, Transaction, Txid, Wtxid,
};

use super::CompactFiltersError;

Expand Down
35 changes: 16 additions & 19 deletions src/blockchain/compact_filters/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,26 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use std::convert::TryInto;
use std::fmt;
use std::io::{Read, Write};
use std::marker::PhantomData;
use std::ops::Deref;
use std::sync::Arc;
use std::sync::RwLock;
use std::{
convert::TryInto,
fmt,
io::{Read, Write},
marker::PhantomData,
ops::Deref,
sync::{Arc, RwLock},
};

use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use rand::{distributions::Alphanumeric, thread_rng, Rng};

use rocksdb::{Direction, IteratorMode, ReadOptions, WriteBatch, DB};

use bitcoin::consensus::{deserialize, encode::VarInt, serialize, Decodable, Encodable};
use bitcoin::hash_types::{FilterHash, FilterHeader};
use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::Hash;
use bitcoin::util::bip158::BlockFilter;
use bitcoin::util::uint::Uint256;
use bitcoin::Block;
use bitcoin::BlockHash;
use bitcoin::BlockHeader;
use bitcoin::Network;
use bitcoin::{
consensus::{deserialize, encode::VarInt, serialize, Decodable, Encodable},
hash_types::{FilterHash, FilterHeader},
hashes::{hex::FromHex, Hash},
util::{bip158::BlockFilter, uint::Uint256},
Block, BlockHash, BlockHeader, Network,
};

use super::CompactFiltersError;

Expand Down
25 changes: 13 additions & 12 deletions src/blockchain/compact_filters/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use std::collections::{BTreeMap, HashMap, VecDeque};
use std::sync::{Arc, Mutex};
use std::time::Duration;

use bitcoin::hash_types::{BlockHash, FilterHeader};
use bitcoin::network::message::NetworkMessage;
use bitcoin::network::message_blockdata::GetHeadersMessage;
use bitcoin::util::bip158::BlockFilter;

use super::peer::*;
use super::store::*;
use super::CompactFiltersError;
use std::{
collections::{BTreeMap, HashMap, VecDeque},
sync::{Arc, Mutex},
time::Duration,
};

use bitcoin::{
hash_types::{BlockHash, FilterHeader},
network::{message::NetworkMessage, message_blockdata::GetHeadersMessage},
util::bip158::BlockFilter,
};

use super::{peer::*, store::*, CompactFiltersError};
use crate::error::Error;

pub(crate) const BURIED_CONFIRMATIONS: usize = 100;
Expand Down
4 changes: 1 addition & 3 deletions src/blockchain/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ use electrum_client::{Client, ConfigBuilder, ElectrumApi, Socks5Config};

use self::utils::{ELSGetHistoryRes, ElectrumLikeSync};
use super::*;
use crate::database::BatchDatabase;
use crate::error::Error;
use crate::FeeRate;
use crate::{database::BatchDatabase, error::Error, FeeRate};

/// Wrapper over an Electrum Client that implements the required blockchain traits
///
Expand Down
23 changes: 13 additions & 10 deletions src/blockchain/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
//! # Ok::<(), bdk::Error>(())
//! ```

use std::collections::{HashMap, HashSet};
use std::fmt;
use std::{
collections::{HashMap, HashSet},
fmt,
};

use futures::stream::{self, FuturesOrdered, StreamExt, TryStreamExt};

Expand All @@ -47,17 +49,18 @@ use serde::Deserialize;

use reqwest::{Client, StatusCode};

use bitcoin::consensus::{self, deserialize, serialize};
use bitcoin::hashes::hex::{FromHex, ToHex};
use bitcoin::hashes::{sha256, Hash};
use bitcoin::{BlockHash, BlockHeader, Script, Transaction, Txid};
use bitcoin::{
consensus::{self, deserialize, serialize},
hashes::{
hex::{FromHex, ToHex},
sha256, Hash,
},
BlockHash, BlockHeader, Script, Transaction, Txid,
};

use self::utils::{ELSGetHistoryRes, ElectrumLikeSync};
use super::*;
use crate::database::BatchDatabase;
use crate::error::Error;
use crate::wallet::utils::ChunksIterator;
use crate::FeeRate;
use crate::{database::BatchDatabase, error::Error, wallet::utils::ChunksIterator, FeeRate};

const DEFAULT_CONCURRENT_REQUESTS: u8 = 4;

Expand Down
16 changes: 9 additions & 7 deletions src/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@
//! [Compact Filters/Neutrino](crate::blockchain::compact_filters), along with a generalized trait
//! [`Blockchain`] that can be implemented to build customized backends.

use std::collections::HashSet;
use std::ops::Deref;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::Arc;
use std::{
collections::HashSet,
ops::Deref,
sync::{
mpsc::{channel, Receiver, Sender},
Arc,
},
};

use bitcoin::{Transaction, Txid};

use crate::database::BatchDatabase;
use crate::error::Error;
use crate::FeeRate;
use crate::{database::BatchDatabase, error::Error, FeeRate};

#[cfg(any(feature = "electrum", feature = "esplora"))]
pub(crate) mod utils;
Expand Down
14 changes: 7 additions & 7 deletions src/blockchain/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ use std::collections::{HashMap, HashSet};

#[allow(unused_imports)]
use log::{debug, error, info, trace};
use rand::seq::SliceRandom;
use rand::thread_rng;
use rand::{seq::SliceRandom, thread_rng};

use bitcoin::{BlockHeader, OutPoint, Script, Transaction, Txid};

use super::*;
use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils};
use crate::error::Error;
use crate::types::{KeychainKind, TransactionDetails, UTXO};
use crate::wallet::time::Instant;
use crate::wallet::utils::ChunksIterator;
use crate::{
database::{BatchDatabase, BatchOperations, DatabaseUtils},
error::Error,
types::{KeychainKind, TransactionDetails, UTXO},
wallet::{time::Instant, utils::ChunksIterator},
};

#[derive(Debug)]
pub struct ELSGetHistoryRes {
Expand Down
25 changes: 15 additions & 10 deletions src/database/keyvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ use std::convert::TryInto;

use sled::{Batch, Tree};

use bitcoin::consensus::encode::{deserialize, serialize};
use bitcoin::hash_types::Txid;
use bitcoin::{OutPoint, Script, Transaction};

use crate::database::memory::MapKey;
use crate::database::{BatchDatabase, BatchOperations, Database};
use crate::error::Error;
use crate::types::*;
use bitcoin::{
consensus::encode::{deserialize, serialize},
hash_types::Txid,
OutPoint, Script, Transaction,
};

use crate::{
database::{memory::MapKey, BatchDatabase, BatchOperations, Database},
error::Error,
types::*,
};

macro_rules! impl_batch_operations {
( { $($after_insert:tt)* }, $process_delete:ident ) => {
Expand Down Expand Up @@ -396,8 +399,10 @@ impl BatchDatabase for Tree {

#[cfg(test)]
mod test {
use std::sync::{Arc, Condvar, Mutex, Once};
use std::time::{SystemTime, UNIX_EPOCH};
use std::{
sync::{Arc, Condvar, Mutex, Once},
time::{SystemTime, UNIX_EPOCH},
};

use sled::{Db, Tree};

Expand Down
Loading