Skip to content

Commit

Permalink
wip Adapt to NetworkId from pure Deposit Wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
HeinrichApfelmus committed Oct 7, 2024
1 parent 6b485dc commit b7404c6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/cardano-foundation/cardano-wallet-agda
tag: e2684108476c4c5f80a9d7d095e3bc201b7c3484
--sha256: 1bhldh54myqh4kbb02w2si5l4rf3dwblz75234nmg6w5319b7vm7
tag: 59079695998a23a1d63c52fab7df624f20b491c8
--sha256: 1pkfjw3f8mf2y2cjqjnwv02044h3w4sv02sblaml4b2dr026byqm
subdir:
lib/customer-deposit-wallet-pure
lib/cardano-wallet-read
Expand Down
12 changes: 8 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 @@ -136,8 +136,10 @@ customerAddress c = lookup c . listCustomers
-- depend on the private key only, not on the entire wallet state
deriveAddress :: WalletState -> (Customer -> Address)
deriveAddress w =
Address.deriveAddress (Address.getXPub (addresses w))
Address.deriveAddress (Address.network as) (Address.getXPub as)
. Address.DerivationCustomer
where
as = addresses w

-- FIXME: More performant with a double index.
knownCustomer :: Customer -> WalletState -> Bool
Expand Down Expand Up @@ -165,16 +167,18 @@ walletXPub = Address.getXPub . addresses
Reading from the blockchain
------------------------------------------------------------------------------}

fromXPubAndGenesis :: XPub -> Word31 -> Read.GenesisData -> WalletState
fromXPubAndGenesis xpub knownCustomerCount _ =
fromXPubAndGenesis
:: XPub -> Word31 -> Read.GenesisData -> WalletState
fromXPubAndGenesis xpub knownCustomerCount genesisData =
WalletState
{ addresses =
Address.fromXPubAndCount xpub knownCustomerCount
Address.fromXPubAndCount network xpub knownCustomerCount
, utxoHistory = UTxOHistory.empty initialUTxO
, submissions = Sbm.empty
, rootXSignKey = Nothing
}
where
network = Read.getNetworkId genesisData
initialUTxO = mempty

getWalletTip :: WalletState -> Read.ChainPoint
Expand Down
16 changes: 14 additions & 2 deletions lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module Cardano.Wallet.Deposit.Read
, Read.EraValue (..)
, Read.Conway

, Network (..)
, Read.SlotNo
, Read.ChainPoint (..)
, Slot
Expand Down Expand Up @@ -52,13 +51,19 @@ module Cardano.Wallet.Deposit.Read
, GenesisData
, GenesisHash
, mockGenesisDataMainnet
, NetworkId
, Network (Mainnet, Testnet)
, getNetworkId

-- * Dummy Values useful for testing
, dummyAddress
) where

import Prelude

import Cardano.Wallet.Deposit.Read.Temp
( Network (Mainnet, Testnet)
)
import Cardano.Wallet.Read.Block.Gen
( mkBlockEra
)
Expand Down Expand Up @@ -102,7 +107,6 @@ import qualified Data.ByteString.Short as SBS
Type definitions
with dummies
------------------------------------------------------------------------------}
data Network = Testnet | Mainnet

-- | Synonym for readability.
-- The ledger specifications define @Addr@.
Expand Down Expand Up @@ -202,3 +206,11 @@ protocolParametersMainnet = Byron.ProtocolParameters
mkLovelacePortionFromGenesisJSON :: Rational -> Byron.LovelacePortion
mkLovelacePortionFromGenesisJSON n =
Byron.rationalToLovelacePortion (n / 10^(15 :: Integer))

type NetworkId = Network

getNetworkId :: GenesisData -> NetworkId
getNetworkId genesisData =
if Byron.gdProtocolMagicId genesisData == Byron.mainnetProtocolMagicId
then Mainnet
else Testnet

0 comments on commit b7404c6

Please sign in to comment.