Skip to content

Commit

Permalink
Delete XPub constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mueller committed Oct 11, 2021
1 parent 213522b commit 67f7b6a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
1 change: 0 additions & 1 deletion plutus-contract/src/Wallet/Emulator/MultiAgent.hs
Expand Up @@ -235,7 +235,6 @@ makeLenses ''EmulatorState

walletState :: Wallet -> Lens' EmulatorState Wallet.WalletState
walletState wallet@(Wallet (MockWallet privKey)) = walletStates . at wallet . anon (Wallet.emptyWalletState privKey) (const False)
walletState (Wallet (XPubWallet _)) = error "XPub Wallets not supported in emulator"
walletState (Wallet (CardanoWallet _)) = error "Cardano wallets not supported in emulator"

-- | Get the blockchain as a list of blocks, starting with the oldest (genesis)
Expand Down
7 changes: 1 addition & 6 deletions plutus-contract/src/Wallet/Emulator/Wallet.hs
Expand Up @@ -99,7 +99,6 @@ deriving anyclass instance OpenApi.ToSchema Cardano.Wallet.WalletId

data WalletId =
MockWallet Crypto.XPrv
| XPubWallet Crypto.XPub
| CardanoWallet Cardano.Wallet.WalletId
deriving (Eq, Ord, Generic)
deriving anyclass (ToJSONKey)
Expand All @@ -126,22 +125,19 @@ deriving anyclass instance OpenApi.ToSchema WalletId

toBase16 :: WalletId -> T.Text
toBase16 (MockWallet xprv) = encodeByteString $ Crypto.unXPrv xprv
toBase16 (XPubWallet xpub) = encodeByteString $ Crypto.unXPub xpub
toBase16 (CardanoWallet wllt) = toText wllt

fromBase16 :: T.Text -> Either String WalletId
fromBase16 s = bimap show CardanoWallet (fromText s) <|> decode where
decode = do
bs <- tryDecode s
case BS.length bs of
64 -> XPubWallet <$> Crypto.xpub bs
128 -> MockWallet <$> Crypto.xprv bs
_ -> Left "fromBase16 error: bytestring length should be 64 or 128"
_ -> Left "fromBase16 error: bytestring length should be 128"

-- | Get a wallet's extended public key
walletXPub :: Wallet -> Maybe Crypto.XPub
walletXPub (Wallet (MockWallet xprv)) = Just (Crypto.toXPub xprv)
walletXPub (Wallet (XPubWallet xpub)) = Just xpub
walletXPub _ = Nothing

-- | Get a wallet's public key.
Expand All @@ -152,7 +148,6 @@ walletPubKey = fmap Crypto.xPubToPublicKey . walletXPub
walletPubKeyHash :: Wallet -> PubKeyHash
walletPubKeyHash = \case
Wallet (MockWallet xprv) -> pubKeyHash $ Crypto.xPubToPublicKey $ Crypto.toXPub xprv
Wallet (XPubWallet xpub) -> pubKeyHash $ Crypto.xPubToPublicKey xpub
Wallet (CardanoWallet (Cardano.Wallet.WalletId i)) -> PubKeyHash $ PlutusTx.toBuiltin @ByteString $ convert i

-- | Get a wallet's address.
Expand Down

0 comments on commit 67f7b6a

Please sign in to comment.