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: consistent naming for ledger constants #396

Merged
merged 1 commit into from
Oct 12, 2023
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
4 changes: 2 additions & 2 deletions cmd/gouroboros/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ func chainSyncRollForwardHandler(blockType uint, blockData interface{}, tip chai
}
// Display block info
switch blockType {
case ledger.BLOCK_TYPE_BYRON_EBB:
case ledger.BlockTypeByronEbb:
byronEbbBlock := block.(*ledger.ByronEpochBoundaryBlock)
fmt.Printf("era = Byron (EBB), epoch = %d, slot = %d, id = %s\n", byronEbbBlock.Header.ConsensusData.Epoch, byronEbbBlock.SlotNumber(), byronEbbBlock.Hash())
case ledger.BLOCK_TYPE_BYRON_MAIN:
case ledger.BlockTypeByronMain:
byronBlock := block.(*ledger.ByronMainBlock)
fmt.Printf("era = Byron, epoch = %d, slot = %d, id = %s\n", byronBlock.Header.ConsensusData.SlotId.Epoch, byronBlock.SlotNumber(), byronBlock.Hash())
default:
Expand Down
2 changes: 1 addition & 1 deletion cmd/gouroboros/localtxsubmission.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func testLocalTxSubmission(f *globalFlags) {
}
}

if err = o.LocalTxSubmission().Client.SubmitTx(ledger.TX_TYPE_ALONZO, txBytes); err != nil {
if err = o.LocalTxSubmission().Client.SubmitTx(ledger.TxTypeAlonzo, txBytes); err != nil {
fmt.Printf("Error submitting transaction: %s\n", err)
os.Exit(1)
}
Expand Down
12 changes: 6 additions & 6 deletions ledger/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
)

const (
ERA_ID_ALLEGRA = 2
EraIdAllegra = 2

BLOCK_TYPE_ALLEGRA = 3
BlockTypeAllegra = 3

BLOCK_HEADER_TYPE_ALLEGRA = 2
BlockHeaderTypeAllegra = 2

TX_TYPE_ALLEGRA = 2
TxTypeAllegra = 2
)

type AllegraBlock struct {
Expand Down Expand Up @@ -56,7 +56,7 @@ func (b *AllegraBlock) SlotNumber() uint64 {
}

func (b *AllegraBlock) Era() Era {
return eras[ERA_ID_ALLEGRA]
return eras[EraIdAllegra]
}

func (b *AllegraBlock) Transactions() []Transaction {
Expand All @@ -77,7 +77,7 @@ type AllegraBlockHeader struct {
}

func (h *AllegraBlockHeader) Era() Era {
return eras[ERA_ID_ALLEGRA]
return eras[EraIdAllegra]
}

type AllegraTransactionBody struct {
Expand Down
12 changes: 6 additions & 6 deletions ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
)

const (
ERA_ID_ALONZO = 4
EraIdAlonzo = 4

BLOCK_TYPE_ALONZO = 5
BlockTypeAlonzo = 5

BLOCK_HEADER_TYPE_ALONZO = 4
BlockHeaderTypeAlonzo = 4

TX_TYPE_ALONZO = 4
TxTypeAlonzo = 4
)

type AlonzoBlock struct {
Expand Down Expand Up @@ -58,7 +58,7 @@ func (b *AlonzoBlock) SlotNumber() uint64 {
}

func (b *AlonzoBlock) Era() Era {
return eras[ERA_ID_ALONZO]
return eras[EraIdAlonzo]
}

func (b *AlonzoBlock) Transactions() []Transaction {
Expand Down Expand Up @@ -87,7 +87,7 @@ type AlonzoBlockHeader struct {
}

func (h *AlonzoBlockHeader) Era() Era {
return eras[ERA_ID_ALONZO]
return eras[EraIdAlonzo]
}

type AlonzoTransactionBody struct {
Expand Down
12 changes: 6 additions & 6 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
)

const (
ERA_ID_BABBAGE = 5
EraIdBabbage = 5

BLOCK_TYPE_BABBAGE = 6
BlockTypeBabbage = 6

BLOCK_HEADER_TYPE_BABBAGE = 5
BlockHeaderTypeBabbage = 5

TX_TYPE_BABBAGE = 5
TxTypeBabbage = 5
)

type BabbageBlock struct {
Expand Down Expand Up @@ -58,7 +58,7 @@ func (b *BabbageBlock) SlotNumber() uint64 {
}

func (b *BabbageBlock) Era() Era {
return eras[ERA_ID_BABBAGE]
return eras[EraIdBabbage]
}

func (b *BabbageBlock) Transactions() []Transaction {
Expand Down Expand Up @@ -132,7 +132,7 @@ func (h *BabbageBlockHeader) SlotNumber() uint64 {
}

func (h *BabbageBlockHeader) Era() Era {
return eras[ERA_ID_BABBAGE]
return eras[EraIdBabbage]
}

type BabbageTransactionBody struct {
Expand Down
22 changes: 11 additions & 11 deletions ledger/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ type BlockHeader interface {

func NewBlockFromCbor(blockType uint, data []byte) (Block, error) {
switch blockType {
case BLOCK_TYPE_BYRON_EBB:
case BlockTypeByronEbb:
return NewByronEpochBoundaryBlockFromCbor(data)
case BLOCK_TYPE_BYRON_MAIN:
case BlockTypeByronMain:
return NewByronMainBlockFromCbor(data)
case BLOCK_TYPE_SHELLEY:
case BlockTypeShelley:
return NewShelleyBlockFromCbor(data)
case BLOCK_TYPE_ALLEGRA:
case BlockTypeAllegra:
return NewAllegraBlockFromCbor(data)
case BLOCK_TYPE_MARY:
case BlockTypeMary:
return NewMaryBlockFromCbor(data)
case BLOCK_TYPE_ALONZO:
case BlockTypeAlonzo:
return NewAlonzoBlockFromCbor(data)
case BLOCK_TYPE_BABBAGE:
case BlockTypeBabbage:
return NewBabbageBlockFromCbor(data)
}
return nil, fmt.Errorf("unknown node-to-client block type: %d", blockType)
Expand All @@ -57,14 +57,14 @@ func NewBlockFromCbor(blockType uint, data []byte) (Block, error) {
// XXX: should this take the block header type instead?
func NewBlockHeaderFromCbor(blockType uint, data []byte) (BlockHeader, error) {
switch blockType {
case BLOCK_TYPE_BYRON_EBB:
case BlockTypeByronEbb:
return NewByronEpochBoundaryBlockHeaderFromCbor(data)
case BLOCK_TYPE_BYRON_MAIN:
case BlockTypeByronMain:
return NewByronMainBlockHeaderFromCbor(data)
// TODO: break into separate cases and parse as specific block header types
case BLOCK_TYPE_SHELLEY, BLOCK_TYPE_ALLEGRA, BLOCK_TYPE_MARY, BLOCK_TYPE_ALONZO:
case BlockTypeShelley, BlockTypeAllegra, BlockTypeMary, BlockTypeAlonzo:
return NewShelleyBlockHeaderFromCbor(data)
case BLOCK_TYPE_BABBAGE:
case BlockTypeBabbage:
return NewBabbageBlockHeaderFromCbor(data)
}
return nil, fmt.Errorf("unknown node-to-node block type: %d", blockType)
Expand Down
24 changes: 12 additions & 12 deletions ledger/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import (
)

const (
ERA_ID_BYRON = 0
EraIdByron = 0

BLOCK_TYPE_BYRON_EBB = 0
BLOCK_TYPE_BYRON_MAIN = 1
BlockTypeByronEbb = 0
BlockTypeByronMain = 1

BLOCK_HEADER_TYPE_BYRON = 0
BlockHeaderTypeByron = 0

TX_TYPE_BYRON = 0
TxTypeByron = 0

BYRON_SLOTS_PER_EPOCH = 21600
ByronSlotsPerEpoch = 21600
)

type ByronMainBlockHeader struct {
Expand Down Expand Up @@ -82,7 +82,7 @@ func (h *ByronMainBlockHeader) Hash() string {
// Prepend bytes for CBOR list wrapper
// The block hash is calculated with these extra bytes, so we have to add them to
// get the correct value
h.hash = generateBlockHeaderHash(h.Cbor(), []byte{0x82, BLOCK_TYPE_BYRON_MAIN})
h.hash = generateBlockHeaderHash(h.Cbor(), []byte{0x82, BlockTypeByronMain})
}
return h.hash
}
Expand All @@ -93,11 +93,11 @@ func (h *ByronMainBlockHeader) BlockNumber() uint64 {
}

func (h *ByronMainBlockHeader) SlotNumber() uint64 {
return uint64((h.ConsensusData.SlotId.Epoch * BYRON_SLOTS_PER_EPOCH) + uint64(h.ConsensusData.SlotId.Slot))
return uint64((h.ConsensusData.SlotId.Epoch * ByronSlotsPerEpoch) + uint64(h.ConsensusData.SlotId.Slot))
}

func (h *ByronMainBlockHeader) Era() Era {
return eras[ERA_ID_BYRON]
return eras[EraIdByron]
}

type ByronTransaction struct {
Expand Down Expand Up @@ -169,7 +169,7 @@ func (h *ByronEpochBoundaryBlockHeader) Hash() string {
// Prepend bytes for CBOR list wrapper
// The block hash is calculated with these extra bytes, so we have to add them to
// get the correct value
h.hash = generateBlockHeaderHash(h.Cbor(), []byte{0x82, BLOCK_TYPE_BYRON_EBB})
h.hash = generateBlockHeaderHash(h.Cbor(), []byte{0x82, BlockTypeByronEbb})
}
return h.hash
}
Expand All @@ -180,11 +180,11 @@ func (h *ByronEpochBoundaryBlockHeader) BlockNumber() uint64 {
}

func (h *ByronEpochBoundaryBlockHeader) SlotNumber() uint64 {
return uint64(h.ConsensusData.Epoch * BYRON_SLOTS_PER_EPOCH)
return uint64(h.ConsensusData.Epoch * ByronSlotsPerEpoch)
}

func (h *ByronEpochBoundaryBlockHeader) Era() Era {
return eras[ERA_ID_BYRON]
return eras[EraIdByron]
}

type ByronMainBlock struct {
Expand Down
24 changes: 12 additions & 12 deletions ledger/era.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ type Era struct {
}

var eras = map[uint8]Era{
ERA_ID_BYRON: Era{
Id: ERA_ID_BYRON,
EraIdByron: Era{
Id: EraIdByron,
Name: "Byron",
},
ERA_ID_SHELLEY: Era{
Id: ERA_ID_SHELLEY,
EraIdShelley: Era{
Id: EraIdShelley,
Name: "Shelley",
},
ERA_ID_ALLEGRA: Era{
Id: ERA_ID_ALLEGRA,
EraIdAllegra: Era{
Id: EraIdAllegra,
Name: "Allegra",
},
ERA_ID_MARY: Era{
Id: ERA_ID_MARY,
EraIdMary: Era{
Id: EraIdMary,
Name: "Mary",
},
ERA_ID_ALONZO: Era{
Id: ERA_ID_ALONZO,
EraIdAlonzo: Era{
Id: EraIdAlonzo,
Name: "Alonzo",
},
ERA_ID_BABBAGE: Era{
Id: ERA_ID_BABBAGE,
EraIdBabbage: Era{
Id: EraIdBabbage,
Name: "Babbage",
},
}
Expand Down
Loading
Loading