Skip to content

Commit

Permalink
Implement getBIP32PathsForOwnedInputs
Browse files Browse the repository at this point in the history
  • Loading branch information
HeinrichApfelmus committed May 7, 2024
1 parent a357902 commit 1e4db0e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import Prelude
import Cardano.Crypto.Wallet
( XPub
)
import Cardano.Wallet.Address.BIP32
( BIP32Path
)
import Cardano.Wallet.Deposit.Pure
( Customer
, WalletState
Expand Down Expand Up @@ -205,7 +208,7 @@ createPayment a w =
Wallet.createPayment a <$> readWalletState w

getBIP32PathsForOwnedInputs
:: Write.TxBody -> WalletInstance -> IO [()]
:: Write.TxBody -> WalletInstance -> IO [BIP32Path]
getBIP32PathsForOwnedInputs a w =
Wallet.getBIP32PathsForOwnedInputs a <$> readWalletState w

Expand Down
35 changes: 31 additions & 4 deletions lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module Cardano.Wallet.Deposit.Pure

-- ** Writing to the blockchain
, createPayment
, BIP32Path (..)
, DerivationType (..)
, getBIP32PathsForOwnedInputs

, addTxSubmission
Expand All @@ -40,6 +42,10 @@ import Prelude
import Cardano.Crypto.Wallet
( XPub
)
import Cardano.Wallet.Address.BIP32
( BIP32Path (..)
, DerivationType (..)
)
import Cardano.Wallet.Deposit.Pure.UTxOHistory
( UTxOHistory
)
Expand All @@ -58,6 +64,9 @@ import Data.List.NonEmpty
import Data.Map
( Map
)
import Data.Maybe
( mapMaybe
)
import Data.Set
( Set
)
Expand Down Expand Up @@ -166,8 +175,11 @@ rollBackward
rollBackward point w = (w, point) -- FIXME: This is a mock implementation

availableBalance :: WalletState -> Read.Value
availableBalance w =
UTxO.balance $ Balance.availableUTxO utxo pending
availableBalance = UTxO.balance . availableUTxO

availableUTxO :: WalletState -> UTxO.UTxO
availableUTxO w =
Balance.availableUTxO utxo pending
where
pending = listTxsInSubmission w
utxo = UTxOHistory.getUTxO $ utxoHistory w
Expand Down Expand Up @@ -202,8 +214,23 @@ createPayment = undefined
-- needs balanceTx
-- needs to sign the transaction

getBIP32PathsForOwnedInputs :: Write.TxBody -> WalletState -> [()]
getBIP32PathsForOwnedInputs = undefined
getBIP32PathsForOwnedInputs :: Write.TxBody -> WalletState -> [BIP32Path]
getBIP32PathsForOwnedInputs txbody w =
getBIP32Paths w
. resolveInputAddresses
$ Write.spendInputs txbody <> Write.collInputs txbody
where
resolveInputAddresses :: Set Read.TxIn -> [Read.Address]
resolveInputAddresses ins =
map (Read.address . snd)
. UTxO.toList
$ UTxO.restrictedBy (availableUTxO w) ins

getBIP32Paths :: WalletState -> [Read.Address] -> [BIP32Path]
getBIP32Paths w =
mapMaybe (get (addresses w))
where get = undefined
-- get = Address.getBIP32Path

addTxSubmission :: Write.Tx -> WalletState -> WalletState
addTxSubmission _tx _w = undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module Cardano.Wallet.Deposit.Pure.UTxO
( UTxO
, balance
, excluding
, restrictedBy
, filterByAddress
, toList

, DeltaUTxO
, excludingD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Cardano.Wallet.Deposit.Read
, Ix
, TxIn
, TxOut
, address
, Value
, UTxO

Expand Down Expand Up @@ -59,6 +60,7 @@ import qualified Cardano.Wallet.Primitive.Types.Address as W
import qualified Cardano.Wallet.Primitive.Types.TokenBundle as W
import qualified Cardano.Wallet.Primitive.Types.Tx as W
import qualified Cardano.Wallet.Primitive.Types.Tx.TxIn as W
import qualified Cardano.Wallet.Primitive.Types.Tx.TxOut as TxOut
import qualified Cardano.Wallet.Primitive.Types.Tx.TxOut as W
import qualified Cardano.Wallet.Primitive.Types.UTxO as W
import qualified Data.ByteString as BS
Expand Down Expand Up @@ -108,6 +110,9 @@ type TxIn = W.TxIn
-- type TxOut = (Addr, Value)
type TxOut = W.TxOut

address :: TxOut -> Address
address = TxOut.address

type Value = W.TokenBundle

-- type UTxO = Map TxIn TxOut
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import Cardano.Wallet.Deposit.IO.Network.Mock
import Cardano.Wallet.Deposit.IO.Network.Type
( NetworkEnv (..)
)
import Cardano.Wallet.Deposit.Pure
( BIP32Path
)
import Control.Tracer
( nullTracer
)
Expand Down Expand Up @@ -128,9 +131,8 @@ payFromFaucet env destinations =
{-----------------------------------------------------------------------------
Transaction submission
------------------------------------------------------------------------------}
type Path = ()

signTx :: XPrv -> [Path] -> Write.TxBody -> Write.Tx
signTx :: XPrv -> [BIP32Path] -> Write.TxBody -> Write.Tx
signTx _ _ txbody =
Write.Tx
{ Write.txbody = txbody
Expand Down

0 comments on commit 1e4db0e

Please sign in to comment.