Skip to content

Commit 74c3b9d

Browse files
committed
Export a deposit public identity type from REST api
1 parent 9b0b464 commit 74c3b9d

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/IO.hs

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Cardano.Wallet.Deposit.IO
66
-- * Types
77
WalletEnv (..)
88
, WalletBootEnv (..)
9+
, WalletPublicIdentity (..)
910
, WalletInstance
1011

1112
-- * Operations
@@ -29,6 +30,7 @@ module Cardano.Wallet.Deposit.IO
2930
, getBIP32PathsForOwnedInputs
3031
, signTxBody
3132
, WalletStore
33+
, walletPublicIdentity
3234
) where
3335

3436
import Prelude
@@ -193,6 +195,18 @@ createAddress c w =
193195
let (r,s1) = Wallet.createAddress c s0
194196
in (Delta.Replace s1, r)
195197

198+
data WalletPublicIdentity = WalletPublicIdentity
199+
{ pubXpub :: XPub
200+
, pubNextUser :: Word31
201+
}
202+
203+
walletPublicIdentity :: WalletInstance -> IO WalletPublicIdentity
204+
walletPublicIdentity w = do
205+
state <- readWalletState w
206+
pure $ WalletPublicIdentity
207+
{ pubXpub = Wallet.walletXPub state
208+
, pubNextUser = Wallet.nextCustomer state
209+
}
196210
{-----------------------------------------------------------------------------
197211
Operations
198212
Reading from the blockchain

lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Pure.hs

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module Cardano.Wallet.Deposit.Pure
3838

3939
, addTxSubmission
4040
, listTxsInSubmission
41+
, nextCustomer
42+
, walletXPub
4143
) where
4244

4345
import Prelude
@@ -83,6 +85,7 @@ import qualified Cardano.Wallet.Deposit.Pure.UTxOHistory as UTxOHistory
8385
import qualified Cardano.Wallet.Deposit.Read as Read
8486
import qualified Cardano.Wallet.Deposit.Write as Write
8587
import qualified Data.Delta as Delta
88+
import qualified Data.Map as Map
8689
import qualified Data.Set as Set
8790

8891
{-----------------------------------------------------------------------------
@@ -137,6 +140,12 @@ isCustomerAddress address =
137140
fromRawCustomer :: Word31 -> Customer
138141
fromRawCustomer = id
139142

143+
nextCustomer :: WalletState -> Customer
144+
nextCustomer = maybe 0 snd . Map.lookupMax . Address.addresses . addresses
145+
146+
walletXPub :: WalletState -> XPub
147+
walletXPub = Address.getXPub . addresses
148+
140149
{-----------------------------------------------------------------------------
141150
Operations
142151
Reading from the blockchain

lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/REST.hs

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module Cardano.Wallet.Deposit.REST
4343
, getBIP32PathsForOwnedInputs
4444
, signTxBody
4545
, walletExists
46+
, walletPublicIdentity
4647
) where
4748

4849
import Prelude
@@ -57,6 +58,9 @@ import Cardano.Crypto.Wallet
5758
import Cardano.Wallet.Address.BIP32
5859
( BIP32Path
5960
)
61+
import Cardano.Wallet.Deposit.IO
62+
( WalletPublicIdentity
63+
)
6064
import Cardano.Wallet.Deposit.IO.Resource
6165
( ErrResourceExists (..)
6266
, ErrResourceMissing (..)
@@ -315,6 +319,9 @@ walletExists fp = liftIO $ findTheDepositWalletOnDisk fp $ \case
315319
Right _ -> pure True
316320
Left _ -> pure False
317321

322+
walletPublicIdentity :: WalletResourceM WalletPublicIdentity
323+
walletPublicIdentity = onWalletInstance WalletIO.walletPublicIdentity
324+
318325
{-----------------------------------------------------------------------------
319326
Operations
320327
------------------------------------------------------------------------------}

0 commit comments

Comments
 (0)