From 98c9ab754a4f698803731f63de63055e63d8d629 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 12 Feb 2024 13:15:45 +0200 Subject: [PATCH 1/9] subxt/tx: Derive std::cmp traits Signed-off-by: Alexandru Vasile --- subxt/src/tx/tx_payload.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/subxt/src/tx/tx_payload.rs b/subxt/src/tx/tx_payload.rs index 508a6a99e6..ff9c71fd21 100644 --- a/subxt/src/tx/tx_payload.rs +++ b/subxt/src/tx/tx_payload.rs @@ -11,6 +11,7 @@ use crate::{ metadata::Metadata, }; use codec::Encode; +use derivative::Derivative; use scale_encode::EncodeAsFields; use scale_value::{Composite, ValueDef, Variant}; use std::{borrow::Cow, sync::Arc}; @@ -48,7 +49,15 @@ pub struct ValidationDetails<'a> { } /// A transaction payload containing some generic `CallData`. -#[derive(Clone, Debug)] +#[derive(Derivative)] +#[derivative( + Clone(bound = "CallData: Clone"), + Debug(bound = "CallData: std::fmt::Debug"), + Eq(bound = "CallData: std::cmp::Eq"), + Ord(bound = "CallData: std::cmp::Ord"), + PartialEq(bound = "CallData: std::cmp::PartialEq"), + PartialOrd(bound = "CallData: std::cmp::PartialOrd") +)] pub struct Payload { pallet_name: Cow<'static, str>, call_name: Cow<'static, str>, From 271e8818ea4fa255f9862125f2202d355a4c1a54 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 12 Feb 2024 13:18:31 +0200 Subject: [PATCH 2/9] subxt/runtime_api: Derive std::cmp traits Signed-off-by: Alexandru Vasile --- subxt/src/runtime_api/runtime_payload.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/subxt/src/runtime_api/runtime_payload.rs b/subxt/src/runtime_api/runtime_payload.rs index cd5a3355b8..ff776eb14f 100644 --- a/subxt/src/runtime_api/runtime_payload.rs +++ b/subxt/src/runtime_api/runtime_payload.rs @@ -69,7 +69,11 @@ pub trait RuntimeApiPayload { #[derive(Derivative)] #[derivative( Clone(bound = "ArgsData: Clone"), - Debug(bound = "ArgsData: std::fmt::Debug") + Debug(bound = "ArgsData: std::fmt::Debug"), + Eq(bound = "ArgsData: std::cmp::Eq"), + Ord(bound = "ArgsData: std::cmp::Ord"), + PartialEq(bound = "ArgsData: std::cmp::PartialEq"), + PartialOrd(bound = "ArgsData: std::cmp::PartialOrd") )] pub struct Payload { trait_name: Cow<'static, str>, From db2fac3f61d8bbf1b4b6817f8d5475bc865c68b2 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 12 Feb 2024 13:23:19 +0200 Subject: [PATCH 3/9] subxt/constants: Derive std::cmp traits Signed-off-by: Alexandru Vasile --- subxt/src/constants/constant_address.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/subxt/src/constants/constant_address.rs b/subxt/src/constants/constant_address.rs index e9a0eb37b0..ed3415b8b3 100644 --- a/subxt/src/constants/constant_address.rs +++ b/subxt/src/constants/constant_address.rs @@ -28,7 +28,14 @@ pub trait ConstantAddress { /// This represents the address of a constant. #[derive(Derivative)] -#[derivative(Clone(bound = ""), Debug(bound = ""))] +#[derivative( + Clone(bound = ""), + Debug(bound = ""), + Eq(bound = ""), + Ord(bound = ""), + PartialEq(bound = ""), + PartialOrd(bound = "") +)] pub struct Address { pallet_name: Cow<'static, str>, constant_name: Cow<'static, str>, From 329bab9488c6b1c387829781457ac6fc184f19c1 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 12 Feb 2024 13:23:35 +0200 Subject: [PATCH 4/9] subxt/custom_values: Derive std::cmp traits Signed-off-by: Alexandru Vasile --- subxt/src/custom_values/custom_value_address.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/subxt/src/custom_values/custom_value_address.rs b/subxt/src/custom_values/custom_value_address.rs index f8034a161b..b21eb5aff3 100644 --- a/subxt/src/custom_values/custom_value_address.rs +++ b/subxt/src/custom_values/custom_value_address.rs @@ -38,7 +38,14 @@ pub struct Yes; /// A static address to a custom value. #[derive(Derivative)] -#[derivative(Clone(bound = ""), Debug(bound = ""))] +#[derivative( + Clone(bound = ""), + Debug(bound = ""), + Eq(bound = ""), + Ord(bound = ""), + PartialEq(bound = ""), + PartialOrd(bound = "") +)] pub struct StaticAddress { name: &'static str, hash: Option<[u8; 32]>, From 890c051926044643748416b0aaa43851954ea4bc Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 12 Feb 2024 13:23:56 +0200 Subject: [PATCH 5/9] subxt/storage: Derive std::cmp traits Signed-off-by: Alexandru Vasile --- subxt/src/storage/storage_address.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/subxt/src/storage/storage_address.rs b/subxt/src/storage/storage_address.rs index 893474b518..2211b20def 100644 --- a/subxt/src/storage/storage_address.rs +++ b/subxt/src/storage/storage_address.rs @@ -55,7 +55,11 @@ pub struct Yes; #[derive(Derivative)] #[derivative( Clone(bound = "StorageKey: Clone"), - Debug(bound = "StorageKey: std::fmt::Debug") + Debug(bound = "StorageKey: std::fmt::Debug"), + Eq(bound = "StorageKey: std::cmp::Eq"), + Ord(bound = "StorageKey: std::cmp::Ord"), + PartialEq(bound = "StorageKey: std::cmp::PartialEq"), + PartialOrd(bound = "StorageKey: std::cmp::PartialOrd") )] pub struct Address { pallet_name: Cow<'static, str>, From eed11c535e63ded13b71e75cb6bade4e7d89be1d Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Mon, 12 Feb 2024 15:19:40 +0200 Subject: [PATCH 6/9] subxt: Fix non_canonical_partial_ord_impl clippy introduced in 1.73 Signed-off-by: Alexandru Vasile --- subxt/src/constants/constant_address.rs | 9 +++++++-- subxt/src/custom_values/custom_value_address.rs | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/subxt/src/constants/constant_address.rs b/subxt/src/constants/constant_address.rs index ed3415b8b3..9a07d13333 100644 --- a/subxt/src/constants/constant_address.rs +++ b/subxt/src/constants/constant_address.rs @@ -33,8 +33,7 @@ pub trait ConstantAddress { Debug(bound = ""), Eq(bound = ""), Ord(bound = ""), - PartialEq(bound = ""), - PartialOrd(bound = "") + PartialEq(bound = "") )] pub struct Address { pallet_name: Cow<'static, str>, @@ -43,6 +42,12 @@ pub struct Address { _marker: std::marker::PhantomData, } +impl PartialOrd for Address { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + /// The type of address typically used to return dynamic constant values. pub type DynamicAddress = Address; diff --git a/subxt/src/custom_values/custom_value_address.rs b/subxt/src/custom_values/custom_value_address.rs index b21eb5aff3..6e2f7f77ea 100644 --- a/subxt/src/custom_values/custom_value_address.rs +++ b/subxt/src/custom_values/custom_value_address.rs @@ -43,8 +43,7 @@ pub struct Yes; Debug(bound = ""), Eq(bound = ""), Ord(bound = ""), - PartialEq(bound = ""), - PartialOrd(bound = "") + PartialEq(bound = "") )] pub struct StaticAddress { name: &'static str, @@ -52,6 +51,12 @@ pub struct StaticAddress { phantom: PhantomData<(ReturnTy, IsDecodable)>, } +impl PartialOrd for StaticAddress { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + impl StaticAddress { #[doc(hidden)] /// Creates a new StaticAddress. From e4b5959ba2cb2cc79262f3407b4ee4702d3e7551 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 13 Feb 2024 10:23:19 +0200 Subject: [PATCH 7/9] subxt: Add comment wrt derivative issue that triggers clippy warning Signed-off-by: Alexandru Vasile --- subxt/src/backend/mod.rs | 1 + subxt/src/constants/constant_address.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/subxt/src/backend/mod.rs b/subxt/src/backend/mod.rs index 3db06818b3..397bbe548f 100644 --- a/subxt/src/backend/mod.rs +++ b/subxt/src/backend/mod.rs @@ -184,6 +184,7 @@ impl PartialEq for BlockRef { } impl Eq for BlockRef {} +// Manual implementation to work aroud https://github.com/mcarton/rust-derivative/issues/115. impl PartialOrd for BlockRef { fn partial_cmp(&self, other: &Self) -> Option { self.hash.partial_cmp(&other.hash) diff --git a/subxt/src/constants/constant_address.rs b/subxt/src/constants/constant_address.rs index 9a07d13333..0a2078baf3 100644 --- a/subxt/src/constants/constant_address.rs +++ b/subxt/src/constants/constant_address.rs @@ -42,6 +42,7 @@ pub struct Address { _marker: std::marker::PhantomData, } +// Manual implementation to work aroud https://github.com/mcarton/rust-derivative/issues/115. impl PartialOrd for Address { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) From 3699a90602f0f41095dbbabf5321ac5bf4694e93 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Tue, 13 Feb 2024 09:41:23 +0100 Subject: [PATCH 8/9] Update subxt/src/backend/mod.rs --- subxt/src/backend/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subxt/src/backend/mod.rs b/subxt/src/backend/mod.rs index 397bbe548f..e816bc904c 100644 --- a/subxt/src/backend/mod.rs +++ b/subxt/src/backend/mod.rs @@ -184,7 +184,7 @@ impl PartialEq for BlockRef { } impl Eq for BlockRef {} -// Manual implementation to work aroud https://github.com/mcarton/rust-derivative/issues/115. +// Manual implementation to work around https://github.com/mcarton/rust-derivative/issues/115. impl PartialOrd for BlockRef { fn partial_cmp(&self, other: &Self) -> Option { self.hash.partial_cmp(&other.hash) From 72ea9be962731af9d064b0553701974dcebabb1c Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Tue, 13 Feb 2024 09:41:32 +0100 Subject: [PATCH 9/9] Update subxt/src/constants/constant_address.rs --- subxt/src/constants/constant_address.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subxt/src/constants/constant_address.rs b/subxt/src/constants/constant_address.rs index 0a2078baf3..3765d4c84b 100644 --- a/subxt/src/constants/constant_address.rs +++ b/subxt/src/constants/constant_address.rs @@ -42,7 +42,7 @@ pub struct Address { _marker: std::marker::PhantomData, } -// Manual implementation to work aroud https://github.com/mcarton/rust-derivative/issues/115. +// Manual implementation to work around https://github.com/mcarton/rust-derivative/issues/115. impl PartialOrd for Address { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other))