pull own output filtering out of the pmatch block
This commit is contained in:
parent
ee6ae128de
commit
14a8b9eece
1 changed files with 23 additions and 17 deletions
|
|
@ -186,6 +186,28 @@ proposalValidator proposal =
|
||||||
|
|
||||||
currentTime <- tclet $ currentProposalTime # txInfoF.validRange
|
currentTime <- tclet $ currentProposalTime # txInfoF.validRange
|
||||||
|
|
||||||
|
-- Filter out own output with own address and PST.
|
||||||
|
-- Delay the evaluation cause in some cases there won't be any continuing output.
|
||||||
|
ownOutputD <-
|
||||||
|
tclet $
|
||||||
|
pdelay $
|
||||||
|
mustBePJust # "Own output should be present" #$ pfind
|
||||||
|
# plam
|
||||||
|
( \input -> unTermCont $ do
|
||||||
|
inputF <- tcont $ pletFields @'["address", "value"] input
|
||||||
|
pure $
|
||||||
|
inputF.address #== ownAddress
|
||||||
|
#&& psymbolValueOf # stCurrencySymbol # inputF.value #== 1
|
||||||
|
)
|
||||||
|
# pfromData txInfoF.outputs
|
||||||
|
|
||||||
|
proposalOutD <-
|
||||||
|
tclet $
|
||||||
|
pdelay $
|
||||||
|
mustFindDatum' @PProposalDatum
|
||||||
|
# (pfield @"datumHash" # pforce ownOutputD)
|
||||||
|
# txInfoF.datums
|
||||||
|
|
||||||
pure $
|
pure $
|
||||||
pmatch proposalRedeemer $ \case
|
pmatch proposalRedeemer $ \case
|
||||||
PVote r -> unTermCont $ do
|
PVote r -> unTermCont $ do
|
||||||
|
|
@ -228,22 +250,6 @@ proposalValidator proposal =
|
||||||
)
|
)
|
||||||
# pfromData stakeInF.lockedBy
|
# pfromData stakeInF.lockedBy
|
||||||
|
|
||||||
-- TODO: maybe we can move this outside of the pmatch block.
|
|
||||||
-- Filter out own output with own address and PST.
|
|
||||||
let ownOutput =
|
|
||||||
mustBePJust # "Own output should be present" #$ pfind
|
|
||||||
# plam
|
|
||||||
( \input -> unTermCont $ do
|
|
||||||
inputF <- tcont $ pletFields @'["address", "value"] input
|
|
||||||
pure $
|
|
||||||
inputF.address #== ownAddress
|
|
||||||
#&& psymbolValueOf # stCurrencySymbol # inputF.value #== 1
|
|
||||||
)
|
|
||||||
# pfromData txInfoF.outputs
|
|
||||||
|
|
||||||
proposalOut :: Term _ PProposalDatum
|
|
||||||
proposalOut = mustFindDatum' # (pfield @"datumHash" # ownOutput) # txInfoF.datums
|
|
||||||
|
|
||||||
let -- Update the vote counter of the proposal, and leave other stuff as is.
|
let -- Update the vote counter of the proposal, and leave other stuff as is.
|
||||||
expectedNewVotes = pmatch (pfromData proposalF.votes) $ \(PProposalVotes m) ->
|
expectedNewVotes = pmatch (pfromData proposalF.votes) $ \(PProposalVotes m) ->
|
||||||
pcon $
|
pcon $
|
||||||
|
|
@ -268,7 +274,7 @@ proposalValidator proposal =
|
||||||
.& #startingTime .= proposalF.startingTime
|
.& #startingTime .= proposalF.startingTime
|
||||||
)
|
)
|
||||||
|
|
||||||
tcassert "Output proposal should be valid" $ proposalOut #== expectedProposalOut
|
tcassert "Output proposal should be valid" $ pforce proposalOutD #== expectedProposalOut
|
||||||
|
|
||||||
-- We validate the output stake datum here as well: We need the vote option
|
-- We validate the output stake datum here as well: We need the vote option
|
||||||
-- to create a valid 'ProposalLock', however the vote option is encoded
|
-- to create a valid 'ProposalLock', however the vote option is encoded
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue