Skip to content

Commit

Permalink
Format everything with dprint
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Nov 19, 2020
1 parent 3a3e344 commit 3d71e51
Show file tree
Hide file tree
Showing 29 changed files with 193 additions and 202 deletions.
19 changes: 19 additions & 0 deletions .dprintrc.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
21 changes: 8 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[workspace]
members = ["elements-harness", "swap", "elements-fun"]
members = [ "elements-harness", "swap", "elements-fun" ]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 10 additions & 16 deletions elements-fun/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "elements-fun"
version = "0.1.0"
authors = ["CoBloX Team <[email protected]>"]
description = "Make it fun to work with the elements blockchain!"
license = "CC0-1.0"
authors = [ "CoBloX Team <[email protected]>" ]
edition = "2018"
license = "CC0-1.0"
description = "Make it fun to work with the elements blockchain!"

[features]
default = [ "json-contract" ]
Expand All @@ -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"
2 changes: 1 addition & 1 deletion elements-fun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
14 changes: 6 additions & 8 deletions elements-fun/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -31,4 +30,3 @@ path = "fuzz_targets/deserialize_block.rs"
[[bin]]
name = "deserialize_output"
path = "fuzz_targets/deserialize_output.rs"

8 changes: 4 additions & 4 deletions elements-fun/fuzz/fuzz_targets/deserialize_block.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

extern crate elements;

fn do_test(data: &[u8]) {
let block_result: Result<elements::Block, _> = elements::encode::deserialize(data);
match block_result {
Err(_) => {},
Err(_) => {}
Ok(block) => {
let reser = elements::encode::serialize(&block);
assert_eq!(data, &reser[..]);
},
}
}
}

Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions elements-fun/fuzz/fuzz_targets/deserialize_output.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

extern crate elements;

fn do_test(data: &[u8]) {
let result: Result<elements::TxOut, _> = elements::encode::deserialize(data);
match result {
Err(_) => {},
Err(_) => {}
Ok(output) => {
let reser = elements::encode::serialize(&output);
assert_eq!(data, &reser[..]);
Expand All @@ -14,7 +13,7 @@ fn do_test(data: &[u8]) {
output.pegout_data();
output.is_fee();
output.minimum_value();
},
}
}
}

Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions elements-fun/fuzz/fuzz_targets/deserialize_transaction.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

extern crate elements;

fn do_test(data: &[u8]) {
let tx_result: Result<elements::Transaction, _> = elements::encode::deserialize(data);
match tx_result {
Err(_) => {},
Err(_) => {}
Ok(mut tx) => {
let reser = elements::encode::serialize(&tx);
assert_eq!(data, &reser[..]);
Expand All @@ -27,7 +26,7 @@ fn do_test(data: &[u8]) {
output.is_fee();
output.minimum_value();
}
},
}
}
}

Expand All @@ -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 {
Expand Down
31 changes: 14 additions & 17 deletions elements-fun/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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!(
Expand Down
8 changes: 1 addition & 7 deletions elements-fun/src/blech32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: AsRef<[u5]>>(fmt: &mut fmt::Formatter, hrp: &str, data: T) -> fmt::Result {
Expand Down Expand Up @@ -235,7 +230,6 @@ const GEN: [u64; 5] = [
#[cfg(test)]
mod test {
use super::*;

use bitcoin::bech32::ToBase32;

#[test]
Expand Down
17 changes: 10 additions & 7 deletions elements-fun/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 12 additions & 14 deletions elements-fun/src/confidential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 3d71e51

Please sign in to comment.