@@ -124,7 +124,7 @@ type TxInfoV3 struct {
124
124
Fee uint64
125
125
Mint lcommon.MultiAsset [lcommon.MultiAssetTypeMint ]
126
126
Certificates []lcommon.Certificate
127
- Withdrawals map [* lcommon.Address ] uint64
127
+ Withdrawals KeyValuePairs [* lcommon.Address , uint64 ]
128
128
ValidRange TimeRange
129
129
Signatories []lcommon.Blake2b224
130
130
Redeemers KeyValuePairs [ScriptInfo , Redeemer ]
@@ -170,22 +170,32 @@ func (t TxInfoV3) ToPlutusData() data.PlutusData {
170
170
}
171
171
172
172
func NewTxInfoV3FromTransaction (
173
+ slotState lcommon.SlotState ,
173
174
tx lcommon.Transaction ,
174
175
resolvedInputs []lcommon.Utxo ,
175
- ) TxInfoV3 {
176
+ ) (TxInfoV3 , error ) {
177
+ validityRange , err := validityRangeInfo (
178
+ slotState ,
179
+ tx .ValidityIntervalStart (),
180
+ tx .TTL (),
181
+ )
182
+ if err != nil {
183
+ return TxInfoV3 {}, err
184
+ }
176
185
assetMint := tx .AssetMint ()
177
186
if assetMint == nil {
178
187
assetMint = & lcommon.MultiAsset [lcommon.MultiAssetTypeMint ]{}
179
188
}
180
189
inputs := sortInputs (tx .Inputs ())
190
+ withdrawals := withdrawalsInfo (tx .Withdrawals ())
181
191
redeemers := redeemersInfo (
182
192
tx .Witnesses (),
183
193
scriptPurposeBuilder (
184
194
resolvedInputs ,
185
195
inputs ,
186
196
* assetMint ,
187
197
tx .Certificates (),
188
- tx . Withdrawals () ,
198
+ withdrawals ,
189
199
// TODO: proposal procedures
190
200
// TODO: votes
191
201
),
@@ -197,15 +207,12 @@ func NewTxInfoV3FromTransaction(
197
207
sortInputs (tx .ReferenceInputs ()),
198
208
resolvedInputs ,
199
209
),
200
- Outputs : collapseOutputs (tx .Produced ()),
201
- Fee : tx .Fee (),
202
- Mint : * assetMint ,
203
- ValidRange : TimeRange {
204
- tx .TTL (),
205
- tx .ValidityIntervalStart (),
206
- },
210
+ Outputs : collapseOutputs (tx .Produced ()),
211
+ Fee : tx .Fee (),
212
+ Mint : * assetMint ,
213
+ ValidRange : validityRange ,
207
214
Certificates : tx .Certificates (),
208
- Withdrawals : tx . Withdrawals () ,
215
+ Withdrawals : withdrawals ,
209
216
Signatories : signatoriesInfo (tx .RequiredSigners ()),
210
217
Redeemers : redeemers ,
211
218
Data : tmpData ,
@@ -219,7 +226,7 @@ func NewTxInfoV3FromTransaction(
219
226
if amt := tx .Donation (); amt > 0 {
220
227
ret .TreasuryDonation .Value = amt
221
228
}
222
- return ret
229
+ return ret , nil
223
230
}
224
231
225
232
type TimeRange struct {
@@ -336,6 +343,54 @@ func sortedRedeemerKeys(
336
343
return ret
337
344
}
338
345
346
+ func validityRangeInfo (
347
+ slotState lcommon.SlotState ,
348
+ startSlot uint64 ,
349
+ endSlot uint64 ,
350
+ ) (TimeRange , error ) {
351
+ var ret TimeRange
352
+ if startSlot > 0 {
353
+ startTime , err := slotState .SlotToTime (startSlot )
354
+ if err != nil {
355
+ return ret , err
356
+ }
357
+ ret .lowerBound = uint64 (startTime .UnixMilli ()) // nolint:gosec
358
+ }
359
+ if endSlot > 0 {
360
+ endTime , err := slotState .SlotToTime (endSlot )
361
+ if err != nil {
362
+ return ret , err
363
+ }
364
+ ret .upperBound = uint64 (endTime .UnixMilli ()) // nolint:gosec
365
+ }
366
+ return ret , nil
367
+ }
368
+
369
+ func withdrawalsInfo (
370
+ withdrawals map [* lcommon.Address ]uint64 ,
371
+ ) KeyValuePairs [* lcommon.Address , uint64 ] {
372
+ var ret KeyValuePairs [* lcommon.Address , uint64 ]
373
+ for addr , amt := range withdrawals {
374
+ ret = append (
375
+ ret ,
376
+ KeyValuePair [* lcommon.Address , uint64 ]{
377
+ Key : addr ,
378
+ Value : amt ,
379
+ },
380
+ )
381
+ }
382
+ // Sort by address bytes
383
+ slices .SortFunc (
384
+ ret ,
385
+ func (a , b KeyValuePair [* lcommon.Address , uint64 ]) int {
386
+ aBytes , _ := a .Key .Bytes ()
387
+ bBytes , _ := b .Key .Bytes ()
388
+ return bytes .Compare (aBytes , bBytes )
389
+ },
390
+ )
391
+ return ret
392
+ }
393
+
339
394
func dataInfo (
340
395
witnessSet lcommon.TransactionWitnessSet ,
341
396
) KeyValuePairs [lcommon.DatumHash , data.PlutusData ] {
0 commit comments