diff --git a/.dprintrc.json b/.dprintrc.json new file mode 100644 index 00000000..1c904734 --- /dev/null +++ b/.dprintrc.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://dprint.dev/schemas/v0.json", + "projectType": "openSource", + "incremental": true, + "markdown": { + }, + "rustfmt": { + "merge_imports": true + }, + "includes": ["**/*.{md,rs,toml}"], + "excludes": [ + "**/target" + ], + "plugins": [ + "https://plugins.dprint.dev/markdown-0.4.1.wasm", + "https://plugins.dprint.dev/rustfmt-0.3.0.wasm", + "https://github.com/thomaseizinger/dprint-plugin-cargo-toml/releases/download/0.1.0/cargo-toml-0.1.0.wasm" + ] +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c283348b..9994b38e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,24 +20,19 @@ jobs: with: profile: minimal override: true - components: rustfmt, clippy + components: clippy - - name: Cache ~/.cargo/bin directory + - name: Cache dprint uses: actions/cache@v1 with: - path: ~/.cargo/bin - key: ubuntu-rust-${{ env.RUST_TOOLCHAIN }}-cargo-bin-directory-v1 + path: ~/.cargo/bin/dprint + key: ubuntu-rust-${{ env.RUST_TOOLCHAIN }}-dprint - - name: Install tomlfmt - run: which cargo-tomlfmt || cargo install cargo-tomlfmt + - name: Install dprint + run: which dprint || cargo install dprint - - name: Check Cargo.toml formatting - run: | - cargo tomlfmt -d -p Cargo.toml - cargo tomlfmt -d -p elements-harness/Cargo.toml - - - name: Check code formatting - run: cargo fmt --all -- --check + - name: Check formatting + run: dprint check - name: Run clippy with default features run: cargo clippy --workspace --all-targets -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index 987a7cad..6d86c727 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["elements-harness", "swap", "elements-fun"] +members = [ "elements-harness", "swap", "elements-fun" ] diff --git a/README.md b/README.md index 0316ccbc..5ba27581 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # Project Droplet -This repository contains code produced in the phase of Project Droplet. +This repository contains code produced in the phase of Project Droplet. diff --git a/elements-fun/Cargo.toml b/elements-fun/Cargo.toml index e280caeb..314c5b52 100644 --- a/elements-fun/Cargo.toml +++ b/elements-fun/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "elements-fun" version = "0.1.0" -authors = ["CoBloX Team "] -description = "Make it fun to work with the elements blockchain!" -license = "CC0-1.0" +authors = [ "CoBloX Team " ] edition = "2018" +license = "CC0-1.0" +description = "Make it fun to work with the elements blockchain!" [features] default = [ "json-contract" ] @@ -13,25 +13,19 @@ serde = [ "bitcoin/use-serde", "serde-crate" ] -"fuzztarget" = [] +"fuzztarget" = [ ] [dependencies] -bitcoin = { version = "0.25", features = ["rand"] } -slip21 = "0.2.0" +bitcoin = { version = "0.25", features = [ "rand" ] } +bitcoin_hashes = "0.9.0" # While this dependency is included in bitcoin, we need this to use the macros. hex = "0.4.2" libc = "0.2.69" -wally-sys = { git= "https://github.com/RCasatta/wally-sys", rev="4a2f6740a18f96e7eeb73f29523757647077a069" } - -# While this dependency is included in bitcoin, we need this to use the macros. -# We should probably try keep this one in sync with the bitcoin version, -# to avoid requiring two version of bitcoin_hashes. -bitcoin_hashes = "0.9.0" - -# Used for ContractHash::from_json_contract. +serde-crate = { package = "serde", version = "1", optional = true, features = [ "derive" ] } # Used for ContractHash::from_json_contract. serde_json = { version = "1", optional = true } -serde-crate = { package = "serde", version = "1", optional = true, features = ["derive"] } +slip21 = "0.2.0" +wally-sys = { git = "https://github.com/RCasatta/wally-sys", rev = "4a2f6740a18f96e7eeb73f29523757647077a069" } [dev-dependencies] rand = "0.6.5" -serde_json = "1" ryu = "<1.0.5" +serde_json = "1" diff --git a/elements-fun/README.md b/elements-fun/README.md index 04bff82d..d4762c73 100644 --- a/elements-fun/README.md +++ b/elements-fun/README.md @@ -4,4 +4,4 @@ TODO: - short description - mention that it was forked from rust-elements -- re-license under CC-0? +- re-license under CC-0? diff --git a/elements-fun/fuzz/Cargo.toml b/elements-fun/fuzz/Cargo.toml index fb7d7299..b381edaa 100644 --- a/elements-fun/fuzz/Cargo.toml +++ b/elements-fun/fuzz/Cargo.toml @@ -1,24 +1,23 @@ [package] name = "elements-fuzz" version = "0.0.1" -authors = ["Automatically generated"] +authors = [ "Automatically generated" ] publish = false [package.metadata] cargo-fuzz = true [features] -afl_fuzz = ["afl"] -honggfuzz_fuzz = ["honggfuzz"] +afl_fuzz = [ "afl" ] +honggfuzz_fuzz = [ "honggfuzz" ] [dependencies] -honggfuzz = { version = "0.5", optional = true } afl = { version = "0.3", optional = true } -elements = { path = "..", features = ["fuzztarget", "serde"] } +elements = { path = "..", features = [ "fuzztarget", "serde" ] } +honggfuzz = { version = "0.5", optional = true } -# Prevent this from interfering with workspaces [workspace] -members = ["."] +members = [ "." ] # Prevent this from interfering with workspaces [[bin]] name = "deserialize_transaction" @@ -31,4 +30,3 @@ path = "fuzz_targets/deserialize_block.rs" [[bin]] name = "deserialize_output" path = "fuzz_targets/deserialize_output.rs" - diff --git a/elements-fun/fuzz/fuzz_targets/deserialize_block.rs b/elements-fun/fuzz/fuzz_targets/deserialize_block.rs index 061fec7e..e581061c 100644 --- a/elements-fun/fuzz/fuzz_targets/deserialize_block.rs +++ b/elements-fun/fuzz/fuzz_targets/deserialize_block.rs @@ -1,14 +1,13 @@ - extern crate elements; fn do_test(data: &[u8]) { let block_result: Result = elements::encode::deserialize(data); match block_result { - Err(_) => {}, + Err(_) => {} Ok(block) => { let reser = elements::encode::serialize(&block); assert_eq!(data, &reser[..]); - }, + } } } @@ -22,7 +21,8 @@ fn main() { } #[cfg(feature = "honggfuzz")] -#[macro_use] extern crate honggfuzz; +#[macro_use] +extern crate honggfuzz; #[cfg(feature = "honggfuzz")] fn main() { loop { diff --git a/elements-fun/fuzz/fuzz_targets/deserialize_output.rs b/elements-fun/fuzz/fuzz_targets/deserialize_output.rs index 22bc06d9..dace27ee 100644 --- a/elements-fun/fuzz/fuzz_targets/deserialize_output.rs +++ b/elements-fun/fuzz/fuzz_targets/deserialize_output.rs @@ -1,10 +1,9 @@ - extern crate elements; fn do_test(data: &[u8]) { let result: Result = elements::encode::deserialize(data); match result { - Err(_) => {}, + Err(_) => {} Ok(output) => { let reser = elements::encode::serialize(&output); assert_eq!(data, &reser[..]); @@ -14,7 +13,7 @@ fn do_test(data: &[u8]) { output.pegout_data(); output.is_fee(); output.minimum_value(); - }, + } } } @@ -28,7 +27,8 @@ fn main() { } #[cfg(feature = "honggfuzz")] -#[macro_use] extern crate honggfuzz; +#[macro_use] +extern crate honggfuzz; #[cfg(feature = "honggfuzz")] fn main() { loop { diff --git a/elements-fun/fuzz/fuzz_targets/deserialize_transaction.rs b/elements-fun/fuzz/fuzz_targets/deserialize_transaction.rs index 25148086..4659f974 100644 --- a/elements-fun/fuzz/fuzz_targets/deserialize_transaction.rs +++ b/elements-fun/fuzz/fuzz_targets/deserialize_transaction.rs @@ -1,10 +1,9 @@ - extern crate elements; fn do_test(data: &[u8]) { let tx_result: Result = elements::encode::deserialize(data); match tx_result { - Err(_) => {}, + Err(_) => {} Ok(mut tx) => { let reser = elements::encode::serialize(&tx); assert_eq!(data, &reser[..]); @@ -27,7 +26,7 @@ fn do_test(data: &[u8]) { output.is_fee(); output.minimum_value(); } - }, + } } } @@ -41,7 +40,8 @@ fn main() { } #[cfg(feature = "honggfuzz")] -#[macro_use] extern crate honggfuzz; +#[macro_use] +extern crate honggfuzz; #[cfg(feature = "honggfuzz")] fn main() { loop { diff --git a/elements-fun/src/address.rs b/elements-fun/src/address.rs index fdfbea6e..360bb913 100644 --- a/elements-fun/src/address.rs +++ b/elements-fun/src/address.rs @@ -15,20 +15,15 @@ //! # Addresses //! -use std::error; -use std::fmt; -use std::str::FromStr; - -// AsciiExt is needed until for Rust 1.26 but not for newer versions -#[allow(unused_imports, deprecated)] -use std::ascii::AsciiExt; - -use bitcoin::bech32::{self, u5, FromBase32, ToBase32}; -use bitcoin::blockdata::{opcodes, script}; -use bitcoin::hashes::Hash; -use bitcoin::secp256k1; -use bitcoin::util::base58; -use bitcoin::PublicKey; +use bitcoin::{ + bech32::{self, u5, FromBase32, ToBase32}, + blockdata::{opcodes, script}, + hashes::Hash, + secp256k1, + util::base58, + PublicKey, +}; +use std::{error, fmt, str::FromStr}; /// Encoding error #[derive(Debug, PartialEq)] @@ -666,9 +661,11 @@ impl serde::Serialize for Address { #[cfg(test)] mod test { use super::*; - use bitcoin::secp256k1::{PublicKey, Secp256k1}; - use bitcoin::util::key; - use bitcoin::Script; + use bitcoin::{ + secp256k1::{PublicKey, Secp256k1}, + util::key, + Script, + }; fn roundtrips(addr: &Address) { assert_eq!( diff --git a/elements-fun/src/blech32.rs b/elements-fun/src/blech32.rs index d7209457..102545e8 100644 --- a/elements-fun/src/blech32.rs +++ b/elements-fun/src/blech32.rs @@ -40,13 +40,8 @@ // Original documentation is left untouched, so it corresponds to bech32. -use std::fmt; - -// AsciiExt is needed until for Rust 1.26 but not for newer versions -#[allow(unused_imports, deprecated)] -use std::ascii::AsciiExt; - use bitcoin::bech32::{u5, Error}; +use std::fmt; /// Encode a bech32 payload to an [fmt::Formatter]. pub fn encode_to_fmt>(fmt: &mut fmt::Formatter, hrp: &str, data: T) -> fmt::Result { @@ -235,7 +230,6 @@ const GEN: [u64; 5] = [ #[cfg(test)] mod test { use super::*; - use bitcoin::bech32::ToBase32; #[test] diff --git a/elements-fun/src/block.rs b/elements-fun/src/block.rs index 75f2e155..8eb41f27 100644 --- a/elements-fun/src/block.rs +++ b/elements-fun/src/block.rs @@ -15,20 +15,23 @@ //! # Blocks //! +use crate::{ + dynafed, + encode::{self, serialize, Decodable, Encodable}, + Transaction, +}; +use bitcoin::{ + blockdata::script::Script, + hashes::{sha256, Hash}, + BlockHash, VarInt, +}; use std::io; -use bitcoin::blockdata::script::Script; -use bitcoin::hashes::{sha256, Hash}; -use bitcoin::{BlockHash, VarInt}; #[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[cfg(feature = "serde")] use std::fmt; -use crate::dynafed; -use crate::encode::{self, serialize, Decodable, Encodable}; -use crate::Transaction; - /// Data related to block signatures #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub enum ExtData { diff --git a/elements-fun/src/confidential.rs b/elements-fun/src/confidential.rs index 876ec051..bf1cf584 100644 --- a/elements-fun/src/confidential.rs +++ b/elements-fun/src/confidential.rs @@ -17,22 +17,20 @@ //! Structures representing Pedersen commitments of various types //! -#[cfg(feature = "serde")] -use serde::{Deserialize, Deserializer, Serialize, Serializer}; - +use crate::{ + encode::{self, Decodable, Encodable}, + wally::{asset_final_vbf, asset_generator_from_bytes, asset_value_commitment}, + AssetId, +}; +use bitcoin::secp256k1::{ + rand::{CryptoRng, Rng, RngCore}, + PublicKey, Secp256k1, SecretKey, Signing, +}; +use hex::{FromHex, FromHexError}; use std::{fmt, io, iter}; -use crate::encode::{self, Decodable, Encodable}; -use crate::wally::asset_final_vbf; -use crate::wally::asset_generator_from_bytes; -use crate::wally::asset_value_commitment; -use crate::AssetId; -use bitcoin::secp256k1::rand::Rng; -use bitcoin::secp256k1::rand::{CryptoRng, RngCore}; -use bitcoin::secp256k1::SecretKey; -use bitcoin::secp256k1::{PublicKey, Secp256k1, Signing}; -use hex::FromHex; -use hex::FromHexError; +#[cfg(feature = "serde")] +use serde::{Deserialize, Deserializer, Serialize, Serializer}; // Helper macro to implement various things for the various confidential // commitment types diff --git a/elements-fun/src/dynafed.rs b/elements-fun/src/dynafed.rs index 4aef01b7..00c210b1 100644 --- a/elements-fun/src/dynafed.rs +++ b/elements-fun/src/dynafed.rs @@ -14,16 +14,15 @@ //! Dynamic Federations +use crate::encode::{self, Decodable, Encodable}; +use bitcoin::hashes::{sha256, sha256d, Hash}; use std::io; -use bitcoin::hashes::{sha256, sha256d, Hash}; #[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[cfg(feature = "serde")] use std::fmt; -use crate::encode::{self, Decodable, Encodable}; - /// Dynamic federations paramaters, as encoded in a block header #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub enum Params { @@ -488,9 +487,7 @@ impl Decodable for Params { #[cfg(test)] mod tests { use super::*; - - use bitcoin::hashes::hex::ToHex; - use bitcoin::hashes::sha256; + use bitcoin::hashes::{hex::ToHex, sha256}; #[test] fn test_param_roots() { diff --git a/elements-fun/src/encode.rs b/elements-fun/src/encode.rs index 8e95d261..8d290d83 100644 --- a/elements-fun/src/encode.rs +++ b/elements-fun/src/encode.rs @@ -15,15 +15,10 @@ //! Consensus-encodable types //! -use std::io::Cursor; -use std::{error, fmt, io, mem}; - -use bitcoin::consensus::encode as btcenc; -use bitcoin::hashes::sha256; - use crate::transaction::{Transaction, TxIn, TxOut}; - pub use bitcoin::consensus::encode::MAX_VEC_SIZE; +use bitcoin::{consensus::encode as btcenc, hashes::sha256}; +use std::{error, fmt, io, io::Cursor, mem}; /// Encoding error #[derive(Debug)] diff --git a/elements-fun/src/fast_merkle_root.rs b/elements-fun/src/fast_merkle_root.rs index 3548bac4..00ca64b9 100644 --- a/elements-fun/src/fast_merkle_root.rs +++ b/elements-fun/src/fast_merkle_root.rs @@ -91,8 +91,7 @@ pub fn fast_merkle_root(leaves: &[[u8; 32]]) -> sha256::Midstate { #[cfg(test)] mod tests { use super::fast_merkle_root; - use bitcoin::hashes::hex::FromHex; - use bitcoin::hashes::sha256; + use bitcoin::hashes::{hex::FromHex, sha256}; #[test] fn test_fast_merkle_root() { diff --git a/elements-fun/src/issuance.rs b/elements-fun/src/issuance.rs index c073842f..45d8d1fd 100644 --- a/elements-fun/src/issuance.rs +++ b/elements-fun/src/issuance.rs @@ -14,14 +14,13 @@ //! Asset Issuance -use std::io; -use std::str::FromStr; - +use crate::{ + encode::{self, Decodable, Encodable}, + fast_merkle_root::fast_merkle_root, + transaction::OutPoint, +}; use bitcoin::hashes::{self, hex, sha256, sha256d, Hash}; - -use crate::encode::{self, Decodable, Encodable}; -use crate::fast_merkle_root::fast_merkle_root; -use crate::transaction::OutPoint; +use std::{io, str::FromStr}; /// The zero hash. const ZERO32: [u8; 32] = [ @@ -260,8 +259,7 @@ mod test { use super::*; use std::str::FromStr; - use bitcoin::hashes::hex::FromHex; - use bitcoin::hashes::sha256; + use bitcoin::hashes::{hex::FromHex, sha256}; #[test] fn example_elements_core() { diff --git a/elements-fun/src/lib.rs b/elements-fun/src/lib.rs index b7b01034..51f32c3c 100644 --- a/elements-fun/src/lib.rs +++ b/elements-fun/src/lib.rs @@ -25,7 +25,6 @@ #![deny(unused_mut)] // #![deny(missing_docs)] -pub use bitcoin; #[macro_use] pub extern crate bitcoin_hashes; @@ -49,8 +48,8 @@ pub mod wally; // export everything at the top level so it can be used as `elements::Transaction` etc. pub use ::bitcoin::consensus::encode::VarInt; pub use address::{Address, AddressError, AddressParams}; -pub use block::ExtData as BlockExtData; -pub use block::{Block, BlockHeader}; +pub use bitcoin; +pub use block::{Block, BlockHeader, ExtData as BlockExtData}; pub use fast_merkle_root::fast_merkle_root; pub use issuance::{AssetId, ContractHash}; pub use transaction::{ diff --git a/elements-fun/src/slip77.rs b/elements-fun/src/slip77.rs index e158b2ef..2553d2c5 100644 --- a/elements-fun/src/slip77.rs +++ b/elements-fun/src/slip77.rs @@ -3,8 +3,11 @@ //! //! Spec: https://github.com/satoshilabs/slips/blob/master/slip-0077.md -use bitcoin::hashes::{hmac, sha256, sha256d, Hash, HashEngine}; -use bitcoin::{self, secp256k1}; +use bitcoin::{ + self, + hashes::{hmac, sha256, sha256d, Hash, HashEngine}, + secp256k1, +}; const SLIP77_DERIVATION: &str = "SLIP-0077"; @@ -50,8 +53,7 @@ mod tests { use std::str::FromStr; - use bitcoin::hashes::hex::FromHex; - use bitcoin::secp256k1::SecretKey; + use bitcoin::{hashes::hex::FromHex, secp256k1::SecretKey}; use crate::address::Address; diff --git a/elements-fun/src/transaction.rs b/elements-fun/src/transaction.rs index efe17b05..e13fe86e 100644 --- a/elements-fun/src/transaction.rs +++ b/elements-fun/src/transaction.rs @@ -15,28 +15,29 @@ //! # Transactions //! -use std::collections::HashMap; -use std::{fmt, io}; - -use bitcoin::blockdata::opcodes; -use bitcoin::blockdata::script::{Instruction, Script}; -use bitcoin::hashes::Hash; -use bitcoin::secp256k1::rand::CryptoRng; -use bitcoin::secp256k1::rand::RngCore; -use bitcoin::secp256k1::Secp256k1; -use bitcoin::secp256k1::SecretKey; -use bitcoin::secp256k1::{PublicKey, Signing}; -use bitcoin::{self, Txid, VarInt}; - -use crate::confidential::Nonce; -use crate::confidential::ValueCommitment; -use crate::confidential::{AssetBlindingFactor, AssetCommitment, ValueBlindingFactor}; -use crate::encode::{self, Decodable, Encodable, Error}; -use crate::issuance::AssetId; -use crate::wally::asset_rangeproof; -use crate::wally::asset_surjectionproof; -use crate::wally::asset_unblind; -use crate::Address; +use crate::{ + confidential::{ + AssetBlindingFactor, AssetCommitment, Nonce, ValueBlindingFactor, ValueCommitment, + }, + encode::{self, Decodable, Encodable, Error}, + issuance::AssetId, + wally::{asset_rangeproof, asset_surjectionproof, asset_unblind}, + Address, +}; +use bitcoin::{ + self, + blockdata::{ + opcodes, + script::{Instruction, Script}, + }, + hashes::Hash, + secp256k1::{ + rand::{CryptoRng, RngCore}, + PublicKey, Secp256k1, SecretKey, Signing, + }, + Txid, VarInt, +}; +use std::{collections::HashMap, fmt, io}; /// Elements transaction #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] diff --git a/elements-fun/src/wally.rs b/elements-fun/src/wally.rs index 903cae60..fa30fd35 100644 --- a/elements-fun/src/wally.rs +++ b/elements-fun/src/wally.rs @@ -2,23 +2,24 @@ //! Links to libwally methods used. //! -use crate::bitcoin::secp256k1; -use crate::{bitcoin, AssetId}; -use std::ptr; - -use std::fmt; - -use bitcoin::hashes::{sha256d, Hash}; - -use crate::confidential::{ - AssetBlindingFactor, AssetCommitment, ValueBlindingFactor, ValueCommitment, +use crate::{ + bitcoin, + bitcoin::secp256k1, + confidential::{AssetBlindingFactor, AssetCommitment, ValueBlindingFactor, ValueCommitment}, + encode::Encodable, + AssetId, +}; +use bitcoin::{ + hashes::{sha256d, Hash}, + secp256k1::rand::{CryptoRng, RngCore}, +}; +use std::{ + borrow::Cow, + ffi::{CStr, CString}, + fmt, + os::raw::c_char, + ptr, }; -use crate::encode::Encodable; -use bitcoin::secp256k1::rand::CryptoRng; -use bitcoin::secp256k1::rand::RngCore; -use std::borrow::Cow; -use std::ffi::{CStr, CString}; -use std::os::raw::c_char; use wally_sys as ffi; #[derive(Clone)] @@ -543,8 +544,7 @@ pub fn read_str(s: *const c_char) -> String { #[cfg(test)] mod tests { use super::*; - use bitcoin::secp256k1; - use bitcoin::Script; + use bitcoin::{secp256k1, Script}; use crate::transaction::ExplicitValue; use hex::FromHex; diff --git a/elements-harness/Cargo.toml b/elements-harness/Cargo.toml index 7ad804ff..18b1b607 100644 --- a/elements-harness/Cargo.toml +++ b/elements-harness/Cargo.toml @@ -1,17 +1,17 @@ [package] name = "elements-harness" version = "0.1.0" -authors = ["CoBloX Team "] +authors = [ "CoBloX Team " ] edition = "2018" [dependencies] anyhow = "1.0" async-trait = "0.1" -elements-fun = { path = "../elements-fun", features = ["serde"] } +elements-fun = { path = "../elements-fun", features = [ "serde" ] } futures = "0.3.5" hex = "0.4.2" hmac = "0.10" -jsonrpc_client = { git = "https://github.com/thomaseizinger/rust-jsonrpc-client", branch = "master", features = ["reqwest"] } +jsonrpc_client = { git = "https://github.com/thomaseizinger/rust-jsonrpc-client", branch = "master", features = [ "reqwest" ] } log = "0.4" rand = "0.7" reqwest = { version = "0.10" } @@ -20,9 +20,9 @@ serde_json = "1.0" sha2 = "0.9" testcontainers = "0.11" thiserror = "1.0" -tokio = { version = "0.2", default-features = false, features = ["blocking", "macros", "rt-core", "time"] } +tokio = { version = "0.2", default-features = false, features = [ "blocking", "macros", "rt-core", "time" ] } tracing = "0.1" url = "2" [features] -default = [] +default = [ ] diff --git a/elements-harness/src/elementd_rpc.rs b/elements-harness/src/elementd_rpc.rs index bcc186ed..0f48812f 100644 --- a/elements-harness/src/elementd_rpc.rs +++ b/elements-harness/src/elementd_rpc.rs @@ -1,9 +1,10 @@ -use anyhow::Context; -use anyhow::Result; -use elements_fun::bitcoin::Amount; -use elements_fun::bitcoin_hashes::hex::FromHex; -use elements_fun::encode::serialize_hex; -use elements_fun::{bitcoin::Txid, Address, AssetId, Transaction}; +use anyhow::{Context, Result}; +use elements_fun::{ + bitcoin::{Amount, Txid}, + bitcoin_hashes::hex::FromHex, + encode::serialize_hex, + Address, AssetId, Transaction, +}; use serde::Deserialize; use std::collections::HashMap; diff --git a/elements-harness/src/image.rs b/elements-harness/src/image.rs index 9e7ab32a..2cf6f8bf 100644 --- a/elements-harness/src/image.rs +++ b/elements-harness/src/image.rs @@ -3,8 +3,7 @@ use hex::encode; use hmac::{Hmac, Mac, NewMac}; use rand::{thread_rng, Rng}; use sha2::Sha256; -use std::fmt; -use std::{collections::HashMap, env::var, thread::sleep, time::Duration}; +use std::{collections::HashMap, env::var, fmt, thread::sleep, time::Duration}; use testcontainers::core::{Container, Docker, Image, Port, WaitForMessage}; #[derive(Debug)] diff --git a/elements-harness/src/lib.rs b/elements-harness/src/lib.rs index 4d46ca7f..6e7abdd5 100644 --- a/elements-harness/src/lib.rs +++ b/elements-harness/src/lib.rs @@ -15,12 +15,11 @@ pub mod elementd_rpc; pub mod image; +use crate::image::ElementsCore; use reqwest::Url; -use testcontainers::{clients, Container, Docker}; +use testcontainers::{clients, core::Port, Container, Docker}; pub use crate::elementd_rpc::Client; -use crate::image::ElementsCore; -use testcontainers::core::Port; pub type Result = std::result::Result; diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 77abf1e4..9dc74699 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -1,18 +1,18 @@ [package] name = "swap" version = "0.1.0" -authors = ["CoBloX Team "] +authors = [ "CoBloX Team " ] edition = "2018" [dependencies] anyhow = "1.0" -bitcoin = { version = "0.25", features = ["rand"] } -secp256k1 = { version = "0.19.0", features = ["global-context"] } -elements-fun = { path = "../elements-fun", features = ["serde"] } +bitcoin = { version = "0.25", features = [ "rand" ] } +elements-fun = { path = "../elements-fun", features = [ "serde" ] } elements-harness = { path = "../elements-harness" } -sha2 = "0.9" rand = "0.6" +secp256k1 = { version = "0.19.0", features = [ "global-context" ] } +sha2 = "0.9" [dev-dependencies] testcontainers = "0.11" -tokio = { version = "0.2", default-features = false, features = ["blocking", "macros", "rt-core", "time"] } +tokio = { version = "0.2", default-features = false, features = [ "blocking", "macros", "rt-core", "time" ] } diff --git a/swap/src/lib.rs b/swap/src/lib.rs index 0099b8dc..9da83d75 100644 --- a/swap/src/lib.rs +++ b/swap/src/lib.rs @@ -1,11 +1,9 @@ -use elements_fun::bitcoin::Network::Regtest; -use elements_fun::bitcoin::PrivateKey; -use elements_fun::bitcoin::PublicKey; -use elements_fun::Address; -use elements_fun::AddressParams; +use elements_fun::{ + bitcoin::{Network::Regtest, PrivateKey, PublicKey}, + Address, AddressParams, +}; use rand::thread_rng; -use secp256k1::SecretKey; -use secp256k1::SECP256K1; +use secp256k1::{SecretKey, SECP256K1}; pub mod states; @@ -39,18 +37,21 @@ pub fn make_confidential_address() -> (Address, SecretKey, PublicKey, SecretKey, #[cfg(test)] mod tests { use bitcoin::Amount; - use elements_fun::bitcoin::secp256k1::Message; - use elements_fun::wally::tx_get_elements_signature_hash; use elements_fun::{ bitcoin::{ blockdata::{opcodes, script::Builder}, + secp256k1::Message, SigHashType, }, bitcoin_hashes::{hash160, hex::FromHex, Hash}, encode::serialize_hex, + wally::tx_get_elements_signature_hash, OutPoint, Transaction, TxIn, TxOut, UnblindedTxOut, }; - use elements_harness::{elementd_rpc::Client, elementd_rpc::ElementsRpc, Elementsd}; + use elements_harness::{ + elementd_rpc::{Client, ElementsRpc}, + Elementsd, + }; use rand::thread_rng; use testcontainers::clients::Cli; diff --git a/swap/src/states.rs b/swap/src/states.rs index beb9766e..2db4f455 100644 --- a/swap/src/states.rs +++ b/swap/src/states.rs @@ -464,8 +464,10 @@ mod tests { states::{Alice0, Bob0}, }; use anyhow::Result; - use elements_fun::bitcoin::{Network, PrivateKey, PublicKey, Txid}; - use elements_fun::encode::serialize_hex; + use elements_fun::{ + bitcoin::{Network, PrivateKey, PublicKey, Txid}, + encode::serialize_hex, + }; use elements_harness::{elementd_rpc::ElementsRpc, Client, Elementsd}; use rand::thread_rng; use secp256k1::{Message, SecretKey, SECP256K1};