-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathbackend.go
151 lines (138 loc) · 4.97 KB
/
backend.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2018 The Fractal Team Authors
// This file is part of the fractal project.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// package rpcapi implements the general API functions.
package rpcapi
import (
"context"
"math/big"
"github.com/fractalplatform/fractal/accountmanager"
"github.com/fractalplatform/fractal/blockchain"
"github.com/fractalplatform/fractal/common"
"github.com/fractalplatform/fractal/consensus"
"github.com/fractalplatform/fractal/debug"
"github.com/fractalplatform/fractal/feemanager"
"github.com/fractalplatform/fractal/params"
"github.com/fractalplatform/fractal/processor/vm"
"github.com/fractalplatform/fractal/rpc"
"github.com/fractalplatform/fractal/rpcapi/filters"
"github.com/fractalplatform/fractal/state"
"github.com/fractalplatform/fractal/txpool"
"github.com/fractalplatform/fractal/types"
"github.com/fractalplatform/fractal/utils/fdb"
)
// Backend interface provides the common API services (that are provided by
// both full and light clients) with access to necessary functions.
type Backend interface {
// ftservice API
ChainDb() fdb.Database
ChainConfig() *params.ChainConfig
SuggestPrice(ctx context.Context) (*big.Int, error)
// BlockChain API
CurrentBlock() *types.Block
HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) *types.Header
BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) *types.Block
StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error)
GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error)
GetReceipts(ctx context.Context, blockHash common.Hash) ([]*types.Receipt, error)
GetDetailTxsLog(ctx context.Context, hash common.Hash) ([]*types.DetailTx, error)
GetBlockDetailLog(ctx context.Context, blockNr rpc.BlockNumber) *types.BlockAndResult
GetTd(blockHash common.Hash) *big.Int
GetEVM(ctx context.Context, account *accountmanager.AccountManager, state *state.StateDB, from common.Name, to common.Name, assetID uint64, gasPrice *big.Int, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error)
GetDetailTxByFilter(ctx context.Context, filterFn func(common.Name) bool, blockNr, lookbackNum uint64) []*types.DetailTx
GetTxsByFilter(ctx context.Context, filterFn func(common.Name) bool, blockNr, lookbackNum uint64) *types.AccountTxs
GetBadBlocks(ctx context.Context) ([]*types.Block, error)
ForkStatus(statedb *state.StateDB) (*blockchain.ForkConfig, blockchain.ForkInfo, error)
SetStatePruning(enable bool) (bool, uint64)
// TxPool
TxPool() *txpool.TxPool
SendTx(ctx context.Context, signedTx *types.Transaction) error
SetGasPrice(gasPrice *big.Int) bool
//Account API
GetAccountManager() (*accountmanager.AccountManager, error)
//fee manager
GetFeeManager() (*feemanager.FeeManager, error)
GetFeeManagerByTime(time uint64) (*feemanager.FeeManager, error)
// P2P
AddPeer(url string) error
RemovePeer(url string) error
AddTrustedPeer(url string) error
RemoveTrustedPeer(url string) error
SeedNodes() []string
PeerCount() int
Peers() []string
BadNodesCount() int
BadNodes() []string
AddBadNode(url string) error
RemoveBadNode(url string) error
SelfNode() string
Engine() consensus.IEngine
APIs() []rpc.API
// Filter Log
HeaderByHash(ctx context.Context, blockHash common.Hash) *types.Header
GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error)
}
func GetAPIs(apiBackend Backend) []rpc.API {
apis := []rpc.API{
{
Namespace: "txpool",
Version: "1.0",
Service: NewPrivateTxPoolAPI(apiBackend),
},
{
Namespace: "bc",
Version: "1.0",
Service: NewPrivateBlockChainAPI(apiBackend),
},
{
Namespace: "ft",
Version: "1.0",
Service: NewPublicBlockChainAPI(apiBackend),
Public: true,
}, {
Namespace: "ft",
Version: "1.0",
Service: NewPublicFractalAPI(apiBackend),
Public: true,
}, {
Namespace: "ft",
Version: "1.0",
Service: filters.NewPublicFilterAPI(apiBackend),
Public: true,
},
{
Namespace: "account",
Version: "1.0",
Service: NewAccountAPI(apiBackend),
Public: true,
}, {
Namespace: "fee",
Version: "1.0",
Service: NewFeeAPI(apiBackend),
Public: true,
},
{
Namespace: "p2p",
Version: "1.0",
Service: NewPrivateP2pAPI(apiBackend),
},
{
Namespace: "debug",
Version: "1.0",
Service: debug.Handler,
},
}
return append(apis, apiBackend.APIs()...)
}