Skip to content

Commit

Permalink
Add Eq and Ord instances for BIP32Path (#31)
Browse files Browse the repository at this point in the history
This pull request adds `Eq` and `Ord` class instances for `BIP32Path` so
that this type can be used in a container type such as `Data.Set.Set`.
  • Loading branch information
HeinrichApfelmus committed May 7, 2024
2 parents 42c6dcf + 42c9404 commit edcece2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,35 @@ data DerivationType : Set where
Hardened : DerivationType

open DerivationType public

{-# COMPILE AGDA2HS DerivationType #-}

instance
iEqDerivationType : Eq DerivationType
iEqDerivationType ._==_ Soft Soft = True
iEqDerivationType ._==_ Hardened Hardened = True
iEqDerivationType ._==_ _ _ = False
{-# COMPILE AGDA2HS iEqDerivationType derive #-}

postulate instance
iOrdDerivationType : Ord DerivationType
{-# COMPILE AGDA2HS iOrdDerivationType #-}

-- | An absolute BIP32 Path.
data BIP32Path : Set where
Root : BIP32Path
Segment : BIP32Path DerivationType Word31 BIP32Path

open BIP32Path public

{-# COMPILE AGDA2HS BIP32Path #-}

instance
iEqBIP32Path : Eq BIP32Path
iEqBIP32Path ._==_ Root Root = True
iEqBIP32Path ._==_ (Segment a1 b1 c1) (Segment a2 b2 c2) =
a1 == a2 && b1 == b2 && c1 == c2
iEqBIP32Path ._==_ _ _ = False
{-# COMPILE AGDA2HS iEqBIP32Path derive #-}

postulate instance
iOrdBIP32Path : Ord BIP32Path
{-# COMPILE AGDA2HS iOrdBIP32Path #-}
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
{-# LANGUAGE StandaloneDeriving #-}
module Cardano.Wallet.Address.BIP32 where

import Data.Word.Odd (Word31)

data DerivationType = Soft
| Hardened

deriving instance Eq DerivationType

deriving instance Ord DerivationType

data BIP32Path = Root
| Segment BIP32Path DerivationType Word31

deriving instance Eq BIP32Path

deriving instance Ord BIP32Path

0 comments on commit edcece2

Please sign in to comment.