-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
80 lines (66 loc) · 1.93 KB
/
config.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
package gaudius
import (
"fmt"
"github.com/alecsavvy/gaudius/gen/contracts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
type AudiusSdkParams struct {
DiscoveryNodes []string
ContentNodes []string
EntityManagerAddress string
RegistryAddress string
EthereumRpc string
}
func NewAudiusSdkMainnetParams() *AudiusSdkParams {
return &AudiusSdkParams{
DiscoveryNodes: MainnetDiscoveryNodesCached,
ContentNodes: MainnetContentNodesCached,
EntityManagerAddress: MainnetAcdcAddress,
RegistryAddress: MainnetRegistryAddress,
}
}
func NewAudiusSdkTestnetParams() *AudiusSdkParams {
return &AudiusSdkParams{
DiscoveryNodes: TestnetDiscoveryNodesCached,
ContentNodes: TestnetContentNodesCached,
EntityManagerAddress: TestnetAcdcAddress,
RegistryAddress: TestnetRegistryAddress,
}
}
func NewCustomSdk(params *AudiusSdkParams) (*AudiusSdk, error) {
discovery, err := NewDiscoveryNode(params.DiscoveryNodes)
if err != nil {
return nil, err
}
content, err := NewContentNode(params.ContentNodes)
if err != nil {
return nil, err
}
addr := common.HexToAddress(params.EntityManagerAddress)
acdcEndpoint := fmt.Sprintf("%s/chain", discovery.SelectedNode)
cl, err := ethclient.Dial(acdcEndpoint)
if err != nil {
return nil, err
}
em, err := contracts.NewEntityManager(addr, cl)
if err != nil {
return nil, err
}
sdk := &AudiusSdk{Discovery: discovery, Content: content, AcdcClient: cl, EntityManager: em, EntityManagerAddress: &addr}
// conditional features
// init eth rpc and contracts if eth rpc supplied
if params.EthereumRpc != "" {
ethrpc, err := ethclient.Dial(params.EthereumRpc)
if err != nil {
return nil, err
}
contracts, err := NewAudiusContracts(ethrpc, params.RegistryAddress)
if err != nil {
return nil, err
}
sdk.EthereumClient = ethrpc
sdk.Contracts = contracts
}
return sdk, nil
}