@@ -23,7 +23,7 @@ module Cardano.Transaction.Edit
23
23
, toEditableTransaction
24
24
, fromEditableTransactionSafe
25
25
, fromEditableTransaction
26
- , RedeemerPurpose (ForSpend, ForMint, ForReward, ForCert)
26
+ , RedeemerPurpose (ForSpend, ForMint, ForReward, ForCert, ForPropose, ForVote )
27
27
, redeemerPurposeToRedeemerTag
28
28
, DetachedRedeemer
29
29
, EditableTransaction
@@ -36,21 +36,12 @@ module Cardano.Transaction.Edit
36
36
37
37
import Prelude
38
38
39
- import Cardano.Types
40
- ( Certificate
41
- , Redeemer (Redeemer)
42
- , RedeemerTag (Mint, Spend, Reward, Cert)
43
- , RewardAddress
44
- , ScriptHash
45
- , Transaction (Transaction)
46
- , TransactionBody (TransactionBody)
47
- , TransactionInput
48
- , _redeemers
49
- , _witnessSet
50
- )
39
+ import Cardano.Types (Certificate , Redeemer (Redeemer), RedeemerTag (Mint, Spend, Reward, Cert, Propose, Vote), RewardAddress , ScriptHash , Transaction (Transaction), TransactionBody (TransactionBody), TransactionInput , _redeemers , _witnessSet )
51
40
import Cardano.Types.BigNum as BigNum
52
41
import Cardano.Types.ExUnits as ExUnits
53
42
import Cardano.Types.RedeemerDatum (RedeemerDatum )
43
+ import Cardano.Types.Voter (Voter )
44
+ import Cardano.Types.VotingProposal (VotingProposal )
54
45
import Data.Array (catMaybes , findIndex , nub )
55
46
import Data.Array as Array
56
47
import Data.Either (Either , blush , hush , note )
@@ -80,6 +71,8 @@ data RedeemerPurpose
80
71
| ForMint ScriptHash
81
72
| ForReward RewardAddress
82
73
| ForCert Certificate
74
+ | ForVote Voter
75
+ | ForPropose VotingProposal
83
76
84
77
derive instance Generic RedeemerPurpose _
85
78
derive instance Eq RedeemerPurpose
@@ -95,6 +88,8 @@ redeemerPurposeToRedeemerTag = case _ of
95
88
ForMint _ -> Mint
96
89
ForReward _ -> Reward
97
90
ForCert _ -> Cert
91
+ ForPropose _ -> Propose
92
+ ForVote _ -> Vote
98
93
99
94
-- | Contains parts of a transaction that are important for redeemer processing.
100
95
-- | Used to avoid re-computing.
@@ -103,18 +98,21 @@ type RedeemersContext =
103
98
, mintingPolicyHashes :: Array ScriptHash
104
99
, rewardAddresses :: Array RewardAddress
105
100
, certs :: Array Certificate
101
+ , proposals :: Array VotingProposal
102
+ , voters :: Array Voter
106
103
}
107
104
108
105
mkRedeemersContext :: Transaction -> RedeemersContext
109
- mkRedeemersContext
110
- (Transaction { body: TransactionBody { inputs, mint, withdrawals, certs } }) =
111
- { inputs: Set .toUnfoldable $ Set .fromFoldable inputs
106
+ mkRedeemersContext (Transaction { body: TransactionBody txBody }) =
107
+ { inputs: Set .toUnfoldable $ Set .fromFoldable txBody.inputs
112
108
, mintingPolicyHashes:
113
109
Set .toUnfoldable $ Map .keys $ unwrap $ fromMaybe
114
110
(wrap Map .empty)
115
- mint
116
- , rewardAddresses: Set .toUnfoldable $ Map .keys $ withdrawals
117
- , certs
111
+ txBody.mint
112
+ , rewardAddresses: Set .toUnfoldable $ Map .keys $ txBody.withdrawals
113
+ , certs: txBody.certs
114
+ , proposals: txBody.votingProposals
115
+ , voters: Set .toUnfoldable $ Map .keys $ unwrap txBody.votingProcedures
118
116
}
119
117
120
118
detachRedeemer :: RedeemersContext -> Redeemer -> Maybe DetachedRedeemer
@@ -129,6 +127,10 @@ detachRedeemer ctx (Redeemer { tag, index, data: datum, exUnits: _ }) = do
129
127
ForReward <$> Array .index ctx.rewardAddresses indexInt
130
128
Cert ->
131
129
ForCert <$> Array .index ctx.certs indexInt
130
+ Propose ->
131
+ ForPropose <$> Array .index ctx.proposals indexInt
132
+ Vote ->
133
+ ForVote <$> Array .index ctx.voters indexInt
132
134
pure { datum, purpose }
133
135
134
136
attachRedeemers
@@ -149,6 +151,10 @@ attachRedeemer ctx { purpose, datum } = do
149
151
{ tag: Reward , index }
150
152
ForCert cert -> findIndex (eq cert) ctx.certs <#> \index ->
151
153
{ tag: Cert , index }
154
+ ForPropose proposal -> findIndex (eq proposal) ctx.proposals <#> \index ->
155
+ { tag: Propose , index }
156
+ ForVote voter -> findIndex (eq voter) ctx.voters <#> \index ->
157
+ { tag: Vote , index }
152
158
pure $
153
159
Redeemer { tag, index: BigNum .fromInt index, data: datum, exUnits: ExUnits .empty }
154
160
0 commit comments