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

Commit 4d1ca99

Browse files
luckysorida-kami
andcommitted
Ignore digits when deriving BitMexPriceEventId's PartialOrd
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>
1 parent c1367c3 commit 4d1ca99

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

model/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ async-trait = "0.1"
99
bdk = { version = "0.19.0", default-features = false }
1010
bdk-ext = { path = "../bdk-ext" }
1111
conquer-once = "0.3"
12+
derivative = "2"
1213
hex = "0.4"
1314
itertools = "0.10"
1415
libp2p-core = { version = "0.33", default-features = false, features = ["serde"] }

model/src/olivia.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use anyhow::Context;
22
use bdk::bitcoin::XOnlyPublicKey;
33
use conquer_once::Lazy;
4+
use derivative::Derivative;
45
use maia_core::secp256k1_zkp::SecretKey;
56
use serde::Deserialize;
67
use serde_with::DeserializeFromStr;
@@ -45,12 +46,17 @@ pub struct Attestation {
4546
pub scalars: Vec<SecretKey>,
4647
}
4748

48-
#[derive(
49-
Debug, Clone, Copy, SerializeDisplay, DeserializeFromStr, PartialEq, Eq, Hash, PartialOrd, Ord,
50-
)]
49+
#[derive(Derivative, Debug, Clone, Copy, SerializeDisplay, DeserializeFromStr)]
50+
#[derivative(PartialEq, Eq, PartialOrd, Ord, Hash)]
5151
pub struct BitMexPriceEventId {
5252
/// The timestamp this price event refers to.
5353
timestamp: OffsetDateTime,
54+
#[derivative(
55+
PartialEq = "ignore",
56+
PartialOrd = "ignore",
57+
Ord = "ignore",
58+
Hash = "ignore"
59+
)]
5460
digits: usize,
5561
}
5662

0 commit comments

Comments
 (0)