Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add features modules to support open wallet state testing.
- Loading branch information
Showing
6 changed files
with
137 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
module Cardano.Wallet.Address.States.Families where | ||
|
||
import Cardano.Wallet.Address.Derivation | ||
( Depth (..) ) | ||
import Cardano.Wallet.Address.Derivation.Byron | ||
( ByronKey ) | ||
import Cardano.Wallet.Address.Discovery.Random | ||
( RndAnyState, RndState ) | ||
import Cardano.Wallet.Address.Discovery.Sequential | ||
( SeqAnyState, SeqState ) | ||
import Cardano.Wallet.Address.Discovery.Shared | ||
( SharedState ) | ||
import Cardano.Wallet.Address.States.Test.State | ||
( TestState ) | ||
import Cardano.Wallet.Read.NetworkId | ||
( NetworkDiscriminant ) | ||
import Data.Kind | ||
( Type ) | ||
|
||
type family CredFromOf s where | ||
CredFromOf (SharedState n key) = 'CredFromScriptK | ||
CredFromOf (SeqState n key) = 'CredFromKeyK | ||
CredFromOf (RndState n) = 'CredFromKeyK | ||
CredFromOf (TestState s n key kt) = kt | ||
CredFromOf (RndAnyState n p) = 'CredFromKeyK | ||
CredFromOf (SeqAnyState n key p) = 'CredFromKeyK | ||
|
||
-- | A type family to get the key type from a state. | ||
type family KeyOf (s :: Type) :: (Depth -> Type -> Type) where | ||
KeyOf (SeqState n k) = k | ||
KeyOf (RndState n) = ByronKey | ||
KeyOf (SharedState n k) = k | ||
KeyOf (SeqAnyState n k p) = k | ||
KeyOf (RndAnyState n p) = ByronKey | ||
KeyOf (TestState s n k kt) = k | ||
|
||
type family NetworkOf (s :: Type) :: NetworkDiscriminant where | ||
NetworkOf (SeqState n k) = n | ||
NetworkOf (RndState n) = n | ||
NetworkOf (SharedState n k) = n | ||
NetworkOf (SeqAnyState n k p) = n | ||
NetworkOf (RndAnyState n p) = n | ||
NetworkOf (TestState s n k kt) = n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
|
||
module Cardano.Wallet.Address.States.Features | ||
( IsOwned | ||
, TestFeatures (..) | ||
, defaultTestFeatures | ||
) | ||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Crypto.Wallet | ||
( XPrv ) | ||
import Cardano.Wallet.Address.Derivation | ||
( Depth (..) ) | ||
import Cardano.Wallet.Address.Derivation.Shared | ||
() | ||
import Cardano.Wallet.Address.States.Families | ||
( CredFromOf, KeyOf ) | ||
import Cardano.Wallet.Primitive.Passphrase.Types | ||
( Passphrase (..) ) | ||
import Cardano.Wallet.Primitive.Types.Address | ||
( Address (..) ) | ||
|
||
type IsOwned s = | ||
s | ||
-> (KeyOf s 'RootK XPrv, Passphrase "encryption") | ||
-> Address | ||
-> Maybe (KeyOf s (CredFromOf s) XPrv, Passphrase "encryption") | ||
|
||
newtype TestFeatures s = TestFeatures | ||
{ isOwned :: IsOwned s | ||
} | ||
|
||
defaultTestFeatures :: TestFeatures s | ||
defaultTestFeatures = TestFeatures | ||
{ isOwned = error "isOwned: not implemented" | ||
} |
25 changes: 25 additions & 0 deletions
25
lib/wallet/src/Cardano/Wallet/Address/States/Test/State.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE KindSignatures #-} | ||
|
||
module Cardano.Wallet.Address.States.Test.State where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.Address.Derivation | ||
( Depth ) | ||
import Cardano.Wallet.Read.NetworkId | ||
( NetworkDiscriminant ) | ||
import Data.Kind | ||
( Type ) | ||
import GHC.Generics | ||
( Generic ) | ||
|
||
newtype | ||
TestState | ||
s | ||
(n :: NetworkDiscriminant) | ||
(k :: Depth -> Type -> Type) | ||
(ktype :: Depth) | ||
= TestState s | ||
deriving (Generic, Show, Eq) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters