From dc769561d52393a13686e2872ec349e5c48af19a Mon Sep 17 00:00:00 2001 From: Matt <98158711+BedrockSquirrel@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:43:56 +0000 Subject: [PATCH] Host RPC: use checksum format for contract addresses (#1674) --- go/host/rpc/clientapi/client_api_obscuro.go | 34 +++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/go/host/rpc/clientapi/client_api_obscuro.go b/go/host/rpc/clientapi/client_api_obscuro.go index 2c72a79767..2b0db66784 100644 --- a/go/host/rpc/clientapi/client_api_obscuro.go +++ b/go/host/rpc/clientapi/client_api_obscuro.go @@ -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" ) @@ -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, + } }