Skip to content

Commit

Permalink
involve policyXPub guard only when minting is part of tx
Browse files Browse the repository at this point in the history
handle reference script situation

resign from fremJust
  • Loading branch information
paweljakubas committed Nov 20, 2024
1 parent 7cd80a3 commit ea516e3
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@ constructTransaction api knownPools poolStatus apiWalletId body = do
_ -> pure ()

when (isJust (body ^. #encryptMetadata) && isNothing (body ^. #metadata) ) $
liftHandler $ throwE ErrConstructTxWrongPayload
liftHandler $ throwE ErrConstructTxWrongPayload

metadata <- case (body ^. #encryptMetadata, body ^. #metadata) of
(Just apiEncrypt, Just metadataWithSchema) -> do
Expand Down Expand Up @@ -2631,11 +2631,17 @@ constructTransaction api knownPools poolStatus apiWalletId body = do
Just action ->
transactionCtx0 { txDelegationAction = Just action }

(policyXPub, _) <-
liftHandler $ W.readPolicyPublicKey wrk
policyXPubM <-
if isJust mintBurnDatum || isJust mintBurnReferenceScriptTemplate then
liftHandler $ Just . fst <$> W.readPolicyPublicKey wrk
else
pure Nothing

transactionCtx2 <-
if isJust mintBurnDatum then do
policyXPub <- case policyXPubM of
Just val -> pure val
Nothing -> liftHandler $ throwE W.ErrReadPolicyPublicKeyAbsent
let isMinting mb = case mb ^. #mintBurnData of
Left (ApiMintBurnDataFromScript _ _ (ApiMint _)) -> True
Right (ApiMintBurnDataFromInput _ _ _ (ApiMint _)) -> True
Expand Down Expand Up @@ -2701,11 +2707,15 @@ constructTransaction api knownPools poolStatus apiWalletId body = do
else
pure transactionCtx1

let referenceScriptM =
referenceScriptM <- case policyXPubM of
Just policyXPub ->
pure $
replaceCosigner
ShelleyKeyS
(Map.singleton (Cosigner 0) policyXPub)
<$> mintBurnReferenceScriptTemplate
Nothing ->
liftHandler $ throwE W.ErrReadPolicyPublicKeyAbsent

let transactionCtx3 = transactionCtx2
{ txReferenceScript = referenceScriptM
Expand All @@ -2727,7 +2737,7 @@ constructTransaction api knownPools poolStatus apiWalletId body = do
mintingOuts = case mintBurnDatum of
Just mintBurns ->
coalesceTokensPerAddr $
map (toMintTxOut policyXPub) $
map (toMintTxOut (fromJust policyXPubM)) $
filter mintWithAddress $
NE.toList mintBurns
Nothing -> []
Expand Down

0 comments on commit ea516e3

Please sign in to comment.