From 7f1adb16f77b44ba22b886d182e16877df8c6e2f Mon Sep 17 00:00:00 2001 From: Jeff Happily Date: Fri, 12 Nov 2021 16:57:28 +0800 Subject: [PATCH] Add walletPubKey and update the definition of walletPubKeyHash (fix #104) --- plutus-contract/src/Plutus/Contract/Trace.hs | 1 + plutus-contract/src/Wallet/Emulator/Types.hs | 1 + plutus-contract/src/Wallet/Emulator/Wallet.hs | 12 ++++++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/plutus-contract/src/Plutus/Contract/Trace.hs b/plutus-contract/src/Plutus/Contract/Trace.hs index 6083685a79..a859074c4f 100644 --- a/plutus-contract/src/Plutus/Contract/Trace.hs +++ b/plutus-contract/src/Plutus/Contract/Trace.hs @@ -41,6 +41,7 @@ module Plutus.Contract.Trace , defaultDistFor -- * Wallets , EM.Wallet(..) + , EM.walletPubKey , EM.walletPubKeyHash , EM.knownWallets , EM.knownWallet diff --git a/plutus-contract/src/Wallet/Emulator/Types.hs b/plutus-contract/src/Wallet/Emulator/Types.hs index 5e9b25f9eb..4bea56fd71 100644 --- a/plutus-contract/src/Wallet/Emulator/Types.hs +++ b/plutus-contract/src/Wallet/Emulator/Types.hs @@ -17,6 +17,7 @@ module Wallet.Emulator.Types( WalletId(..), Crypto.XPrv, Crypto.XPub, + walletPubKey, walletPubKeyHash, addSignature, knownWallets, diff --git a/plutus-contract/src/Wallet/Emulator/Wallet.hs b/plutus-contract/src/Wallet/Emulator/Wallet.hs index d9f8db1f52..efeb20be04 100644 --- a/plutus-contract/src/Wallet/Emulator/Wallet.hs +++ b/plutus-contract/src/Wallet/Emulator/Wallet.hs @@ -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