mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
chg: handle edge cases with string blockNumber
This commit is contained in:
parent
59b085a54c
commit
9cb6fcac0b
4 changed files with 39 additions and 7 deletions
|
|
@ -132,7 +132,7 @@ func (mr *MockBackendMockRecorder) GetBorBlockLogs(arg0, arg1 interface{}) *gomo
|
|||
// GetBorBlockReceipt mocks base method.
|
||||
func (m *MockBackend) GetBorBlockReceipt(arg0 context.Context, arg1 common.Hash) (*types.Receipt, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "BorBlockReceipt", arg0, arg1)
|
||||
ret := m.ctrl.Call(m, "GetBorBlockReceipt", arg0, arg1)
|
||||
ret0, _ := ret[0].(*types.Receipt)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
|
|
@ -141,7 +141,7 @@ func (m *MockBackend) GetBorBlockReceipt(arg0 context.Context, arg1 common.Hash)
|
|||
// GetBorBlockReceipt indicates an expected call of GetBorBlockReceipt.
|
||||
func (mr *MockBackendMockRecorder) GetBorBlockReceipt(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BorBlockReceipt", reflect.TypeOf((*MockBackend)(nil).GetBorBlockReceipt), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBorBlockReceipt", reflect.TypeOf((*MockBackend)(nil).GetBorBlockReceipt), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetLogs mocks base method.
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -65,7 +65,7 @@ require (
|
|||
github.com/kylelemons/godebug v1.1.0
|
||||
github.com/maticnetwork/crand v1.0.2
|
||||
github.com/maticnetwork/heimdall v1.0.7
|
||||
github.com/maticnetwork/polyproto v0.0.3
|
||||
github.com/maticnetwork/polyproto v0.0.4-0.20241113101917-6744479e4d59
|
||||
github.com/mattn/go-colorable v0.1.13
|
||||
github.com/mattn/go-isatty v0.0.20
|
||||
github.com/mitchellh/cli v1.1.5
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -1707,8 +1707,8 @@ github.com/maticnetwork/heimdall v1.0.4/go.mod h1:Xh7KFvtbs/SVNjOI8IgYmk6JdzYx89
|
|||
github.com/maticnetwork/heimdall v1.0.7 h1:QStn+hbZKxfE+PqecaorA/uATDPuQoi+U9Z7IIonb60=
|
||||
github.com/maticnetwork/heimdall v1.0.7/go.mod h1:+ANI5+VV28ahwfdl7oMzrcNwaTEs1Fn6z39BqBGcvaA=
|
||||
github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
|
||||
github.com/maticnetwork/polyproto v0.0.3 h1:a69rIp97fcl3ABY4LlVX9B2t1qhLa0Jhny3HNOzReBU=
|
||||
github.com/maticnetwork/polyproto v0.0.3/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
|
||||
github.com/maticnetwork/polyproto v0.0.4-0.20241113101917-6744479e4d59 h1:FAezvZ+jt3b1all6taYql6+mafszYBpwfD5KYQqQdNg=
|
||||
github.com/maticnetwork/polyproto v0.0.4-0.20241113101917-6744479e4d59/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
|
||||
github.com/maticnetwork/tendermint v0.33.0 h1:f+vORM02BoUOlCvnu3Zjw5rv6l6JSNVchWjH03rUuR8=
|
||||
github.com/maticnetwork/tendermint v0.33.0/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk=
|
||||
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
|
||||
|
|
|
|||
|
|
@ -38,7 +38,11 @@ func headerToProtoborHeader(h *types.Header) *protobor.Header {
|
|||
}
|
||||
|
||||
func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNumberRequest) (*protobor.GetHeaderByNumberResponse, error) {
|
||||
header, err := s.backend.APIBackend.HeaderByNumber(ctx, rpc.BlockNumber(req.Number))
|
||||
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
|
||||
}
|
||||
|
|
@ -47,7 +51,11 @@ func (s *Server) HeaderByNumber(ctx context.Context, req *protobor.GetHeaderByNu
|
|||
}
|
||||
|
||||
func (s *Server) BlockByNumber(ctx context.Context, req *protobor.GetBlockByNumberRequest) (*protobor.GetBlockByNumberResponse, error) {
|
||||
block, err := s.backend.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(req.Number))
|
||||
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
|
||||
}
|
||||
|
|
@ -91,3 +99,27 @@ func (s *Server) BorBlockReceipt(ctx context.Context, req *protobor.ReceiptReque
|
|||
|
||||
return &protobor.ReceiptResponse{Receipt: ConvertReceiptToProtoReceipt(receipt)}, nil
|
||||
}
|
||||
|
||||
func getRpcBlockNumberFromString(blockNumber string) (rpc.BlockNumber, error) {
|
||||
if blockNumber == "latest" {
|
||||
return rpc.LatestBlockNumber, nil
|
||||
}
|
||||
|
||||
if blockNumber == "earliest" {
|
||||
return rpc.EarliestBlockNumber, nil
|
||||
}
|
||||
|
||||
if blockNumber == "pending" {
|
||||
return rpc.PendingBlockNumber, nil
|
||||
}
|
||||
|
||||
if blockNumber == "finalized" {
|
||||
return rpc.FinalizedBlockNumber, nil
|
||||
}
|
||||
|
||||
if blockNumber == "safe" {
|
||||
return rpc.SafeBlockNumber, nil
|
||||
}
|
||||
|
||||
return rpc.BlockNumber(0), errors.New("invalid block number")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue