Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADP 3491] Relax policy key guard #4850

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 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,18 @@ 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 ->
if isJust mintBurnReferenceScriptTemplate then
liftHandler $ throwE W.ErrReadPolicyPublicKeyAbsent
else
pure Nothing

let transactionCtx3 = transactionCtx2
{ txReferenceScript = referenceScriptM
Expand All @@ -2727,7 +2740,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
Loading