Skip to content

Commit

Permalink
Add walletPubKey and update the definition of walletPubKeyHash (fix I…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffhappily committed Nov 12, 2021
1 parent eabb8c0 commit 7f1adb1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions plutus-contract/src/Plutus/Contract/Trace.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module Plutus.Contract.Trace
, defaultDistFor
-- * Wallets
, EM.Wallet(..)
, EM.walletPubKey
, EM.walletPubKeyHash
, EM.knownWallets
, EM.knownWallet
Expand Down
1 change: 1 addition & 0 deletions plutus-contract/src/Wallet/Emulator/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Wallet.Emulator.Types(
WalletId(..),
Crypto.XPrv,
Crypto.XPub,
walletPubKey,
walletPubKeyHash,
addSignature,
knownWallets,
Expand Down
12 changes: 8 additions & 4 deletions plutus-contract/src/Wallet/Emulator/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,18 @@ fromBase16 s = bimap show WalletId (fromText s)
walletMockWallet :: Wallet -> Maybe MockWallet
walletMockWallet (Wallet wid) = find ((==) wid . WalletId . CW.mwWalletId) CW.knownWallets

-- | The public key hash of a mock wallet. (Fails if the wallet is not a mock wallet).
walletPubKeyHash :: Wallet -> PubKeyHash
walletPubKeyHash w = CW.pubKeyHash
$ fromMaybe (error $ "Wallet.Emulator.Wallet.walletPubKeyHash: Wallet "
-- | The public key of a mock wallet. (Fails if the wallet is not a mock wallet).
walletPubKey :: Wallet -> PubKey
walletPubKey w = CW.pubKey
$ fromMaybe (error $ "Wallet.Emulator.Wallet.walletPubKey: Wallet "
<> show w
<> " is not a mock wallet")
$ walletMockWallet w

-- | The public key hash of a mock wallet. (Fails if the wallet is not a mock wallet).
walletPubKeyHash :: Wallet -> PubKeyHash
walletPubKeyHash = pubKeyHash . walletPubKey

-- | Get the address of a mock wallet. (Fails if the wallet is not a mock wallet).
walletAddress :: Wallet -> Address
walletAddress = pubKeyHashAddress . walletPubKeyHash
Expand Down

0 comments on commit 7f1adb1

Please sign in to comment.