Skip to content

Commit

Permalink
feat: support for Conway redeemers and PlutusV3 TX witnesses
Browse files Browse the repository at this point in the history
Fixes #671
  • Loading branch information
agaffney committed Jul 17, 2024
1 parent d0eef33 commit 45ddd42
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
16 changes: 15 additions & 1 deletion ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,25 @@ func (o AlonzoTransactionOutput) Utxorpc() *utxorpc.TxOutput {
}
}

type AlonzoRedeemer struct {
cbor.StructAsArray
Tag uint8
Index uint32
Data cbor.RawMessage
ExUnits RedeemerExUnits
}

type RedeemerExUnits struct {
cbor.StructAsArray
Memory uint64
Steps uint64
}

type AlonzoTransactionWitnessSet struct {
ShelleyTransactionWitnessSet
PlutusScripts []cbor.RawMessage `cbor:"3,keyasint,omitempty"`
PlutusData []cbor.RawMessage `cbor:"4,keyasint,omitempty"`
Redeemers []cbor.RawMessage `cbor:"5,keyasint,omitempty"`
Redeemers []AlonzoRedeemer `cbor:"5,keyasint,omitempty"`
}

func (t *AlonzoTransactionWitnessSet) UnmarshalCBOR(cborData []byte) error {
Expand Down
55 changes: 53 additions & 2 deletions ledger/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type ConwayBlock struct {
cbor.DecodeStoreCbor
Header *ConwayBlockHeader
TransactionBodies []ConwayTransactionBody
TransactionWitnessSets []BabbageTransactionWitnessSet
TransactionWitnessSets []ConwayTransactionWitnessSet
TransactionMetadataSet map[uint]*cbor.LazyValue
InvalidTransactions []uint
}
Expand Down Expand Up @@ -119,6 +119,57 @@ func (h *ConwayBlockHeader) Era() Era {
return eras[EraIdConway]
}

type ConwayRedeemerKey struct {
cbor.StructAsArray
Tag uint8
Index uint32
}

type ConwayRedeemerValue struct {
cbor.StructAsArray
Data cbor.RawMessage
ExUnits RedeemerExUnits
}

type ConwayRedeemers struct {
Redeemers map[ConwayRedeemerKey]ConwayRedeemerValue
legacy bool
}

func (r *ConwayRedeemers) UnmarshalCBOR(cborData []byte) error {
// Try to parse as legacy redeemer first
var tmpRedeemers []AlonzoRedeemer
if _, err := cbor.Decode(cborData, &tmpRedeemers); err == nil {
// Copy data from legacy redeemer type
for _, redeemer := range tmpRedeemers {
tmpKey := ConwayRedeemerKey{
Tag: redeemer.Tag,
Index: redeemer.Index,
}
tmpVal := ConwayRedeemerValue{
Data: redeemer.Data,
ExUnits: redeemer.ExUnits,
}
r.Redeemers[tmpKey] = tmpVal
}
r.legacy = true
} else {
_, err := cbor.Decode(cborData, &(r.Redeemers))
return err
}
return nil
}

type ConwayTransactionWitnessSet struct {
BabbageTransactionWitnessSet
Redeemers ConwayRedeemers `cbor:"5,keyasint,omitempty"`
PlutusV3Scripts []cbor.RawMessage `cbor:"7,keyasint,omitempty"`
}

func (t *ConwayTransactionWitnessSet) UnmarshalCBOR(cborData []byte) error {
return t.UnmarshalCbor(cborData, t)
}

type ConwayTransactionBody struct {
BabbageTransactionBody
TxVotingProcedures VotingProcedures `cbor:"19,keyasint,omitempty"`
Expand Down Expand Up @@ -336,7 +387,7 @@ type ConwayTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Body ConwayTransactionBody
WitnessSet BabbageTransactionWitnessSet
WitnessSet ConwayTransactionWitnessSet
IsTxValid bool
TxMetadata *cbor.LazyValue
}
Expand Down

0 comments on commit 45ddd42

Please sign in to comment.