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: block function to get header #800

Merged
merged 1 commit into from
Nov 22, 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
8 changes: 4 additions & 4 deletions cmd/gouroboros/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,15 @@ func chainSyncRollForwardHandler(
byronEbbBlock := block.(*ledger.ByronEpochBoundaryBlock)
fmt.Printf(
"era = Byron (EBB), epoch = %d, slot = %d, id = %s\n",
byronEbbBlock.Header.ConsensusData.Epoch,
byronEbbBlock.BlockHeader.ConsensusData.Epoch,
byronEbbBlock.SlotNumber(),
byronEbbBlock.Hash(),
)
case ledger.BlockTypeByronMain:
byronBlock := block.(*ledger.ByronMainBlock)
fmt.Printf(
"era = Byron, epoch = %d, slot = %d, id = %s\n",
byronBlock.Header.ConsensusData.SlotId.Epoch,
byronBlock.BlockHeader.ConsensusData.SlotId.Epoch,
byronBlock.SlotNumber(),
byronBlock.Hash(),
)
Expand All @@ -313,9 +313,9 @@ func blockFetchBlockHandler(
) error {
switch block := blockData.(type) {
case *ledger.ByronEpochBoundaryBlock:
fmt.Printf("era = Byron (EBB), epoch = %d, slot = %d, id = %s\n", block.Header.ConsensusData.Epoch, block.SlotNumber(), block.Hash())
fmt.Printf("era = Byron (EBB), epoch = %d, slot = %d, id = %s\n", block.BlockHeader.ConsensusData.Epoch, block.SlotNumber(), block.Hash())
case *ledger.ByronMainBlock:
fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", block.Header.ConsensusData.SlotId.Epoch, block.SlotNumber(), block.Hash())
fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", block.BlockHeader.ConsensusData.SlotId.Epoch, block.SlotNumber(), block.Hash())
case ledger.Block:
fmt.Printf("era = %s, slot = %d, block_no = %d, id = %s\n", block.Era().Name, block.SlotNumber(), block.BlockNumber(), block.Hash())
}
Expand Down
18 changes: 11 additions & 7 deletions ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {
type AllegraBlock struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Header *AllegraBlockHeader
BlockHeader *AllegraBlockHeader
TransactionBodies []AllegraTransactionBody
TransactionWitnessSets []shelley.ShelleyTransactionWitnessSet
TransactionMetadataSet map[uint]*cbor.LazyValue
Expand All @@ -65,27 +65,31 @@ func (AllegraBlock) Type() int {
}

func (b *AllegraBlock) Hash() string {
return b.Header.Hash()
return b.BlockHeader.Hash()
}

func (b *AllegraBlock) Header() common.BlockHeader {
return b.BlockHeader
}

func (b *AllegraBlock) PrevHash() string {
return b.Header.PrevHash()
return b.BlockHeader.PrevHash()
}

func (b *AllegraBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
return b.BlockHeader.BlockNumber()
}

func (b *AllegraBlock) SlotNumber() uint64 {
return b.Header.SlotNumber()
return b.BlockHeader.SlotNumber()
}

func (b *AllegraBlock) IssuerVkey() common.IssuerVkey {
return b.Header.IssuerVkey()
return b.BlockHeader.IssuerVkey()
}

func (b *AllegraBlock) BlockBodySize() uint64 {
return b.Header.BlockBodySize()
return b.BlockHeader.BlockBodySize()
}

func (b *AllegraBlock) Era() common.Era {
Expand Down
18 changes: 11 additions & 7 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func init() {
type AlonzoBlock struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Header *AlonzoBlockHeader
BlockHeader *AlonzoBlockHeader
TransactionBodies []AlonzoTransactionBody
TransactionWitnessSets []AlonzoTransactionWitnessSet
TransactionMetadataSet map[uint]*cbor.LazyValue
Expand All @@ -68,27 +68,31 @@ func (AlonzoBlock) Type() int {
}

func (b *AlonzoBlock) Hash() string {
return b.Header.Hash()
return b.BlockHeader.Hash()
}

func (b *AlonzoBlock) Header() common.BlockHeader {
return b.BlockHeader
}

func (b *AlonzoBlock) PrevHash() string {
return b.Header.PrevHash()
return b.BlockHeader.PrevHash()
}

func (b *AlonzoBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
return b.BlockHeader.BlockNumber()
}

func (b *AlonzoBlock) SlotNumber() uint64 {
return b.Header.SlotNumber()
return b.BlockHeader.SlotNumber()
}

func (b *AlonzoBlock) IssuerVkey() common.IssuerVkey {
return b.Header.IssuerVkey()
return b.BlockHeader.IssuerVkey()
}

func (b *AlonzoBlock) BlockBodySize() uint64 {
return b.Header.BlockBodySize()
return b.BlockHeader.BlockBodySize()
}

func (b *AlonzoBlock) Era() common.Era {
Expand Down
18 changes: 11 additions & 7 deletions ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func init() {
type BabbageBlock struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Header *BabbageBlockHeader
BlockHeader *BabbageBlockHeader
TransactionBodies []BabbageTransactionBody
TransactionWitnessSets []BabbageTransactionWitnessSet
TransactionMetadataSet map[uint]*cbor.LazyValue
Expand All @@ -69,27 +69,31 @@ func (BabbageBlock) Type() int {
}

func (b *BabbageBlock) Hash() string {
return b.Header.Hash()
return b.BlockHeader.Hash()
}

func (b *BabbageBlock) Header() common.BlockHeader {
return b.BlockHeader
}

func (b *BabbageBlock) PrevHash() string {
return b.Header.PrevHash()
return b.BlockHeader.PrevHash()
}

func (b *BabbageBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
return b.BlockHeader.BlockNumber()
}

func (b *BabbageBlock) SlotNumber() uint64 {
return b.Header.SlotNumber()
return b.BlockHeader.SlotNumber()
}

func (b *BabbageBlock) IssuerVkey() common.IssuerVkey {
return b.Header.IssuerVkey()
return b.BlockHeader.IssuerVkey()
}

func (b *BabbageBlock) BlockBodySize() uint64 {
return b.Header.BlockBodySize()
return b.BlockHeader.BlockBodySize()
}

func (b *BabbageBlock) Era() common.Era {
Expand Down
44 changes: 26 additions & 18 deletions ledger/byron/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ func (h *ByronEpochBoundaryBlockHeader) Era() common.Era {
type ByronMainBlock struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Header *ByronMainBlockHeader
Body ByronMainBlockBody
Extra []interface{}
BlockHeader *ByronMainBlockHeader
Body ByronMainBlockBody
Extra []interface{}
}

func (b *ByronMainBlock) UnmarshalCBOR(cborData []byte) error {
Expand All @@ -574,31 +574,35 @@ func (ByronMainBlock) Type() int {
}

func (b *ByronMainBlock) Hash() string {
return b.Header.Hash()
return b.BlockHeader.Hash()
}

func (b *ByronMainBlock) Header() common.BlockHeader {
return b.BlockHeader
}

func (b *ByronMainBlock) PrevHash() string {
return b.Header.PrevHash()
return b.BlockHeader.PrevHash()
}

func (b *ByronMainBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
return b.BlockHeader.BlockNumber()
}

func (b *ByronMainBlock) SlotNumber() uint64 {
return b.Header.SlotNumber()
return b.BlockHeader.SlotNumber()
}

func (b *ByronMainBlock) IssuerVkey() common.IssuerVkey {
return b.Header.IssuerVkey()
return b.BlockHeader.IssuerVkey()
}

func (b *ByronMainBlock) BlockBodySize() uint64 {
return uint64(len(b.Body.Cbor()))
}

func (b *ByronMainBlock) Era() common.Era {
return b.Header.Era()
return b.BlockHeader.Era()
}

func (b *ByronMainBlock) Transactions() []common.Transaction {
Expand All @@ -617,9 +621,9 @@ func (b *ByronMainBlock) Utxorpc() *utxorpc.Block {
type ByronEpochBoundaryBlock struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Header *ByronEpochBoundaryBlockHeader
Body []common.Blake2b224
Extra []interface{}
BlockHeader *ByronEpochBoundaryBlockHeader
Body []common.Blake2b224
Extra []interface{}
}

func (b *ByronEpochBoundaryBlock) UnmarshalCBOR(cborData []byte) error {
Expand All @@ -632,23 +636,27 @@ func (ByronEpochBoundaryBlock) Type() int {
}

func (b *ByronEpochBoundaryBlock) Hash() string {
return b.Header.Hash()
return b.BlockHeader.Hash()
}

func (b *ByronEpochBoundaryBlock) Header() common.BlockHeader {
return b.BlockHeader
}

func (b *ByronEpochBoundaryBlock) PrevHash() string {
return b.Header.PrevHash()
return b.BlockHeader.PrevHash()
}

func (b *ByronEpochBoundaryBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
return b.BlockHeader.BlockNumber()
}

func (b *ByronEpochBoundaryBlock) SlotNumber() uint64 {
return b.Header.SlotNumber()
return b.BlockHeader.SlotNumber()
}

func (b *ByronEpochBoundaryBlock) IssuerVkey() common.IssuerVkey {
return b.Header.IssuerVkey()
return b.BlockHeader.IssuerVkey()
}

func (b *ByronEpochBoundaryBlock) BlockBodySize() uint64 {
Expand All @@ -657,7 +665,7 @@ func (b *ByronEpochBoundaryBlock) BlockBodySize() uint64 {
}

func (b *ByronEpochBoundaryBlock) Era() common.Era {
return b.Header.Era()
return b.BlockHeader.Era()
}

func (b *ByronEpochBoundaryBlock) Transactions() []common.Transaction {
Expand Down
1 change: 1 addition & 0 deletions ledger/common/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"

type Block interface {
BlockHeader
Header() BlockHeader
Type() int
Transactions() []Transaction
Utxorpc() *utxorpc.Block
Expand Down
18 changes: 11 additions & 7 deletions ledger/conway/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func init() {
type ConwayBlock struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Header *ConwayBlockHeader
BlockHeader *ConwayBlockHeader
TransactionBodies []ConwayTransactionBody
TransactionWitnessSets []ConwayTransactionWitnessSet
TransactionMetadataSet map[uint]*cbor.LazyValue
Expand All @@ -68,27 +68,31 @@ func (ConwayBlock) Type() int {
}

func (b *ConwayBlock) Hash() string {
return b.Header.Hash()
return b.BlockHeader.Hash()
}

func (b *ConwayBlock) Header() common.BlockHeader {
return b.BlockHeader
}

func (b *ConwayBlock) PrevHash() string {
return b.Header.PrevHash()
return b.BlockHeader.PrevHash()
}

func (b *ConwayBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
return b.BlockHeader.BlockNumber()
}

func (b *ConwayBlock) SlotNumber() uint64 {
return b.Header.SlotNumber()
return b.BlockHeader.SlotNumber()
}

func (b *ConwayBlock) IssuerVkey() common.IssuerVkey {
return b.Header.IssuerVkey()
return b.BlockHeader.IssuerVkey()
}

func (b *ConwayBlock) BlockBodySize() uint64 {
return b.Header.BlockBodySize()
return b.BlockHeader.BlockBodySize()
}

func (b *ConwayBlock) Era() common.Era {
Expand Down
18 changes: 11 additions & 7 deletions ledger/mary/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func init() {
type MaryBlock struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Header *MaryBlockHeader
BlockHeader *MaryBlockHeader
TransactionBodies []MaryTransactionBody
TransactionWitnessSets []MaryTransactionWitnessSet
TransactionMetadataSet map[uint]*cbor.LazyValue
Expand All @@ -67,27 +67,31 @@ func (MaryBlock) Type() int {
}

func (b *MaryBlock) Hash() string {
return b.Header.Hash()
return b.BlockHeader.Hash()
}

func (b *MaryBlock) Header() common.BlockHeader {
return b.BlockHeader
}

func (b *MaryBlock) PrevHash() string {
return b.Header.PrevHash()
return b.BlockHeader.PrevHash()
}

func (b *MaryBlock) BlockNumber() uint64 {
return b.Header.BlockNumber()
return b.BlockHeader.BlockNumber()
}

func (b *MaryBlock) SlotNumber() uint64 {
return b.Header.SlotNumber()
return b.BlockHeader.SlotNumber()
}

func (b *MaryBlock) IssuerVkey() common.IssuerVkey {
return b.Header.IssuerVkey()
return b.BlockHeader.IssuerVkey()
}

func (b *MaryBlock) BlockBodySize() uint64 {
return b.Header.BlockBodySize()
return b.BlockHeader.BlockBodySize()
}

func (b *MaryBlock) Era() common.Era {
Expand Down
Loading