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
2 changes: 1 addition & 1 deletion cmd/gouroboros/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func chainSyncRollForwardHandler(
block = v
case ledger.BlockHeader:
blockSlot := v.SlotNumber()
blockHash, _ := hex.DecodeString(v.Hash())
blockHash := v.Hash().Bytes()
var err error
if oConn == nil {
return errors.New("empty ouroboros connection, aborting!")
Expand Down
12 changes: 5 additions & 7 deletions ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package allegra

import (
"encoding/hex"
"fmt"

"github.com/blinklabs-io/gouroboros/cbor"
Expand Down Expand Up @@ -61,15 +60,15 @@ func (AllegraBlock) Type() int {
return BlockTypeAllegra
}

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

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

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

Expand Down Expand Up @@ -108,7 +107,6 @@ func (b *AllegraBlock) Transactions() []common.Transaction {

func (b *AllegraBlock) Utxorpc() *utxorpc.Block {
txs := []*utxorpc.Tx{}
tmpHash, _ := hex.DecodeString(b.Hash())
for _, t := range b.Transactions() {
tx := t.Utxorpc()
txs = append(txs, tx)
Expand All @@ -117,7 +115,7 @@ func (b *AllegraBlock) Utxorpc() *utxorpc.Block {
Tx: txs,
}
header := &utxorpc.BlockHeader{
Hash: tmpHash,
Hash: b.Hash().Bytes(),
Height: b.BlockNumber(),
Slot: b.SlotNumber(),
}
Expand Down Expand Up @@ -178,7 +176,7 @@ func (AllegraTransaction) Type() int {
return TxTypeAllegra
}

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

Expand Down Expand Up @@ -280,7 +278,7 @@ func (t AllegraTransaction) Produced() []common.Utxo {
ret = append(
ret,
common.Utxo{
Id: shelley.NewShelleyTransactionInput(t.Hash(), idx),
Id: shelley.NewShelleyTransactionInput(t.Hash().String(), idx),
Output: output,
},
)
Expand Down
12 changes: 5 additions & 7 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package alonzo

import (
"encoding/hex"
"encoding/json"
"fmt"

Expand Down Expand Up @@ -64,15 +63,15 @@ func (AlonzoBlock) Type() int {
return BlockTypeAlonzo
}

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

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

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

Expand Down Expand Up @@ -117,7 +116,6 @@ func (b *AlonzoBlock) Transactions() []common.Transaction {

func (b *AlonzoBlock) Utxorpc() *utxorpc.Block {
txs := []*utxorpc.Tx{}
tmpHash, _ := hex.DecodeString(b.Hash())
for _, t := range b.Transactions() {
tx := t.Utxorpc()
txs = append(txs, tx)
Expand All @@ -126,7 +124,7 @@ func (b *AlonzoBlock) Utxorpc() *utxorpc.Block {
Tx: txs,
}
header := &utxorpc.BlockHeader{
Hash: tmpHash,
Hash: b.Hash().Bytes(),
Height: b.BlockNumber(),
Slot: b.SlotNumber(),
}
Expand Down Expand Up @@ -370,7 +368,7 @@ func (AlonzoTransaction) Type() int {
return TxTypeAlonzo
}

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

Expand Down Expand Up @@ -477,7 +475,7 @@ func (t AlonzoTransaction) Produced() []common.Utxo {
ret = append(
ret,
common.Utxo{
Id: shelley.NewShelleyTransactionInput(t.Hash(), idx),
Id: shelley.NewShelleyTransactionInput(t.Hash().String(), idx),
Output: output,
},
)
Expand Down
34 changes: 14 additions & 20 deletions ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package babbage

import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -66,15 +65,15 @@ func (BabbageBlock) Type() int {
return BlockTypeBabbage
}

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

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

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

Expand Down Expand Up @@ -119,7 +118,6 @@ func (b *BabbageBlock) Transactions() []common.Transaction {

func (b *BabbageBlock) Utxorpc() *utxorpc.Block {
txs := []*utxorpc.Tx{}
tmpHash, _ := hex.DecodeString(b.Hash())
for _, t := range b.Transactions() {
tx := t.Utxorpc()
txs = append(txs, tx)
Expand All @@ -128,7 +126,7 @@ func (b *BabbageBlock) Utxorpc() *utxorpc.Block {
Tx: txs,
}
header := &utxorpc.BlockHeader{
Hash: tmpHash,
Hash: b.Hash().Bytes(),
Height: b.BlockNumber(),
Slot: b.SlotNumber(),
}
Expand All @@ -142,7 +140,7 @@ func (b *BabbageBlock) Utxorpc() *utxorpc.Block {
type BabbageBlockHeader struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
hash string
hash *common.Blake2b256
Body BabbageBlockHeaderBody
Signature []byte
}
Expand Down Expand Up @@ -179,16 +177,16 @@ func (h *BabbageBlockHeader) UnmarshalCBOR(cborData []byte) error {
return h.UnmarshalCbor(cborData, h)
}

func (h *BabbageBlockHeader) Hash() string {
if h.hash == "" {
func (h *BabbageBlockHeader) Hash() common.Blake2b256 {
if h.hash == nil {
tmpHash := common.Blake2b256Hash(h.Cbor())
h.hash = hex.EncodeToString(tmpHash.Bytes())
h.hash = &tmpHash
}
return h.hash
return *h.hash
}

func (h *BabbageBlockHeader) PrevHash() string {
return h.Body.PrevHash.String()
func (h *BabbageBlockHeader) PrevHash() common.Blake2b256 {
return h.Body.PrevHash
}

func (h *BabbageBlockHeader) BlockNumber() uint64 {
Expand Down Expand Up @@ -282,10 +280,6 @@ func (b *BabbageTransactionBody) Utxorpc() *utxorpc.Tx {
input := ri.Utxorpc()
txri = append(txri, input)
}
tmpHash, err := hex.DecodeString(b.Hash())
if err != nil {
return &utxorpc.Tx{}
}
tx := &utxorpc.Tx{
Inputs: txi,
Outputs: txo,
Expand All @@ -299,7 +293,7 @@ func (b *BabbageTransactionBody) Utxorpc() *utxorpc.Tx {
// Successful: b.Successful(),
// Auxiliary: b.AuxData(),
// Validity: b.Validity(),
Hash: tmpHash,
Hash: b.Hash().Bytes(),
}
return tx
}
Expand Down Expand Up @@ -523,7 +517,7 @@ func (BabbageTransaction) Type() int {
return TxTypeBabbage
}

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

Expand Down Expand Up @@ -630,7 +624,7 @@ func (t BabbageTransaction) Produced() []common.Utxo {
ret = append(
ret,
common.Utxo{
Id: shelley.NewShelleyTransactionInput(t.Hash(), idx),
Id: shelley.NewShelleyTransactionInput(t.Hash().String(), idx),
Output: output,
},
)
Expand All @@ -642,7 +636,7 @@ func (t BabbageTransaction) Produced() []common.Utxo {
}
return []common.Utxo{
{
Id: shelley.NewShelleyTransactionInput(t.Hash(), len(t.Outputs())),
Id: shelley.NewShelleyTransactionInput(t.Hash().String(), len(t.Outputs())),
Output: t.CollateralReturn(),
},
}
Expand Down
4 changes: 1 addition & 3 deletions ledger/babbage/babbage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package babbage

import (
"encoding/hex"
"testing"

"github.com/blinklabs-io/gouroboros/ledger/alonzo"
Expand Down Expand Up @@ -2747,8 +2746,7 @@ func TestBabbageBlock_Utxorpc(t *testing.T) {
assert.Equal(t, len(babbageBlock.TransactionBodies), len(utxoBlock.Body.Tx))

// Validate the header details
tmpHash, _ := hex.DecodeString(babbageBlock.Hash())
assert.Equal(t, tmpHash, utxoBlock.Header.Hash)
assert.Equal(t, babbageBlock.Hash().Bytes(), utxoBlock.Header.Hash)
assert.Equal(t, babbageBlock.BlockNumber(), utxoBlock.Header.Height)
assert.Equal(t, babbageBlock.SlotNumber(), utxoBlock.Header.Slot)

Expand Down
Loading
Loading