-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
59 lines (52 loc) · 1.89 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2021 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package eth
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/rpc"
"github.com/jsvisa/hdt/backend"
)
// API is the collection of tracing APIs exposed over the private debugging endpoint.
type API struct {
backend backend.Backend
}
// NewAPI creates a new API definition for the tracing methods of the Ethereum service.
func NewAPI(backend backend.Backend) *API {
return &API{backend: backend}
}
// GetBlockByNumber is the wrapper of the chain access function offered by the backend.
// It will return an error if the block is not found.
func (api *API) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) {
block, err := api.backend.BlockByNumber(ctx, number)
if err != nil {
return nil, err
}
if block == nil {
return nil, fmt.Errorf("block #%d not found", number)
}
return RPCMarshalBlock(block, true, fullTx)
}
// APIs return the collection of RPC services the tracer package offers.
func APIs(backend backend.Backend) []rpc.API {
// Append all the local APIs and return
return []rpc.API{
{
Namespace: "eth",
Service: NewAPI(backend),
},
}
}