diff --git a/changelog.md b/changelog.md index 66750996..ba64a748 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- `Eq` and `Ord` instances for `Operator` + ### Deleted ## [0.3.0.0] diff --git a/src/wallet/lib/Convex/Wallet/Operator.hs b/src/wallet/lib/Convex/Wallet/Operator.hs index ce58cad6..458a32be 100644 --- a/src/wallet/lib/Convex/Wallet/Operator.hs +++ b/src/wallet/lib/Convex/Wallet/Operator.hs @@ -44,9 +44,10 @@ import Convex.Utils (readSigningKeyFromFile, readStakingKeyFromFile, readVerificationKeyFromFile) import Convex.Wallet (addSignature, addSignatureExtended) +import Data.Function (on) import Options.Applicative (Parser, help, long, metavar, optional, strOption) -import PlutusLedgerApi.V1 (PubKeyHash (..)) +import PlutusLedgerApi.V1 (PubKeyHash) data Signing @@ -60,6 +61,18 @@ data PaymentExtendedKey k where deriving stock instance Show (PaymentExtendedKey Signing) deriving stock instance Show (PaymentExtendedKey Verification) +instance Eq (PaymentExtendedKey Signing) where + l == r = show l == show r + +instance Eq (PaymentExtendedKey Verification) where + l == r = show l == show r + +instance Ord (PaymentExtendedKey Signing) where + compare = compare `on` show + +instance Ord (PaymentExtendedKey Verification) where + compare = compare `on` show + verificationKey :: PaymentExtendedKey k -> C.VerificationKey C.PaymentKey verificationKey = \case PESigningEx k -> C.castVerificationKey $ C.getVerificationKey k @@ -89,8 +102,23 @@ data Operator k = deriving stock instance Show (PaymentExtendedKey k) => Show (Operator k) -instance Show (PaymentExtendedKey k) => Eq (Operator k) where - l == r = show l == show r +instance Eq (Operator Signing) where + l == r = + oPaymentKey l == oPaymentKey r && show (oStakeKey l) == show (oStakeKey r) + +instance Eq (Operator Verification) where + l == r = + oPaymentKey l == oPaymentKey r && show (oStakeKey l) == show (oStakeKey r) + +instance Ord (Operator Signing) where + compare = + let mkT Operator{oPaymentKey, oStakeKey} = (oPaymentKey, show oStakeKey) + in compare `on` mkT + +instance Ord (Operator Verification) where + compare = + let mkT Operator{oPaymentKey, oStakeKey} = (oPaymentKey, show oStakeKey) + in compare `on` mkT {-| Address of the operator in a network -}