Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
Ignore digits when deriving BitMexPriceEventId's PartialOrd
Browse files Browse the repository at this point in the history
This is important because deriving `PartialOrd` normally means that it
looks at all the struct's fields _in order_. For this type we want to
compare the `timestamp`, but do not care about the `digits`! More
importantly, someone could unintentionally change this behaviour by
reordering the fields.

We also have to ignore the `digits` field for other derived traits,
because inconsistencies there could cause trouble[1].

[1]: rust-lang/rust-clippy#1621.

Co-authored-by: Daniel Karzel <daniel.karzel@coblox.tech>
  • Loading branch information
luckysori and da-kami committed Jul 26, 2022
1 parent 20ce513 commit d05fa65
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async-trait = "0.1"
bdk = { version = "0.19.0", default-features = false }
bdk-ext = { path = "../bdk-ext" }
conquer-once = "0.3"
derivative = "2"
hex = "0.4"
itertools = "0.10"
libp2p-core = { version = "0.33", default-features = false, features = ["serde"] }
Expand Down
12 changes: 9 additions & 3 deletions model/src/olivia.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Context;
use bdk::bitcoin::XOnlyPublicKey;
use conquer_once::Lazy;
use derivative::Derivative;
use maia_core::secp256k1_zkp::SecretKey;
use serde::Deserialize;
use serde_with::DeserializeFromStr;
Expand Down Expand Up @@ -45,12 +46,17 @@ pub struct Attestation {
pub scalars: Vec<SecretKey>,
}

#[derive(
Debug, Clone, Copy, SerializeDisplay, DeserializeFromStr, PartialEq, Eq, Hash, PartialOrd, Ord,
)]
#[derive(Derivative, Debug, Clone, Copy, SerializeDisplay, DeserializeFromStr)]
#[derivative(PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BitMexPriceEventId {
/// The timestamp this price event refers to.
timestamp: OffsetDateTime,
#[derivative(
PartialEq = "ignore",
PartialOrd = "ignore",
Ord = "ignore",
Hash = "ignore"
)]
digits: usize,
}

Expand Down

0 comments on commit d05fa65

Please sign in to comment.