-
Notifications
You must be signed in to change notification settings - Fork 0
/
apis.go
70 lines (64 loc) · 1.78 KB
/
apis.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
package rest
import (
clientcontext "github.com/ci123chain/ci123chain/pkg/client/context"
"github.com/ci123chain/ci123chain/pkg/client/helper"
"github.com/ci123chain/ci123chain/pkg/vm/client/rest/api/eth"
"github.com/ci123chain/ci123chain/pkg/vm/client/rest/api/eth/filters"
"github.com/ci123chain/ci123chain/pkg/vm/client/rest/api/net"
"github.com/ci123chain/ci123chain/pkg/vm/client/rest/api/personal"
"github.com/ci123chain/ci123chain/pkg/vm/client/rest/api/web3"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/rpc"
"github.com/spf13/viper"
)
// RPC namespaces and API version
const (
Web3Namespace = "web3"
EthNamespace = "eth"
PersonalNamespace = "personal"
NetNamespace = "net"
apiVersion = "1.0"
)
// GetAPIs returns the list of all APIs from the Ethereum namespaces
func GetAPIs(clientCtx clientcontext.Context) []rpc.API {
ks := getDefaultKeystore()
ethAPI := eth.NewAPI(clientCtx, ks)
backend := filters.New(clientCtx)
return []rpc.API{
{
Namespace: Web3Namespace,
Version: apiVersion,
Service: web3.NewAPI(),
Public: true,
},
{
Namespace: EthNamespace,
Version: apiVersion,
Service: ethAPI,
Public: true,
},
{
Namespace: EthNamespace,
Version: apiVersion,
Service: filters.NewAPI(clientCtx, backend),
Public: true,
},
{
Namespace: PersonalNamespace,
Version: apiVersion,
Service: personal.NewAPI(ethAPI, ks),
Public: false,
},
{
Namespace: NetNamespace,
Version: apiVersion,
Service: net.NewAPI(clientCtx),
Public: true,
},
}
}
func getDefaultKeystore() *keystore.KeyStore {
dir := viper.GetString(helper.FlagHomeDir)
ks := keystore.NewKeyStore(dir, keystore.StandardScryptN, keystore.StandardScryptP)
return ks
}