Skip to content

Commit

Permalink
chg: logs
Browse files Browse the repository at this point in the history
  • Loading branch information
marcello33 committed Nov 8, 2024
1 parent af5c327 commit af939db
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
2 changes: 0 additions & 2 deletions core/bor_blockchain.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package core

import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
)

// GetBorReceiptByHash retrieves the bor block receipt in a given block.
func (bc *BlockChain) GetBorReceiptByHash(hash common.Hash) *types.Receipt {
fmt.Printf(">>>>> GetBorBlockReceiptBorBlockchain\n")
if receipt, ok := bc.borReceiptsCache.Get(hash); ok {
return receipt
}
Expand Down
8 changes: 0 additions & 8 deletions eth/bor_api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var errBorEngineNotAvailable error = errors.New("Only available in Bor engine")
// GetRootHash returns root hash for given start and end block
func (b *EthAPIBackend) GetRootHash(ctx context.Context, starBlockNr uint64, endBlockNr uint64) (string, error) {
var api *bor.API
fmt.Printf(">>>>> GetRootHashApiBackend\n")

for _, _api := range b.eth.Engine().APIs(b.eth.BlockChain()) {
if _api.Namespace == "bor" {
Expand All @@ -43,7 +42,6 @@ func (b *EthAPIBackend) GetRootHash(ctx context.Context, starBlockNr uint64, end
// GetVoteOnHash returns the vote on hash
func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, endBlockNr uint64, hash string, milestoneId string) (bool, error) {
var api *bor.API
fmt.Printf(">>>>> GetVoteOnHashApiBackend\n")

for _, _api := range b.eth.Engine().APIs(b.eth.BlockChain()) {
if _api.Namespace == "bor" {
Expand Down Expand Up @@ -92,7 +90,6 @@ func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, e

// GetBorBlockReceipt returns bor block receipt
func (b *EthAPIBackend) GetBorBlockReceipt(ctx context.Context, hash common.Hash) (*types.Receipt, error) {
fmt.Printf(">>>>> GetBorBlockReceiptApiBackend\n")

receipt := b.eth.blockchain.GetBorReceiptByHash(hash)
if receipt == nil {
Expand All @@ -104,7 +101,6 @@ func (b *EthAPIBackend) GetBorBlockReceipt(ctx context.Context, hash common.Hash

// GetBorBlockLogs returns bor block logs
func (b *EthAPIBackend) GetBorBlockLogs(ctx context.Context, hash common.Hash) ([]*types.Log, error) {
fmt.Printf(">>>>> GetBorBlockLogsApiBackend\n")
receipt := b.eth.blockchain.GetBorReceiptByHash(hash)
if receipt == nil {
return nil, nil
Expand All @@ -115,25 +111,21 @@ func (b *EthAPIBackend) GetBorBlockLogs(ctx context.Context, hash common.Hash) (

// GetBorBlockTransaction returns bor block tx
func (b *EthAPIBackend) GetBorBlockTransaction(ctx context.Context, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) {
fmt.Printf(">>>>> GetBorBlockTransactionApiBackend\n")
tx, blockHash, blockNumber, index := rawdb.ReadBorTransaction(b.eth.ChainDb(), hash)
return tx, blockHash, blockNumber, index, nil
}

func (b *EthAPIBackend) GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) {
fmt.Printf(">>>>> GetBorBlockTransactionWithBlockHashApiBackend\n")
tx, blockHash, blockNumber, index := rawdb.ReadBorTransactionWithBlockHash(b.eth.ChainDb(), txHash, blockHash)
return tx, blockHash, blockNumber, index, nil
}

// SubscribeStateSyncEvent subscribes to state sync event
func (b *EthAPIBackend) SubscribeStateSyncEvent(ch chan<- core.StateSyncEvent) event.Subscription {
fmt.Printf(">>>>> SubscribeStateSyncEventApiBackend\n")
return b.eth.BlockChain().SubscribeStateSyncEvent(ch)
}

// SubscribeChain2HeadEvent subscribes to reorg/head/fork event
func (b *EthAPIBackend) SubscribeChain2HeadEvent(ch chan<- core.Chain2HeadEvent) event.Subscription {
fmt.Printf(">>>>> SubscribeChain2HeadEventApiBackend\n")
return b.eth.BlockChain().SubscribeChain2HeadEvent(ch)
}
27 changes: 21 additions & 6 deletions internal/cli/server/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,26 @@ import (
)

func (s *Server) GetRootHash(ctx context.Context, req *protobor.GetRootHashRequest) (*protobor.GetRootHashResponse, error) {
fmt.Printf(">>>>> GetRootHash: %v\n", req)
fmt.Printf(">>>>> GetRootHash: req %v\n", req)
rootHash, err := s.backend.APIBackend.GetRootHash(ctx, req.StartBlockNumber, req.EndBlockNumber)
if err != nil {
fmt.Printf(">>>>> GetRootHash: err %v\n", err)
return nil, err
}

fmt.Printf(">>>>> GetRootHash: returning\n")
return &protobor.GetRootHashResponse{RootHash: rootHash}, nil
}

func (s *Server) GetVoteOnHash(ctx context.Context, req *protobor.GetVoteOnHashRequest) (*protobor.GetVoteOnHashResponse, error) {
fmt.Printf(">>>>> GetVoteOnHash: %v\n", req)
fmt.Printf(">>>>> GetVoteOnHash: req %v\n", req)
vote, err := s.backend.APIBackend.GetVoteOnHash(ctx, req.StartBlockNumber, req.EndBlockNumber, req.Hash, req.MilestoneId)
if err != nil {
fmt.Printf(">>>>> GetVoteOnHash: err %v\n", err)
return nil, err
}

fmt.Printf(">>>>> GetVoteOnHash: returning\n")
return &protobor.GetVoteOnHashResponse{Response: vote}, nil
}

Expand All @@ -40,22 +44,26 @@ func headerToProtoborHeader(h *types.Header) *protobor.Header {
}

func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) {
fmt.Printf(">>>>> HeaderByNumber: %v\n", req)
fmt.Printf(">>>>> HeaderByNumber: req %v\n", req)
header, err := s.backend.APIBackend.HeaderByNumber(ctx, rpc.BlockNumber(req.Number))
if err != nil {
fmt.Printf(">>>>> HeaderByNumber: err %v\n", err)
return nil, err
}

fmt.Printf(">>>>> HeaderByNumber: returning\n")
return &protobor.GetHeaderByNumberResponse{Header: headerToProtoborHeader(header)}, nil
}

func (s *Server) BlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) {
fmt.Printf(">>>>> BlockByNumber: %v\n", req)
fmt.Printf(">>>>> BlockByNumber: req %v\n", req)
block, err := s.backend.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(req.Number))
if err != nil {
fmt.Printf(">>>>> BlockByNumber: err %v\n", err)
return nil, err
}

fmt.Printf(">>>>> BlockByNumber: returning\n")
return &protobor.GetBlockByNumberResponse{Block: blockToProtoBlock(block)}, nil
}

Expand All @@ -66,34 +74,41 @@ func blockToProtoBlock(h *types.Block) *protobor.Block {
}

func (s *Server) TransactionReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) {
fmt.Printf(">>>>> TransactionReceipt: %v\n", req)
fmt.Printf(">>>>> TransactionReceipt: req %v\n", req)
_, blockHash, _, txnIndex, err := s.backend.APIBackend.GetTransaction(ctx, protoutil.ConvertH256ToHash(req.Hash))
if err != nil {
fmt.Printf(">>>>> TransactionReceipt: err1 %v\n", err)
return nil, err
}

receipts, err := s.backend.APIBackend.GetReceipts(ctx, blockHash)
if err != nil {
fmt.Printf(">>>>> TransactionReceipt: err2 %v\n", err)
return nil, err
}

if receipts == nil {
fmt.Printf(">>>>> TransactionReceipt: err3 %v\n", errors.New("no receipts found"))
return nil, errors.New("no receipts found")
}

if len(receipts) <= int(txnIndex) {
fmt.Printf(">>>>> TransactionReceipt: err4 %v\n", errors.New("transaction index out of bounds"))
return nil, errors.New("transaction index out of bounds")
}

fmt.Printf(">>>>> TransactionReceipt: returning\n")
return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipts[txnIndex])}, nil
}

func (s *Server) BorBlockReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) {
fmt.Printf(">>>>> BorBlockReceipt: %v\n", req)
fmt.Printf(">>>>> BorBlockReceipt: req %v\n", req)
receipt, err := s.backend.APIBackend.GetBorBlockReceipt(ctx, protoutil.ConvertH256ToHash(req.Hash))
if err != nil {
fmt.Printf(">>>>> BorBlockReceipt: err %v\n", err)
return nil, err
}

fmt.Printf(">>>>> BorBlockReceipt: returning\n")
return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipt)}, nil
}
6 changes: 0 additions & 6 deletions internal/cli/server/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package server

import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/internal/cli/server/proto"
Expand All @@ -13,7 +12,6 @@ import (
)

func PeerInfoToPeer(info *p2p.PeerInfo) *proto.Peer {
fmt.Printf(">>>>> PeerInfoToPeer: %v\n", info)
return &proto.Peer{
Id: info.ID,
Enode: info.Enode,
Expand All @@ -26,14 +24,12 @@ func PeerInfoToPeer(info *p2p.PeerInfo) *proto.Peer {
}

func ConvertBloomToProtoBloom(bloom types.Bloom) *protobor.Bloom {
fmt.Printf(">>>>> ConvertBloomToProtoBloom: %v\n", bloom)
return &protobor.Bloom{
Bloom: bloom.Bytes(),
}
}

func ConvertLogsToProtoLogs(logs []*types.Log) []*protobor.Log {
fmt.Printf(">>>>> ConvertLogsToProtoLogs: %v\n", logs)
var protoLogs []*protobor.Log
for _, log := range logs {
protoLog := &protobor.Log{
Expand All @@ -54,7 +50,6 @@ func ConvertLogsToProtoLogs(logs []*types.Log) []*protobor.Log {
}

func ConvertTopicsToProtoTopics(topics []common.Hash) []*protocommon.H256 {
fmt.Printf(">>>>> ConvertTopicsToProtoTopics: %v\n", topics)
var protoTopics []*protocommon.H256
for _, topic := range topics {
protoTopics = append(protoTopics, protoutil.ConvertHashToH256(topic))
Expand All @@ -64,7 +59,6 @@ func ConvertTopicsToProtoTopics(topics []common.Hash) []*protocommon.H256 {
}

func ConvertReceiptToProtoReceipt(receipt *types.Receipt) *protobor.Receipt {
fmt.Printf(">>>>> ConvertReceiptToProtoReceipt: %v\n", receipt)
return &protobor.Receipt{
Type: uint64(receipt.Type),
PostState: receipt.PostState,
Expand Down

0 comments on commit af939db

Please sign in to comment.