Skip to content

Commit

Permalink
[ADP-3344] Support Testnet addresses in Deposit Wallet (#4803)
Browse files Browse the repository at this point in the history
This pull request adds support for Testnet addresses in the Deposit
Wallet.

The fact whether we are in Mainnet or a Testnet is computed from
`GenesisData`.

### Issue Number

ADP-3344
  • Loading branch information
HeinrichApfelmus authored Oct 9, 2024
2 parents 99606f7 + 373901e commit 805a175
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 24 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: 45aa257d25871b667cac6fb85e17ceeeac72f421
--sha256: 061hdzgskhp2cc4y8841v27zwkgczsx03xmca1a4aqfs0p600c98
subdir:
lib/customer-deposit-wallet-pure
lib/cardano-wallet-read
Expand Down
1 change: 0 additions & 1 deletion lib/customer-deposit-wallet/customer-deposit-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ library
, bytestring
, cardano-crypto
, cardano-ledger-api
, cardano-ledger-byron
, cardano-strict-containers
, cardano-wallet
, cardano-wallet-network-layer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ findTheDepositWalletOnDisk dir action = do
fromXPubAndGenesis
identity
(fromIntegral @Int users)
(error "FIXME")
Read.mockGenesisDataMainnet
store <- newStore
writeS store state
action $ Right store
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.getNetworkTag 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
19 changes: 6 additions & 13 deletions lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module Cardano.Wallet.Deposit.Read
, Read.EraValue (..)
, Read.Conway

, Network (..)
, Read.SlotNo
, Read.ChainPoint (..)
, Slot
Expand Down Expand Up @@ -47,8 +46,12 @@ module Cardano.Wallet.Deposit.Read
, mockNextBlock
, Read.mockRawHeaderHash

, GenesisData
, GenesisHash
, Read.GenesisData
, Read.GenesisHash
, Read.mockGenesisDataMainnet

, Read.NetworkId (Read.Mainnet, Read.Testnet)
, Read.getNetworkId

-- * Dummy Values useful for testing
, dummyAddress
Expand Down Expand Up @@ -83,7 +86,6 @@ import Data.Word
( Word8
)

import qualified Cardano.Chain.Genesis as Byron
import qualified Cardano.Wallet.Read as Read
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as B8
Expand All @@ -93,7 +95,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 @@ -143,11 +144,3 @@ mockNextBlock old txs =
slotNumber = case old of
Read.GenesisPoint -> Read.SlotNo 0
Read.BlockPoint{slotNo = n} -> succ n

{-----------------------------------------------------------------------------
Genesis
------------------------------------------------------------------------------}

-- GenesisData is not part of the ledger specification proper
type GenesisData = Byron.GenesisData
type GenesisHash = Byron.GenesisHash
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ withScenarioEnvMock action = do
networkEnv <- mapBlock Read.EraValue <$> newNetworkEnvMock
action
$ ScenarioEnv
{ genesisData = error "TODO: Mock Genesis Data"
{ genesisData = Read.mockGenesisDataMainnet
, networkEnv
, faucet = Faucet{xprv = error "TODO: Faucet xprv"}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ testXPub =
------------------------------------------------------------------------------}

testGenesis :: Read.GenesisData
testGenesis = undefined
testGenesis = Read.mockGenesisDataMainnet

spendOneTxOut :: UTxO.UTxO -> Read.Tx
spendOneTxOut utxo =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import qualified Cardano.Wallet.Deposit.Read as Read
import qualified Data.ByteString.Char8 as B8

fakeBootEnv :: WalletBootEnv IO
fakeBootEnv = WalletBootEnv undefined undefined undefined
fakeBootEnv = WalletBootEnv nullTracer Read.mockGenesisDataMainnet undefined

xpub :: XPub
xpub =
Expand Down

0 comments on commit 805a175

Please sign in to comment.