diff --git a/ledger/conway/conway.go b/ledger/conway/conway.go index e65e076d..6b433c6f 100644 --- a/ledger/conway/conway.go +++ b/ledger/conway/conway.go @@ -199,6 +199,28 @@ func (t *ConwayTransactionWitnessSet) UnmarshalCBOR(cborData []byte) error { return t.UnmarshalCbor(cborData, t) } +type ConwayTransactionInput struct { + shelley.ShelleyTransactionInput +} + +func NewConwayTransactionInput(hash string, idx int) ConwayTransactionInput { + tmpHash, err := hex.DecodeString(hash) + if err != nil { + panic(fmt.Sprintf("failed to decode transaction hash: %s", err)) + } + return ConwayTransactionInput{ + ShelleyTransactionInput: shelley.ShelleyTransactionInput{ + TxId: common.Blake2b256(tmpHash), + OutputIndex: uint32(idx), + }, + } +} + +func (i *ConwayTransactionInput) UnmarshalCBOR(data []byte) error { + // We override the unmarshal function from ShelleyTransactionInput + return cbor.DecodeGeneric(data, &i.ShelleyTransactionInput) +} + type ConwayTransactionBody struct { babbage.BabbageTransactionBody TxVotingProcedures common.VotingProcedures `cbor:"19,keyasint,omitempty"` diff --git a/ledger/shelley/shelley.go b/ledger/shelley/shelley.go index 798ca198..e9186a2f 100644 --- a/ledger/shelley/shelley.go +++ b/ledger/shelley/shelley.go @@ -386,8 +386,6 @@ func (i ShelleyTransactionInput) Utxorpc() *utxorpc.TxInput { return &utxorpc.TxInput{ TxHash: i.TxId.Bytes(), OutputIndex: i.OutputIndex, - // AsOutput: i.AsOutput, - // Redeemer: i.Redeemer, } } @@ -395,6 +393,16 @@ func (i ShelleyTransactionInput) String() string { return fmt.Sprintf("%s#%d", i.TxId, i.OutputIndex) } +func (i *ShelleyTransactionInput) UnmarshalCBOR(data []byte) error { + // Make sure this isn't a tag-wrapped set + // This is needed to prevent Conway+ TXs from being decoded as an earlier type + var tmpTag cbor.RawTag + if _, err := cbor.Decode(data, &tmpTag); err == nil { + return fmt.Errorf("did not expect CBOR tag") + } + return cbor.DecodeGeneric(data, i) +} + func (i ShelleyTransactionInput) MarshalJSON() ([]byte, error) { return []byte("\"" + i.String() + "\""), nil }