Skip to content

Commit

Permalink
remove unused funcs and clean up var reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidOrchard committed Sep 10, 2024
1 parent 8f26d15 commit c3f5616
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions core/capabilities/gateway_connector/service_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@ func (h *connectorSigner) Sign(data ...[]byte) ([]byte, error) {
return gwcommon.SignData(h.signerKey, data...)
}

func (h *connectorSigner) Start(ctx context.Context) error {
return h.StartOnce("ConnectorSigner", func() error {
return nil
})
}
func (h *connectorSigner) Close() error {
return h.StopOnce("ConnectorSigner", func() (err error) {
return nil
})
}

func (h *connectorSigner) SetConnector(connector connector.GatewayConnector) {
h.connector = connector
}

func translateConfigs(f config.GatewayConnector) connector.ConnectorConfig {
r := connector.ConnectorConfig{}
r.NodeAddress = f.NodeAddress()
Expand Down Expand Up @@ -97,31 +82,32 @@ func NewGatewayConnectorServiceWrapper(config config.GatewayConnector, keystore
func (e *ServiceWrapper) Start(ctx context.Context) error {
return e.StartOnce("GatewayConnectorServiceWrapper", func() error {
conf := e.config
chainID, _ := new(big.Int).SetString(conf.ChainIDForNodeKey(), 0)
nodeAddress := conf.ChainIDForNodeKey()
chainID, _ := new(big.Int).SetString(nodeAddress, 0)
enabledKeys, err := e.keystore.EnabledKeysForChain(ctx, chainID)
if err != nil {
return err
}
if len(enabledKeys) == 0 {
return errors.New("no available keys found")
}
configuredNodeAddress := common.HexToAddress(conf.NodeAddress())
configuredNodeAddress := common.HexToAddress(nodeAddress)
idx := slices.IndexFunc(enabledKeys, func(key ethkey.KeyV2) bool { return key.Address == configuredNodeAddress })

if idx == -1 {
return errors.New("key for configured node address not found")
}
signerKey := enabledKeys[idx].ToEcdsaPrivKey()
if enabledKeys[idx].ID() != conf.NodeAddress() {
if enabledKeys[idx].ID() != nodeAddress {
return errors.New("node address mismatch")
}

signer, err := NewConnectorSigner(e.config, signerKey, e.lggr)
signer, err := NewConnectorSigner(conf, signerKey, e.lggr)
if err != nil {
return err
}
translated := translateConfigs(conf)
e.connector, err = connector.NewGatewayConnector(&translated, signer, clockwork.NewRealClock(), e.lggr)
e.connector, err = connector.NewGatewayConnector(&translated, signer, clockwork.NewFakeClock(), e.lggr)
if err != nil {
return err
}
Expand Down

0 comments on commit c3f5616

Please sign in to comment.