diff --git a/lib/api/src/Cardano/Wallet/Api/Http/Server/Handlers/MintBurn.hs b/lib/api/src/Cardano/Wallet/Api/Http/Server/Handlers/MintBurn.hs index 0301154933e..82f43f617f2 100644 --- a/lib/api/src/Cardano/Wallet/Api/Http/Server/Handlers/MintBurn.hs +++ b/lib/api/src/Cardano/Wallet/Api/Http/Server/Handlers/MintBurn.hs @@ -44,9 +44,6 @@ import Control.Category import Control.Monad.IO.Class ( MonadIO (liftIO) ) -import Control.Monad.Trans.Except - ( runExceptT - ) import Data.Either.Extra ( eitherToMaybe ) @@ -62,7 +59,7 @@ convertApiAssetMintBurn -> Handler (ApiAssetMintBurn, ApiAssetMintBurn) convertApiAssetMintBurn ctx (mint, burn) = do xpubM <- fmap (fmap fst . eitherToMaybe) - <$> liftIO . runExceptT $ readPolicyPublicKey ctx + <$> liftIO $ readPolicyPublicKey ctx let convert tokenWithScripts = ApiAssetMintBurn { tokens = toApiTokens tokenWithScripts , walletPolicyKeyHash = diff --git a/lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs b/lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs index eaac0a99269..f757ac82a56 100644 --- a/lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs +++ b/lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs @@ -2632,10 +2632,7 @@ constructTransaction api knownPools poolStatus apiWalletId body = do transactionCtx0 { txDelegationAction = Just action } policyXPubM <- - if isJust mintBurnDatum || isJust mintBurnReferenceScriptTemplate then - liftHandler $ Just . fst <$> W.readPolicyPublicKey wrk - else - pure Nothing + fmap fst . eitherToMaybe <$> liftIO (W.readPolicyPublicKey wrk) transactionCtx2 <- if isJust mintBurnDatum then do @@ -3434,8 +3431,18 @@ decodeTransaction let ApiDecodeTransactionPostData (ApiT sealed) decryptMetadata = postData era <- liftIO $ NW.currentNodeEra netLayer withWorkerCtx ctx wid liftE liftE $ \wrk -> do - (k, _) <- liftHandler $ W.readPolicyPublicKey wrk - let keyhash = KeyHash Policy (xpubToBytes k) + policyKeyM <- + fmap fst . eitherToMaybe <$> liftIO (W.readPolicyPublicKey wrk) + let txWitnessCount = + mkApiWitnessCount + . witnessCount + $ maybe + AnyWitnessCountCtx + ( ShelleyWalletCtx + . KeyHash Policy + . xpubToBytes + ) + policyKeyM TxExtended{..} = decodeTx tl era sealed Tx { txId , fee @@ -3492,8 +3499,7 @@ decodeTransaction , metadata = ApiTxMetadata metadata' , scriptValidity = ApiT <$> scriptValidity , validityInterval = ApiValidityIntervalExplicit <$> validity - , witnessCount = mkApiWitnessCount $ witnessCount - $ ShelleyWalletCtx keyhash + , witnessCount = txWitnessCount } where tl = ctx ^. W.transactionLayer @(KeyOf s) @'CredFromKeyK @@ -4425,7 +4431,7 @@ getPolicyKey -> Handler ApiPolicyKey getPolicyKey ctx (ApiT wid) hashed = do withWorkerCtx @_ @s ctx wid liftE liftE $ \wrk -> do - (k, _) <- liftHandler $ W.readPolicyPublicKey wrk + (k, _) <- liftHandler $ ExceptT $ W.readPolicyPublicKey wrk pure $ uncurry ApiPolicyKey (computeKeyPayload hashed k) postPolicyKey @@ -4468,7 +4474,7 @@ postPolicyId ctx (ApiT wid) payload = do liftHandler $ throwE ErrGetPolicyIdWrongMintingBurningTemplate withWorkerCtx @_ @s ctx wid liftE liftE $ \wrk -> do - (xpub, _) <- liftHandler $ W.readPolicyPublicKey wrk + (xpub, _) <- liftHandler $ ExceptT $ W.readPolicyPublicKey wrk pure $ ApiPolicyId $ ApiT $ toTokenPolicyId (keyFlavorFromState @s) scriptTempl (Map.singleton (Cosigner 0) xpub) diff --git a/lib/wallet/src/Cardano/Wallet.hs b/lib/wallet/src/Cardano/Wallet.hs index 10f9d1b8f9c..0dde86e8fb7 100644 --- a/lib/wallet/src/Cardano/Wallet.hs +++ b/lib/wallet/src/Cardano/Wallet.hs @@ -1670,20 +1670,23 @@ readPolicyPublicKey :: forall s . WalletFlavor s => WalletLayer IO s - -> ExceptT ErrReadPolicyPublicKey IO (XPub, NonEmpty DerivationIndex) -readPolicyPublicKey ctx = db & \DBLayer{..} -> do - cp <- lift $ atomically readCheckpoint - case walletFlavor @s of - ShelleyWallet -> do - let s = getState cp - case Seq.policyXPub s of - Nothing -> throwE ErrReadPolicyPublicKeyAbsent - Just xpub -> pure - ( getRawKey (keyFlavorFromState @s) xpub - , policyDerivationPath - ) - _ -> - throwE ErrReadPolicyPublicKeyNotAShelleyWallet + -> IO (Either ErrReadPolicyPublicKey (XPub, NonEmpty DerivationIndex)) +readPolicyPublicKey ctx = + db & \DBLayer{..} -> do + cp <- atomically readCheckpoint + case walletFlavor @s of + ShelleyWallet -> do + let s = getState cp + case Seq.policyXPub s of + Nothing -> pure $ Left ErrReadPolicyPublicKeyAbsent + Just xpub -> + pure + $ Right + ( getRawKey (keyFlavorFromState @s) xpub + , policyDerivationPath + ) + _ -> + pure $ Left ErrReadPolicyPublicKeyNotAShelleyWallet where db = ctx ^. dbLayer