Skip to content

Commit

Permalink
Host RPC: use checksum format for contract addresses (#1674)
Browse files Browse the repository at this point in the history
  • Loading branch information
BedrockSquirrel authored Nov 29, 2023
1 parent 362a80b commit dc76956
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions go/host/rpc/clientapi/client_api_obscuro.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package clientapi

import (
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/common/host"
)
Expand All @@ -22,6 +23,35 @@ func (api *ObscuroAPI) Health() (*host.HealthCheck, error) {
}

// Config returns the config status of obscuro host + enclave + db
func (api *ObscuroAPI) Config() (*common.ObscuroNetworkInfo, error) {
return api.host.ObscuroConfig()
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
SequencerID gethcommon.AddressEIP55
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,
SequencerID: gethcommon.AddressEIP55(info.SequencerID),
MessageBusAddress: gethcommon.AddressEIP55(info.MessageBusAddress),
L2MessageBusAddress: gethcommon.AddressEIP55(info.L2MessageBusAddress),
ImportantContracts: importantContracts,
}
}

0 comments on commit dc76956

Please sign in to comment.