forked from ten-protocol/go-ten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_api_obscuro.go
57 lines (49 loc) · 1.9 KB
/
client_api_obscuro.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
package clientapi
import (
"context"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/common/host"
)
// ObscuroAPI implements Obscuro-specific JSON RPC operations.
type ObscuroAPI struct {
host host.Host
}
func NewObscuroAPI(host host.Host) *ObscuroAPI {
return &ObscuroAPI{
host: host,
}
}
// Health returns the health status of obscuro host + enclave + db
func (api *ObscuroAPI) Health(ctx context.Context) (*host.HealthCheck, error) {
return api.host.HealthCheck(ctx)
}
// Config returns the config status of obscuro host + enclave + db
func (api *ObscuroAPI) Config() (*ChecksumFormattedObscuroNetworkConfig, error) {
config, err := api.host.ObscuroConfig()
if err != nil {
return nil, err
}
return checksumFormatted(config), nil
}
// ChecksumFormattedObscuroNetworkConfig serialises the addresses as EIP55 checksum addresses.
type ChecksumFormattedObscuroNetworkConfig struct {
ManagementContractAddress gethcommon.AddressEIP55
L1StartHash gethcommon.Hash
MessageBusAddress gethcommon.AddressEIP55
L2MessageBusAddress gethcommon.AddressEIP55
ImportantContracts map[string]gethcommon.AddressEIP55 // map of contract name to address
}
func checksumFormatted(info *common.ObscuroNetworkInfo) *ChecksumFormattedObscuroNetworkConfig {
importantContracts := make(map[string]gethcommon.AddressEIP55)
for name, addr := range info.ImportantContracts {
importantContracts[name] = gethcommon.AddressEIP55(addr)
}
return &ChecksumFormattedObscuroNetworkConfig{
ManagementContractAddress: gethcommon.AddressEIP55(info.ManagementContractAddress),
L1StartHash: info.L1StartHash,
MessageBusAddress: gethcommon.AddressEIP55(info.MessageBusAddress),
L2MessageBusAddress: gethcommon.AddressEIP55(info.L2MessageBusAddress),
ImportantContracts: importantContracts,
}
}