File tree Expand file tree Collapse file tree 7 files changed +41
-9
lines changed Expand file tree Collapse file tree 7 files changed +41
-9
lines changed Original file line number Diff line number Diff line change @@ -269,8 +269,6 @@ type AlonzoTransactionOutput struct {
269
269
}
270
270
271
271
func (o * AlonzoTransactionOutput ) UnmarshalCBOR (cborData []byte ) error {
272
- // Save original CBOR
273
- o .SetCbor (cborData )
274
272
// Try to parse as legacy mary.Mary output first
275
273
var tmpOutput mary.MaryTransactionOutput
276
274
if _ , err := cbor .Decode (cborData , & tmpOutput ); err == nil {
@@ -279,8 +277,15 @@ func (o *AlonzoTransactionOutput) UnmarshalCBOR(cborData []byte) error {
279
277
o .OutputAmount = tmpOutput .OutputAmount
280
278
o .legacyOutput = true
281
279
} else {
282
- return cbor .DecodeGeneric (cborData , o )
280
+ type tAlonzoTransactionOutput AlonzoTransactionOutput
281
+ var tmp tAlonzoTransactionOutput
282
+ if _ , err := cbor .Decode (cborData , & tmp ); err != nil {
283
+ return err
284
+ }
285
+ * o = AlonzoTransactionOutput (tmp )
283
286
}
287
+ // Save original CBOR
288
+ o .SetCbor (cborData )
284
289
return nil
285
290
}
286
291
Original file line number Diff line number Diff line change @@ -435,7 +435,12 @@ func (o *BabbageTransactionOutput) UnmarshalCBOR(cborData []byte) error {
435
435
o .OutputAmount = tmpOutput .OutputAmount
436
436
o .legacyOutput = true
437
437
} else {
438
- return cbor .DecodeGeneric (cborData , o )
438
+ type tBabbageTransactionOutput BabbageTransactionOutput
439
+ var tmp tBabbageTransactionOutput
440
+ if _ , err := cbor .Decode (cborData , & tmp ); err != nil {
441
+ return err
442
+ }
443
+ * o = BabbageTransactionOutput (tmp )
439
444
}
440
445
return nil
441
446
}
Original file line number Diff line number Diff line change @@ -337,6 +337,7 @@ func (i *ByronTransactionInput) UnmarshalCBOR(data []byte) error {
337
337
}
338
338
switch id {
339
339
case 0 :
340
+ // Decode outer data
340
341
var tmpData struct {
341
342
cbor.StructAsArray
342
343
Id int
@@ -345,9 +346,13 @@ func (i *ByronTransactionInput) UnmarshalCBOR(data []byte) error {
345
346
if _ , err := cbor .Decode (data , & tmpData ); err != nil {
346
347
return err
347
348
}
348
- if err := cbor .DecodeGeneric (tmpData .Cbor , i ); err != nil {
349
+ // Decode inner data
350
+ type tByronTransactionInput ByronTransactionInput
351
+ var tmp tByronTransactionInput
352
+ if _ , err := cbor .Decode (tmpData .Cbor , & tmp ); err != nil {
349
353
return err
350
354
}
355
+ * i = ByronTransactionInput (tmp )
351
356
default :
352
357
// [u8 .ne 0, encoded-cbor]
353
358
return errors .New ("can't parse yet" )
Original file line number Diff line number Diff line change @@ -45,9 +45,12 @@ func (n *Nonce) UnmarshalCBOR(data []byte) error {
45
45
case NonceTypeNeutral :
46
46
// Value uses default value
47
47
case NonceTypeNonce :
48
- if err := cbor .DecodeGeneric (data , n ); err != nil {
48
+ type tNonce Nonce
49
+ var tmp tNonce
50
+ if _ , err := cbor .Decode (data , & tmp ); err != nil {
49
51
return err
50
52
}
53
+ * n = Nonce (tmp )
51
54
default :
52
55
return fmt .Errorf ("unsupported nonce type %d" , nonceType )
53
56
}
Original file line number Diff line number Diff line change @@ -471,12 +471,16 @@ type MaryTransactionOutputValue struct {
471
471
}
472
472
473
473
func (v * MaryTransactionOutputValue ) UnmarshalCBOR (data []byte ) error {
474
+ // Try to decode as simple amount first
474
475
if _ , err := cbor .Decode (data , & (v .Amount )); err == nil {
475
476
return nil
476
477
}
477
- if err := cbor .DecodeGeneric (data , v ); err != nil {
478
+ type tMaryTransactionOutputValue MaryTransactionOutputValue
479
+ var tmp tMaryTransactionOutputValue
480
+ if _ , err := cbor .Decode (data , & tmp ); err != nil {
478
481
return err
479
482
}
483
+ * v = MaryTransactionOutputValue (tmp )
480
484
return nil
481
485
}
482
486
Original file line number Diff line number Diff line change @@ -144,9 +144,14 @@ func NewMsgRollForwardNtC(
144
144
}
145
145
146
146
func (m * MsgRollForwardNtC ) UnmarshalCBOR (data []byte ) error {
147
- if err := cbor .DecodeGeneric (data , m ); err != nil {
147
+ // Decode message
148
+ type tMsgRollForwardNtC MsgRollForwardNtC
149
+ var tmp tMsgRollForwardNtC
150
+ if _ , err := cbor .Decode (data , & tmp ); err != nil {
148
151
return err
149
152
}
153
+ * m = MsgRollForwardNtC (tmp )
154
+ // Decode wrapped block
150
155
var wb WrappedBlock
151
156
if _ , err := cbor .Decode (m .WrappedBlock .Content .([]byte ), & wb ); err != nil {
152
157
return err
Original file line number Diff line number Diff line change @@ -525,7 +525,12 @@ func (u *UtxoId) UnmarshalCBOR(data []byte) error {
525
525
u .Hash = tmpData .Hash
526
526
u .Idx = tmpData .Idx
527
527
case 3 :
528
- return cbor .DecodeGeneric (data , u )
528
+ type tUtxoId UtxoId
529
+ var tmp tUtxoId
530
+ if _ , err := cbor .Decode (data , & tmp ); err != nil {
531
+ return err
532
+ }
533
+ * u = UtxoId (tmp )
529
534
default :
530
535
return fmt .Errorf ("invalid list length: %d" , listLen )
531
536
}
You can’t perform that action at this time.
0 commit comments