Skip to content

Commit

Permalink
Clippy'd again
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Carton committed Apr 19, 2023
1 parent 3dbd0c7 commit afe15a4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
8 changes: 5 additions & 3 deletions src/chainparams/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ pub struct ChainParams {
pub magic: u32,
}

impl ChainParams {
// #[cfg_attr(all(feature = "wasm-bindgen-address"), wasm_bindgen(constructor))]
pub fn default() -> ChainParams {
impl Default for ChainParams {
fn default() -> ChainParams {
ChainParams {
p2pkh: 0x00,
p2sh: 0x05,
Expand All @@ -22,7 +21,10 @@ impl ChainParams {
magic: 0xe3e1f3e8,
}
}
}

impl ChainParams {
// #[cfg_attr(all(feature = "wasm-bindgen-address"), wasm_bindgen(constructor))]
pub fn new(p2pkh: u8, p2sh: u8, privkey: u8, xpub: u32, xpriv: u32, magic: u32) -> ChainParams {
ChainParams {
p2pkh,
Expand Down
5 changes: 1 addition & 4 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ pub mod state;
pub use state::*;
mod script_matching;

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Default)]
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum Status {
#[default]
Running,
Finished,
}



#[derive(Clone, Serialize, Deserialize)]
pub struct TxScript {
pub(crate) tx: Transaction,
Expand Down
12 changes: 2 additions & 10 deletions src/signature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{get_hash_digest, BSVErrors, PublicKey, SigHash, SigningHash, ECDSA};
use k256::{ecdsa::recoverable, ecdsa::Signature as SecpSignature, FieldBytes};
use num_traits::FromPrimitive;

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct RecoveryInfo {
is_y_odd: bool,
is_x_reduced: bool,
Expand All @@ -25,14 +25,6 @@ impl RecoveryInfo {
is_pubkey_compressed,
}
}

pub fn default() -> RecoveryInfo {
RecoveryInfo {
is_y_odd: false,
is_x_reduced: false,
is_pubkey_compressed: false,
}
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -139,7 +131,7 @@ impl Signature {
is_y_odd,
is_x_reduced,
is_pubkey_compressed,
} = recovery_info.or_else(|| self.recovery.clone()).unwrap_or_else(RecoveryInfo::default);
} = recovery_info.or_else(|| self.recovery.clone()).unwrap_or_default();

let mut recovery = ((is_x_reduced as u8) << 1 | (is_y_odd as u8)) + 27 + 4;

Expand Down
11 changes: 7 additions & 4 deletions src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub use sighash::*;
pub use txin::*;
pub use txout::*;

#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Transaction {
pub(super) version: u32,
pub(super) inputs: Vec<TxIn>,
Expand All @@ -28,6 +28,12 @@ pub struct Transaction {
pub(super) hash_cache: HashCache,
}

impl Default for Transaction {
fn default() -> Transaction {
Transaction::new_impl(2, vec![], vec![], 0)
}
}

impl Transaction {
pub(crate) fn new_impl(version: u32, inputs: Vec<TxIn>, outputs: Vec<TxOut>, n_locktime: u32) -> Transaction {
Transaction {
Expand Down Expand Up @@ -266,9 +272,6 @@ impl Transaction {
}

// #[cfg_attr(all(feature = "wasm-bindgen-transaction"), wasm_bindgen)]
pub fn default() -> Transaction {
Transaction::new_impl(2, vec![], vec![], 0)
}

// #[cfg_attr(all(feature = "wasm-bindgen-transaction"), wasm_bindgen(js_name = setVersion))]
pub fn set_version(&mut self, version: u32) -> Transaction {
Expand Down
23 changes: 13 additions & 10 deletions src/transaction/txin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ pub struct TxIn {
pub(crate) satoshis: Option<u64>,
}

impl Default for TxIn {
fn default() -> TxIn {
TxIn {
prev_tx_id: vec![],
satoshis: None,
unlocking_script: Script::default(),
sequence: u32::MAX,
locking_script: None,
vout: 0,
}
}
}

impl TxIn {
pub(crate) fn get_finalised_script_impl(&self) -> Result<Script, BSVErrors> {
match self.locking_script.as_ref() {
Expand Down Expand Up @@ -221,16 +234,6 @@ impl TxIn {
}

// #[cfg_attr(all(feature = "wasm-bindgen-transaction"), wasm_bindgen)]
pub fn default() -> TxIn {
TxIn {
prev_tx_id: vec![],
satoshis: None,
unlocking_script: Script::default(),
sequence: u32::MAX,
locking_script: None,
vout: 0,
}
}

// #[cfg_attr(all(feature = "wasm-bindgen-transaction"), wasm_bindgen(js_name = getPrevTxId))]
pub fn get_prev_tx_id(&self, little_endian: Option<bool>) -> Vec<u8> {
Expand Down

0 comments on commit afe15a4

Please sign in to comment.