-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1383 from maticnetwork/v1.5.3-beta-candidate
v1.5.3 candidate
- Loading branch information
Showing
21 changed files
with
300 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,5 @@ do | |
fi | ||
done | ||
|
||
echo $peers | ||
echo $block | ||
echo "$peers" | ||
echo "$block" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/common/math" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
|
||
protobor "github.com/maticnetwork/polyproto/bor" | ||
protoutil "github.com/maticnetwork/polyproto/utils" | ||
) | ||
|
||
func (s *Server) GetRootHash(ctx context.Context, req *protobor.GetRootHashRequest) (*protobor.GetRootHashResponse, error) { | ||
rootHash, err := s.backend.APIBackend.GetRootHash(ctx, req.StartBlockNumber, req.EndBlockNumber) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &protobor.GetRootHashResponse{RootHash: rootHash}, nil | ||
} | ||
|
||
func (s *Server) GetVoteOnHash(ctx context.Context, req *protobor.GetVoteOnHashRequest) (*protobor.GetVoteOnHashResponse, error) { | ||
vote, err := s.backend.APIBackend.GetVoteOnHash(ctx, req.StartBlockNumber, req.EndBlockNumber, req.Hash, req.MilestoneId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &protobor.GetVoteOnHashResponse{Response: vote}, nil | ||
} | ||
|
||
func headerToProtoborHeader(h *types.Header) *protobor.Header { | ||
return &protobor.Header{ | ||
Number: h.Number.Uint64(), | ||
ParentHash: protoutil.ConvertHashToH256(h.ParentHash), | ||
Time: h.Time, | ||
} | ||
} | ||
|
||
func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) { | ||
bN, err := getRpcBlockNumberFromString(req.Number) | ||
if err != nil { | ||
return nil, err | ||
} | ||
header, err := s.backend.APIBackend.HeaderByNumber(ctx, bN) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &protobor.GetHeaderByNumberResponse{Header: headerToProtoborHeader(header)}, nil | ||
} | ||
|
||
func (s *Server) BlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) { | ||
bN, err := getRpcBlockNumberFromString(req.Number) | ||
if err != nil { | ||
return nil, err | ||
} | ||
block, err := s.backend.APIBackend.BlockByNumber(ctx, bN) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &protobor.GetBlockByNumberResponse{Block: blockToProtoBlock(block)}, nil | ||
} | ||
|
||
func blockToProtoBlock(h *types.Block) *protobor.Block { | ||
return &protobor.Block{ | ||
Header: headerToProtoborHeader(h.Header()), | ||
} | ||
} | ||
|
||
func (s *Server) TransactionReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { | ||
_, _, blockHash, _, txnIndex, err := s.backend.APIBackend.GetTransaction(ctx, protoutil.ConvertH256ToHash(req.Hash)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
receipts, err := s.backend.APIBackend.GetReceipts(ctx, blockHash) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if receipts == nil { | ||
return nil, errors.New("no receipts found") | ||
} | ||
|
||
if len(receipts) <= int(txnIndex) { | ||
return nil, errors.New("transaction index out of bounds") | ||
} | ||
|
||
return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipts[txnIndex])}, nil | ||
} | ||
|
||
func (s *Server) BorBlockReceipt(ctx context.Context, req *protobor.ReceiptRequest) (*protobor.ReceiptResponse, error) { | ||
receipt, err := s.backend.APIBackend.GetBorBlockReceipt(ctx, protoutil.ConvertH256ToHash(req.Hash)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipt)}, nil | ||
} | ||
|
||
func getRpcBlockNumberFromString(blockNumber string) (rpc.BlockNumber, error) { | ||
switch blockNumber { | ||
case "latest": | ||
return rpc.LatestBlockNumber, nil | ||
case "earliest": | ||
return rpc.EarliestBlockNumber, nil | ||
case "pending": | ||
return rpc.PendingBlockNumber, nil | ||
case "finalized": | ||
return rpc.FinalizedBlockNumber, nil | ||
case "safe": | ||
return rpc.SafeBlockNumber, nil | ||
default: | ||
blckNum, err := hexutil.DecodeUint64(blockNumber) | ||
if err != nil { | ||
return rpc.BlockNumber(0), errors.New("invalid block number") | ||
} | ||
if blckNum > math.MaxInt64 { | ||
return rpc.BlockNumber(0), errors.New("block number out of range") | ||
} | ||
return rpc.BlockNumber(blckNum), nil | ||
} | ||
} |
Oops, something went wrong.