Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene committed Feb 13, 2024
1 parent 9a46ced commit a207e06
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions tools/walletextension/accountmanager/account_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,34 +253,28 @@ func (m *AccountManager) suggestAccountClient(req *wecommon.RPCRequest, accClien
return client
}
}

// per call specific logic to determine the sender.
if req.Method == rpc.Call || req.Method == rpc.EstimateGas {
switch req.Method {
case rpc.Call, rpc.EstimateGas:
return m.handleEthCall(req, accClients)
} else if req.Method == rpc.GetBalance {
if len(req.Params) == 0 {
return nil
}
requestedAddress, err := gethencoding.ExtractAddress(req.Params[0])
if err == nil {
return accClients[*requestedAddress]
}
} else if req.Method == rpc.GetLogs {
forAddressHex, ok := req.Params[1].(string)
if !ok {
return nil
}
forAddress := gethcommon.HexToAddress(forAddressHex)
return accClients[forAddress]
} else if req.Method == rpc.GetTransactionCount {
forAddressHex, ok := req.Params[0].(string)
if !ok {
return nil
}
forAddress := gethcommon.HexToAddress(forAddressHex)
return accClients[forAddress]
case rpc.GetBalance:
return extractAddress(0, req.Params, accClients)
case rpc.GetLogs:
return extractAddress(1, req.Params, accClients)
case rpc.GetTransactionCount:
return extractAddress(0, req.Params, accClients)
default:
return nil
}
}

func extractAddress(pos int, params []interface{}, accClients map[gethcommon.Address]*rpc.EncRPCClient) *rpc.EncRPCClient {
if len(params) < pos+1 {
return nil
}
requestedAddress, err := gethencoding.ExtractAddress(params[pos])
if err == nil {
return accClients[*requestedAddress]
}
return nil
}

Expand Down

0 comments on commit a207e06

Please sign in to comment.