@@ -130,7 +130,7 @@ type TxInfoV3 struct {
130130 Redeemers KeyValuePairs [ScriptInfo , Redeemer ]
131131 Data KeyValuePairs [lcommon.Blake2b256 , data.PlutusData ]
132132 Id lcommon.Blake2b256
133- Votes KeyValuePairs [lcommon.Voter , KeyValuePairs [lcommon.GovActionId , lcommon.VotingProcedure ]]
133+ Votes KeyValuePairs [* lcommon.Voter , KeyValuePairs [* lcommon.GovActionId , lcommon.VotingProcedure ]]
134134 ProposalProcedures []lcommon.ProposalProcedure
135135 CurrentTreasuryAmount Option [Coin ]
136136 TreasuryDonation Option [PositiveCoin ]
@@ -160,8 +160,7 @@ func (t TxInfoV3) ToPlutusData() data.PlutusData {
160160 tmpRedeemers .ToPlutusData (),
161161 t .Data .ToPlutusData (),
162162 data .NewByteString (t .Id .Bytes ()),
163- // TODO: votes
164- data .NewMap ([][2 ]data.PlutusData {}),
163+ t .Votes .ToPlutusData (),
165164 // TODO: proposal procedures
166165 toPlutusData ([]any {}),
167166 t .CurrentTreasuryAmount .ToPlutusData (),
@@ -188,6 +187,7 @@ func NewTxInfoV3FromTransaction(
188187 }
189188 inputs := sortInputs (tx .Inputs ())
190189 withdrawals := withdrawalsInfo (tx .Withdrawals ())
190+ votes := votingInfo (tx .VotingProcedures ())
191191 redeemers := redeemersInfo (
192192 tx .Witnesses (),
193193 scriptPurposeBuilder (
@@ -197,7 +197,7 @@ func NewTxInfoV3FromTransaction(
197197 tx .Certificates (),
198198 withdrawals ,
199199 // TODO: proposal procedures
200- // TODO: votes
200+ votes ,
201201 ),
202202 )
203203 tmpData := dataInfo (tx .Witnesses ())
@@ -217,7 +217,7 @@ func NewTxInfoV3FromTransaction(
217217 Redeemers : redeemers ,
218218 Data : tmpData ,
219219 Id : tx .Hash (),
220- // TODO: Votes
220+ Votes : votes ,
221221 // TODO: ProposalProcedures
222222 }
223223 if amt := tx .CurrentTreasuryValue (); amt > 0 {
@@ -454,6 +454,80 @@ func signatoriesInfo(
454454 return tmp
455455}
456456
457+ func votingInfo (
458+ votingProcedures lcommon.VotingProcedures ,
459+ ) KeyValuePairs [* lcommon.Voter , KeyValuePairs [* lcommon.GovActionId , lcommon.VotingProcedure ]] {
460+ var ret KeyValuePairs [* lcommon.Voter , KeyValuePairs [* lcommon.GovActionId , lcommon.VotingProcedure ]]
461+ for voter , voterData := range votingProcedures {
462+ voterPairs := make (KeyValuePairs [* lcommon.GovActionId , lcommon.VotingProcedure ], 0 , len (votingProcedures ))
463+ for govActionId , votingProcedure := range voterData {
464+ voterPairs = append (
465+ voterPairs ,
466+ KeyValuePair [* lcommon.GovActionId , lcommon.VotingProcedure ]{
467+ Key : govActionId ,
468+ Value : votingProcedure ,
469+ },
470+ )
471+ }
472+ // Sort voter pairs by gov action ID
473+ slices .SortFunc (
474+ voterPairs ,
475+ func (a , b KeyValuePair [* lcommon.GovActionId , lcommon.VotingProcedure ]) int {
476+ // Compare TX ID
477+ x := bytes .Compare (a .Key .TransactionId [:], b .Key .TransactionId [:])
478+ if x != 0 {
479+ return x
480+ }
481+ // Compare index
482+ if a .Key .GovActionIdx < b .Key .GovActionIdx {
483+ return - 1
484+ } else if a .Key .GovActionIdx > b .Key .GovActionIdx {
485+ return 1
486+ }
487+ return 0
488+ },
489+ )
490+ ret = append (
491+ ret ,
492+ KeyValuePair [* lcommon.Voter , KeyValuePairs [* lcommon.GovActionId , lcommon.VotingProcedure ]]{
493+ Key : voter ,
494+ Value : voterPairs ,
495+ },
496+ )
497+ }
498+ // Sort by voter ID
499+ slices .SortFunc (
500+ ret ,
501+ func (a , b KeyValuePair [* lcommon.Voter , KeyValuePairs [* lcommon.GovActionId , lcommon.VotingProcedure ]]) int {
502+ voterTag := func (v * lcommon.Voter ) int {
503+ switch v .Type {
504+ case lcommon .VoterTypeConstitutionalCommitteeHotScriptHash :
505+ return 0
506+ case lcommon .VoterTypeConstitutionalCommitteeHotKeyHash :
507+ return 1
508+ case lcommon .VoterTypeDRepScriptHash :
509+ return 2
510+ case lcommon .VoterTypeDRepKeyHash :
511+ return 3
512+ case lcommon .VoterTypeStakingPoolKeyHash :
513+ return 4
514+ }
515+ return - 1
516+ }
517+ tagA := voterTag (a .Key )
518+ tagB := voterTag (b .Key )
519+ if tagA == tagB {
520+ return bytes .Compare (a .Key .Hash [:], b .Key .Hash [:])
521+ }
522+ if tagA < tagB {
523+ return - 1
524+ }
525+ return 1
526+ },
527+ )
528+ return ret
529+ }
530+
457531func certificatesToPlutusData (
458532 certificates []lcommon.Certificate ,
459533) data.PlutusData {
0 commit comments