Skip to content
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
6 changes: 3 additions & 3 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ type AlonzoRedeemer struct {

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

func (t *AlonzoTransactionWitnessSet) UnmarshalCBOR(cborData []byte) error {
Expand Down
2 changes: 1 addition & 1 deletion ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func (o BabbageTransactionOutput) Utxorpc() *utxorpc.TxOutput {

type BabbageTransactionWitnessSet struct {
alonzo.AlonzoTransactionWitnessSet
PlutusV2Scripts []cbor.RawMessage `cbor:"6,keyasint,omitempty"`
PlutusV2Scripts [][]byte `cbor:"6,keyasint,omitempty"`
}

func (t *BabbageTransactionWitnessSet) UnmarshalCBOR(cborData []byte) error {
Expand Down
7 changes: 5 additions & 2 deletions ledger/babbage/babbage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ func TestBabbageBlockTransactions(t *testing.T) {
b.TransactionWitnessSets[i] = BabbageTransactionWitnessSet{
AlonzoTransactionWitnessSet: alonzo.AlonzoTransactionWitnessSet{
ShelleyTransactionWitnessSet: shelley.ShelleyTransactionWitnessSet{
VkeyWitnesses: []interface{}{
append(make([]byte, 95), 1<<i),
VkeyWitnesses: []common.VkeyWitness{
{
Vkey: append(make([]byte, 31), 1<<i)[:],
Signature: append(make([]byte, 63), 1<<i)[:],
},
},
},
},
Expand Down
94 changes: 94 additions & 0 deletions ledger/common/native_script.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package common

import (
"fmt"

"github.com/blinklabs-io/gouroboros/cbor"
)

type NativeScript struct {
item any
}

func (n *NativeScript) Item() any {
return n.item
}

func (n *NativeScript) UnmarshalCBOR(data []byte) error {
id, err := cbor.DecodeIdFromList(data)
if err != nil {
return err
}
var tmpData any
switch id {
case 0:
tmpData = &NativeScriptPubkey{}
case 1:
tmpData = &NativeScriptAll{}
case 2:
tmpData = &NativeScriptAny{}
case 3:
tmpData = &NativeScriptNofK{}
case 4:
tmpData = &NativeScriptInvalidBefore{}
case 5:
tmpData = &NativeScriptInvalidHereafter{}
default:
return fmt.Errorf("unknown native script type %d", id)
}
if _, err := cbor.Decode(data, tmpData); err != nil {
return err
}
return nil
}

type NativeScriptPubkey struct {
cbor.StructAsArray
Type uint
Hash []byte
}

type NativeScriptAll struct {
cbor.StructAsArray
Type uint
Scripts []NativeScript
}

type NativeScriptAny struct {
cbor.StructAsArray
Type uint
Scripts []NativeScript
}

type NativeScriptNofK struct {
cbor.StructAsArray
Type uint
N uint
Scripts []NativeScript
}

type NativeScriptInvalidBefore struct {
cbor.StructAsArray
Type uint
Slot uint64
}

type NativeScriptInvalidHereafter struct {
cbor.StructAsArray
Type uint
Slot uint64
}
33 changes: 33 additions & 0 deletions ledger/common/witness.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package common

import (
"github.com/blinklabs-io/gouroboros/cbor"
)

type VkeyWitness struct {
cbor.StructAsArray
Vkey []byte
Signature []byte
}

type BootstrapWitness struct {
cbor.StructAsArray
PublicKey []byte
Signature []byte
ChainCode []byte
Attributes []byte
}
4 changes: 2 additions & 2 deletions ledger/conway/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ func (r *ConwayRedeemers) UnmarshalCBOR(cborData []byte) error {

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

func (t *ConwayTransactionWitnessSet) UnmarshalCBOR(cborData []byte) error {
Expand Down
1 change: 0 additions & 1 deletion ledger/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type MaryTransaction = mary.MaryTransaction
type MaryTransactionBody = mary.MaryTransactionBody
type MaryTransactionOutput = mary.MaryTransactionOutput
type MaryTransactionOutputValue = mary.MaryTransactionOutputValue
type MaryTransactionWitnessSet = mary.MaryTransactionWitnessSet
type MaryProtocolParameters = mary.MaryProtocolParameters
type MaryProtocolParameterUpdate = mary.MaryProtocolParameterUpdate

Expand Down
10 changes: 2 additions & 8 deletions ledger/mary/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type MaryBlock struct {
cbor.DecodeStoreCbor
BlockHeader *MaryBlockHeader
TransactionBodies []MaryTransactionBody
TransactionWitnessSets []MaryTransactionWitnessSet
TransactionWitnessSets []shelley.ShelleyTransactionWitnessSet
TransactionMetadataSet map[uint]*cbor.LazyValue
}

Expand Down Expand Up @@ -180,20 +180,14 @@ type MaryTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Body MaryTransactionBody
WitnessSet MaryTransactionWitnessSet
WitnessSet shelley.ShelleyTransactionWitnessSet
TxMetadata *cbor.LazyValue
}

func (MaryTransaction) Type() int {
return TxTypeMary
}

type MaryTransactionWitnessSet struct {
shelley.ShelleyTransactionWitnessSet
Script []interface{} `cbor:"4,keyasint,omitempty"`
PlutusScripts []interface{} `cbor:"5,keyasint,omitempty"`
}

func (t MaryTransaction) Hash() string {
return t.Body.Hash()
}
Expand Down
6 changes: 3 additions & 3 deletions ledger/shelley/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ func (o ShelleyTransactionOutput) Utxorpc() *utxorpc.TxOutput {

type ShelleyTransactionWitnessSet struct {
cbor.DecodeStoreCbor
VkeyWitnesses []interface{} `cbor:"0,keyasint,omitempty"`
MultisigScripts []interface{} `cbor:"1,keyasint,omitempty"`
BootstrapWitnesses []interface{} `cbor:"2,keyasint,omitempty"`
VkeyWitnesses []common.VkeyWitness `cbor:"0,keyasint,omitempty"`
NativeScripts []common.NativeScript `cbor:"1,keyasint,omitempty"`
BootstrapWitnesses []common.BootstrapWitness `cbor:"2,keyasint,omitempty"`
}

func (t *ShelleyTransactionWitnessSet) UnmarshalCBOR(cborData []byte) error {
Expand Down
Loading