Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for Conway redeemers and PlutusV3 TX witnesses #672

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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