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: 5 additions & 1 deletion ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ func (AllegraTransaction) Type() int {
}

func (t AllegraTransaction) Hash() common.Blake2b256 {
return t.Body.Hash()
return t.Id()
}

func (t AllegraTransaction) Id() common.Blake2b256 {
return t.Body.Id()
}

func (t AllegraTransaction) Inputs() []common.TransactionInput {
Expand Down
6 changes: 5 additions & 1 deletion ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,11 @@ func (AlonzoTransaction) Type() int {
}

func (t AlonzoTransaction) Hash() common.Blake2b256 {
return t.Body.Hash()
return t.Id()
}

func (t AlonzoTransaction) Id() common.Blake2b256 {
return t.Body.Id()
}

func (t AlonzoTransaction) Inputs() []common.TransactionInput {
Expand Down
15 changes: 14 additions & 1 deletion ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ type BabbageTransactionPparamUpdate struct {

type BabbageTransactionBody struct {
common.TransactionBodyBase
hash *common.Blake2b256
TxInputs shelley.ShelleyTransactionInputSet `cbor:"0,keyasint,omitempty"`
TxOutputs []BabbageTransactionOutput `cbor:"1,keyasint,omitempty"`
TxFee uint64 `cbor:"2,keyasint,omitempty"`
Expand Down Expand Up @@ -266,6 +267,14 @@ func (b *BabbageTransactionBody) UnmarshalCBOR(cborData []byte) error {
return nil
}

func (b *BabbageTransactionBody) Id() common.Blake2b256 {
if b.hash == nil {
tmpHash := common.Blake2b256Hash(b.Cbor())
b.hash = &tmpHash
}
return *b.hash
}

func (b *BabbageTransactionBody) Inputs() []common.TransactionInput {
ret := []common.TransactionInput{}
for _, input := range b.TxInputs.Items() {
Expand Down Expand Up @@ -742,7 +751,11 @@ func (BabbageTransaction) Type() int {
}

func (t BabbageTransaction) Hash() common.Blake2b256 {
return t.Body.Hash()
return t.Id()
}

func (t BabbageTransaction) Id() common.Blake2b256 {
return t.Body.Id()
}

func (t BabbageTransaction) Inputs() []common.TransactionInput {
Expand Down
6 changes: 6 additions & 0 deletions ledger/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func NewBlockFromCbor(blockType uint, data []byte) (Block, error) {
return NewBabbageBlockFromCbor(data)
case BlockTypeConway:
return NewConwayBlockFromCbor(data)
case BlockTypeLeiosEndorser:
return NewLeiosEndorserBlockFromCbor(data)
case BlockTypeLeiosRanking:
return NewLeiosRankingBlockFromCbor(data)
}
return nil, fmt.Errorf("unknown node-to-client block type: %d", blockType)
}
Expand All @@ -66,6 +70,8 @@ func NewBlockHeaderFromCbor(blockType uint, data []byte) (BlockHeader, error) {
return NewBabbageBlockHeaderFromCbor(data)
case BlockTypeConway:
return NewConwayBlockHeaderFromCbor(data)
case BlockTypeLeiosRanking:
return NewLeiosBlockHeaderFromCbor(data)
default:
return nil, fmt.Errorf("unknown node-to-node block type: %d", blockType)
}
Expand Down
6 changes: 5 additions & 1 deletion ledger/byron/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func (ByronTransaction) Type() int {
}

func (t *ByronTransaction) Hash() common.Blake2b256 {
return t.Id()
}

func (t *ByronTransaction) Id() common.Blake2b256 {
if t.hash == nil {
tmpHash := common.Blake2b256Hash(t.Cbor())
t.hash = &tmpHash
Expand Down Expand Up @@ -289,7 +293,7 @@ func (t *ByronTransaction) Produced() []common.Utxo {
ret = append(
ret,
common.Utxo{
Id: NewByronTransactionInput(t.Hash().String(), idx),
Id: NewByronTransactionInput(t.Id().String(), idx),
Output: output,
},
)
Expand Down
38 changes: 38 additions & 0 deletions ledger/common/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
CertificateTypeRegistrationDrep = 16
CertificateTypeDeregistrationDrep = 17
CertificateTypeUpdateDrep = 18
CertificateTypeLeiosEb = 19
)

type CertificateWrapper struct {
Expand Down Expand Up @@ -99,6 +100,8 @@ func (c *CertificateWrapper) UnmarshalCBOR(data []byte) error {
tmpCert = &DeregistrationDrepCertificate{}
case CertificateTypeUpdateDrep:
tmpCert = &UpdateDrepCertificate{}
case CertificateTypeLeiosEb:
tmpCert = &LeiosEbCertificate{}
default:
return fmt.Errorf("unknown certificate type: %d", certType)
}
Expand Down Expand Up @@ -1361,3 +1364,38 @@ func (c *UpdateDrepCertificate) Utxorpc() (*utxorpc.Certificate, error) {
func (c *UpdateDrepCertificate) Type() uint {
return c.CertType
}

type LeiosEbCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
CertType uint
ElectionId Blake2b256
EndorserBlockHash Blake2b256
PersistentVoters []any
NonpersistentVoters map[Blake2b256]any
AggregateEligSig *any
AggregateVoteSig any
}

func (c LeiosEbCertificate) isCertificate() {}

func (c *LeiosEbCertificate) UnmarshalCBOR(
cborData []byte,
) error {
type tLeiosEbCertificate LeiosEbCertificate
var tmp tLeiosEbCertificate
if _, err := cbor.Decode(cborData, &tmp); err != nil {
return err
}
*c = LeiosEbCertificate(tmp)
c.SetCbor(cborData)
return nil
}

func (c *LeiosEbCertificate) Utxorpc() (*utxorpc.Certificate, error) {
return &utxorpc.Certificate{}, nil
}

func (c *LeiosEbCertificate) Type() uint {
return c.CertType
}
15 changes: 12 additions & 3 deletions ledger/common/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Transaction interface {
TransactionBody
Type() int
Cbor() []byte
Hash() Blake2b256
Metadata() *cbor.LazyValue
IsValid() bool
Consumed() []TransactionInput
Expand All @@ -36,7 +37,7 @@ type Transaction interface {
type TransactionBody interface {
Cbor() []byte
Fee() uint64
Hash() Blake2b256
Id() Blake2b256
Inputs() []TransactionInput
Outputs() []TransactionOutput
TTL() uint64
Expand Down Expand Up @@ -97,6 +98,14 @@ type TransactionWitnessRedeemers interface {
Iter() iter.Seq2[RedeemerKey, RedeemerValue]
}

// TxReference provides a reference to a transaction which includes a hash of the full transaction
// body bytes and the total transaction size in bytes
type TxReference struct {
cbor.StructAsArray
TxHash Blake2b256
TxSize uint16
}

type Utxo struct {
cbor.StructAsArray
Id TransactionInput
Expand All @@ -111,7 +120,7 @@ type TransactionBodyBase struct {
hash *Blake2b256
}

func (b *TransactionBodyBase) Hash() Blake2b256 {
func (b *TransactionBodyBase) Id() Blake2b256 {
if b.hash == nil {
tmpHash := Blake2b256Hash(b.Cbor())
b.hash = &tmpHash
Expand Down Expand Up @@ -230,7 +239,7 @@ func TransactionBodyToUtxorpc(tx TransactionBody) (*utxorpc.Tx, error) {
// Validity: tx.Validity(),
// Successful: tx.Successful(),
// Auxiliary: tx.AuxData(),
Hash: tx.Hash().Bytes(),
Hash: tx.Id().Bytes(),
// Proposals: tx.ProposalProcedures(),
}
for _, ri := range tx.ReferenceInputs() {
Expand Down
6 changes: 5 additions & 1 deletion ledger/conway/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,11 @@ func (ConwayTransaction) Type() int {
}

func (t ConwayTransaction) Hash() common.Blake2b256 {
return t.Body.Hash()
return t.Id()
}

func (t ConwayTransaction) Id() common.Blake2b256 {
return t.Body.Id()
}

func (t ConwayTransaction) Inputs() []common.TransactionInput {
Expand Down
50 changes: 50 additions & 0 deletions ledger/leios.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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 ledger

import "github.com/blinklabs-io/gouroboros/ledger/leios"

// The below are compatibility types, constants, and functions for the Leios era
// to keep existing code working after a refactor of the ledger package

// Leios types
type (
LeiosBlockHeader = leios.LeiosBlockHeader
LeiosEndorderBlock = leios.LeiosEndorserBlock
LeiosRankingBlock = leios.LeiosRankingBlock
LeiosTransaction = leios.LeiosTransaction
LeiosTransactionBody = leios.LeiosTransactionBody
LeiosTransactionWitnessSet = leios.LeiosTransactionWitnessSet
LeiosProtocolParameters = leios.LeiosProtocolParameters
LeiosProtocolParameterUpdate = leios.LeiosProtocolParameterUpdate
)

// Leios constants
const (
EraIdLeios = leios.EraIdLeios
BlockTypeLeiosRanking = leios.BlockTypeLeiosRanking
BlockTypeLeiosEndorser = leios.BlockTypeLeiosEndorser
BlockHeaderTypeLeios = leios.BlockHeaderTypeLeios
TxTypeLeios = leios.TxTypeLeios
)

// Leios functions
var (
NewLeiosEndorserBlockFromCbor = leios.NewLeiosEndorserBlockFromCbor
NewLeiosRankingBlockFromCbor = leios.NewLeiosRankingBlockFromCbor
NewLeiosBlockHeaderFromCbor = leios.NewLeiosBlockHeaderFromCbor
NewLeiosTransactionFromCbor = leios.NewLeiosTransactionFromCbor
NewLeiosTransactionBodyFromCbor = leios.NewLeiosTransactionBodyFromCbor
)
Loading
Loading