@@ -130,7 +130,7 @@ type TxInfoV3 struct {
130
130
Redeemers KeyValuePairs [ScriptInfo , Redeemer ]
131
131
Data KeyValuePairs [lcommon.Blake2b256 , data.PlutusData ]
132
132
Id lcommon.Blake2b256
133
- Votes KeyValuePairs [lcommon.Voter , KeyValuePairs [lcommon.GovActionId , lcommon.VotingProcedure ]]
133
+ Votes KeyValuePairs [* lcommon.Voter , KeyValuePairs [* lcommon.GovActionId , lcommon.VotingProcedure ]]
134
134
ProposalProcedures []lcommon.ProposalProcedure
135
135
CurrentTreasuryAmount Option [Coin ]
136
136
TreasuryDonation Option [PositiveCoin ]
@@ -160,8 +160,7 @@ func (t TxInfoV3) ToPlutusData() data.PlutusData {
160
160
tmpRedeemers .ToPlutusData (),
161
161
t .Data .ToPlutusData (),
162
162
data .NewByteString (t .Id .Bytes ()),
163
- // TODO: votes
164
- data .NewMap ([][2 ]data.PlutusData {}),
163
+ t .Votes .ToPlutusData (),
165
164
// TODO: proposal procedures
166
165
toPlutusData ([]any {}),
167
166
t .CurrentTreasuryAmount .ToPlutusData (),
@@ -188,6 +187,7 @@ func NewTxInfoV3FromTransaction(
188
187
}
189
188
inputs := sortInputs (tx .Inputs ())
190
189
withdrawals := withdrawalsInfo (tx .Withdrawals ())
190
+ votes := votingInfo (tx .VotingProcedures ())
191
191
redeemers := redeemersInfo (
192
192
tx .Witnesses (),
193
193
scriptPurposeBuilder (
@@ -197,7 +197,7 @@ func NewTxInfoV3FromTransaction(
197
197
tx .Certificates (),
198
198
withdrawals ,
199
199
// TODO: proposal procedures
200
- // TODO: votes
200
+ votes ,
201
201
),
202
202
)
203
203
tmpData := dataInfo (tx .Witnesses ())
@@ -217,7 +217,7 @@ func NewTxInfoV3FromTransaction(
217
217
Redeemers : redeemers ,
218
218
Data : tmpData ,
219
219
Id : tx .Hash (),
220
- // TODO: Votes
220
+ Votes : votes ,
221
221
// TODO: ProposalProcedures
222
222
}
223
223
if amt := tx .CurrentTreasuryValue (); amt > 0 {
@@ -454,6 +454,80 @@ func signatoriesInfo(
454
454
return tmp
455
455
}
456
456
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
+
457
531
func certificatesToPlutusData (
458
532
certificates []lcommon.Certificate ,
459
533
) data.PlutusData {
0 commit comments