Skip to content

Commit

Permalink
wallet: Add Eq and Ord instance for operator (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mueller authored Jan 26, 2024
1 parent b4123bf commit c9de3a4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
34 changes: 31 additions & 3 deletions src/wallet/lib/Convex/Wallet/Operator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
-}
Expand Down

0 comments on commit c9de3a4

Please sign in to comment.