diff --git a/ledger/alonzo/alonzo.go b/ledger/alonzo/alonzo.go index bc6b07c6..0cc54feb 100644 --- a/ledger/alonzo/alonzo.go +++ b/ledger/alonzo/alonzo.go @@ -269,8 +269,6 @@ type AlonzoTransactionOutput struct { } func (o *AlonzoTransactionOutput) UnmarshalCBOR(cborData []byte) error { - // Save original CBOR - o.SetCbor(cborData) // Try to parse as legacy mary.Mary output first var tmpOutput mary.MaryTransactionOutput if _, err := cbor.Decode(cborData, &tmpOutput); err == nil { @@ -279,8 +277,15 @@ func (o *AlonzoTransactionOutput) UnmarshalCBOR(cborData []byte) error { o.OutputAmount = tmpOutput.OutputAmount o.legacyOutput = true } else { - return cbor.DecodeGeneric(cborData, o) + type tAlonzoTransactionOutput AlonzoTransactionOutput + var tmp tAlonzoTransactionOutput + if _, err := cbor.Decode(cborData, &tmp); err != nil { + return err + } + *o = AlonzoTransactionOutput(tmp) } + // Save original CBOR + o.SetCbor(cborData) return nil } diff --git a/ledger/babbage/babbage.go b/ledger/babbage/babbage.go index ee199a5d..f42ac70f 100644 --- a/ledger/babbage/babbage.go +++ b/ledger/babbage/babbage.go @@ -435,7 +435,12 @@ func (o *BabbageTransactionOutput) UnmarshalCBOR(cborData []byte) error { o.OutputAmount = tmpOutput.OutputAmount o.legacyOutput = true } else { - return cbor.DecodeGeneric(cborData, o) + type tBabbageTransactionOutput BabbageTransactionOutput + var tmp tBabbageTransactionOutput + if _, err := cbor.Decode(cborData, &tmp); err != nil { + return err + } + *o = BabbageTransactionOutput(tmp) } return nil } diff --git a/ledger/byron/byron.go b/ledger/byron/byron.go index 4f410164..bbe8050f 100644 --- a/ledger/byron/byron.go +++ b/ledger/byron/byron.go @@ -337,6 +337,7 @@ func (i *ByronTransactionInput) UnmarshalCBOR(data []byte) error { } switch id { case 0: + // Decode outer data var tmpData struct { cbor.StructAsArray Id int @@ -345,9 +346,13 @@ func (i *ByronTransactionInput) UnmarshalCBOR(data []byte) error { if _, err := cbor.Decode(data, &tmpData); err != nil { return err } - if err := cbor.DecodeGeneric(tmpData.Cbor, i); err != nil { + // Decode inner data + type tByronTransactionInput ByronTransactionInput + var tmp tByronTransactionInput + if _, err := cbor.Decode(tmpData.Cbor, &tmp); err != nil { return err } + *i = ByronTransactionInput(tmp) default: // [u8 .ne 0, encoded-cbor] return errors.New("can't parse yet") diff --git a/ledger/common/nonce.go b/ledger/common/nonce.go index 453375b6..d8bf42d9 100644 --- a/ledger/common/nonce.go +++ b/ledger/common/nonce.go @@ -45,9 +45,12 @@ func (n *Nonce) UnmarshalCBOR(data []byte) error { case NonceTypeNeutral: // Value uses default value case NonceTypeNonce: - if err := cbor.DecodeGeneric(data, n); err != nil { + type tNonce Nonce + var tmp tNonce + if _, err := cbor.Decode(data, &tmp); err != nil { return err } + *n = Nonce(tmp) default: return fmt.Errorf("unsupported nonce type %d", nonceType) } diff --git a/ledger/mary/mary.go b/ledger/mary/mary.go index 8062c5c1..612c2b8c 100644 --- a/ledger/mary/mary.go +++ b/ledger/mary/mary.go @@ -471,12 +471,16 @@ type MaryTransactionOutputValue struct { } func (v *MaryTransactionOutputValue) UnmarshalCBOR(data []byte) error { + // Try to decode as simple amount first if _, err := cbor.Decode(data, &(v.Amount)); err == nil { return nil } - if err := cbor.DecodeGeneric(data, v); err != nil { + type tMaryTransactionOutputValue MaryTransactionOutputValue + var tmp tMaryTransactionOutputValue + if _, err := cbor.Decode(data, &tmp); err != nil { return err } + *v = MaryTransactionOutputValue(tmp) return nil } diff --git a/protocol/chainsync/messages.go b/protocol/chainsync/messages.go index 7f080431..64a7c924 100644 --- a/protocol/chainsync/messages.go +++ b/protocol/chainsync/messages.go @@ -144,9 +144,14 @@ func NewMsgRollForwardNtC( } func (m *MsgRollForwardNtC) UnmarshalCBOR(data []byte) error { - if err := cbor.DecodeGeneric(data, m); err != nil { + // Decode message + type tMsgRollForwardNtC MsgRollForwardNtC + var tmp tMsgRollForwardNtC + if _, err := cbor.Decode(data, &tmp); err != nil { return err } + *m = MsgRollForwardNtC(tmp) + // Decode wrapped block var wb WrappedBlock if _, err := cbor.Decode(m.WrappedBlock.Content.([]byte), &wb); err != nil { return err diff --git a/protocol/localstatequery/queries.go b/protocol/localstatequery/queries.go index 59711737..34a4a92c 100644 --- a/protocol/localstatequery/queries.go +++ b/protocol/localstatequery/queries.go @@ -527,7 +527,12 @@ func (u *UtxoId) UnmarshalCBOR(data []byte) error { u.Hash = tmpData.Hash u.Idx = tmpData.Idx case 3: - return cbor.DecodeGeneric(data, u) + type tUtxoId UtxoId + var tmp tUtxoId + if _, err := cbor.Decode(data, &tmp); err != nil { + return err + } + *u = UtxoId(tmp) default: return fmt.Errorf("invalid list length: %d", listLen) }