Skip to content

Commit

Permalink
Add can-sign state observation to deposit state
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Nov 15, 2024
1 parent f37f9e5 commit 1ef83bf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module Cardano.Wallet.Deposit.REST
-- * Internals
, onWalletInstance
, resolveCurrentEraTx
, canSign

) where

Expand Down Expand Up @@ -81,7 +82,8 @@ import Cardano.Wallet.Deposit.IO.Resource
, ErrResourceMissing (..)
)
import Cardano.Wallet.Deposit.Pure
( Credentials
( CanSign
, Credentials
, CurrentEraResolvedTx
, Customer
, ErrCreatePayment
Expand Down Expand Up @@ -452,6 +454,9 @@ getBIP32PathsForOwnedInputs
getBIP32PathsForOwnedInputs =
onWalletInstance . WalletIO.getBIP32PathsForOwnedInputs

canSign :: WalletResourceM CanSign
canSign = onWalletInstance WalletIO.canSign

signTx
:: Write.Tx
-> WalletResourceM (Maybe Write.Tx)
Expand Down
8 changes: 8 additions & 0 deletions lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module Cardano.Wallet.Deposit.IO
, onWalletState
, readWalletState
, resolveCurrentEraTx
, canSign
) where

import Prelude
Expand All @@ -74,6 +75,9 @@ import Cardano.Wallet.Deposit.Pure.API.TxHistory
, ByTime
, LookupTimeFromSlot
)
import Cardano.Wallet.Deposit.Pure.State.Creation
( CanSign
)
import Cardano.Wallet.Deposit.Read
( Address
, TxId
Expand Down Expand Up @@ -356,6 +360,10 @@ resolveCurrentEraTx tx w =
Signing transactions
------------------------------------------------------------------------------}

canSign :: WalletInstance -> IO CanSign
canSign w = do
Wallet.canSign <$> readWalletState w

getBIP32PathsForOwnedInputs
:: Write.Tx -> WalletInstance -> IO [BIP32Path]
getBIP32PathsForOwnedInputs a w =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ module Cardano.Wallet.Deposit.Pure
, BIP32Path (..)
, DerivationType (..)
, ResolvedTx (..)
, canSign
, CanSign (..)
, getBIP32PathsForOwnedInputs
, signTx
, addTxSubmission
Expand All @@ -65,8 +67,10 @@ import Cardano.Wallet.Address.BIP32
, DerivationType (..)
)
import Cardano.Wallet.Deposit.Pure.State.Creation
( Credentials (..)
( CanSign (..)
, Credentials (..)
, WalletPublicIdentity (..)
, canSign
, fromCredentialsAndGenesis
)
import Cardano.Wallet.Deposit.Pure.State.Payment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DeriveGeneric #-}
{-# OPTIONS_GHC -Wno-orphans #-}
{-# LANGUAGE NamedFieldPuns #-}
module Cardano.Wallet.Deposit.Pure.State.Creation
( WalletPublicIdentity (..)
, fromCredentialsAndGenesis
Expand All @@ -10,6 +11,8 @@ module Cardano.Wallet.Deposit.Pure.State.Creation
, xprvFromCredentials
, ErrDecodingXPub (..)
, encodedXPubFromCredentials
, canSign
, CanSign (..)
) where

import Prelude hiding
Expand Down Expand Up @@ -112,6 +115,14 @@ credentialsFromMnemonics mnemonics passphrase =
in
XPrvCredentials encryptedXPrv (toXPub unencryptedXPrv)

data CanSign = CanSign | CannotSign
deriving (Eq, Show)

canSign :: WalletState -> CanSign
canSign WalletState{rootXSignKey} = case rootXSignKey of
Nothing -> CannotSign
Just _ -> CanSign

-- | Create 'Credentials' from an extended public key failures to decode
data ErrDecodingXPub = ErrFromXPubBase16 | ErrFromXPubDecodeKey
deriving (Show, Eq)
Expand Down

0 comments on commit 1ef83bf

Please sign in to comment.