Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene committed Mar 19, 2024
1 parent 50d6d0b commit 3fa1306
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
11 changes: 10 additions & 1 deletion tools/walletextension/accountmanager/account_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ func (m *AccountManager) ProxyRequest(rpcReq *wecommon.RPCRequest, rpcResp *inte
if err != nil {
return err
}
err = m.subscriptionsManager.HandleNewSubscriptions(clients, rpcReq, rpcResp, userConn)
critBytes, err := json.Marshal(rpcReq.Params[1])
if err != nil {
return err
}
criteria := new(filters.FilterCriteria)
err = criteria.UnmarshalJSON(critBytes)
if err != nil {
return err
}
err = m.subscriptionsManager.HandleNewSubscriptions(clients, *criteria, rpcResp, userConn)
if err != nil {
m.logger.Error("Error subscribing to multiple clients")
return err
Expand Down
14 changes: 6 additions & 8 deletions tools/walletextension/subscriptions/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/eth/filters"

"github.com/go-kit/kit/transport/http/jsonrpc"

gethlog "github.com/ethereum/go-ethereum/log"
Expand All @@ -33,12 +35,8 @@ func New(logger gethlog.Logger) *SubscriptionManager {

// HandleNewSubscriptions subscribes to an event with all the clients provided.
// Doing this is necessary because we have relevancy rule, and we want to subscribe sometimes with all clients to get all the events
func (sm *SubscriptionManager) HandleNewSubscriptions(clients []rpc.Client, req *wecommon.RPCRequest, resp *interface{}, userConn userconn.UserConn) error {
if len(req.Params) == 0 {
return fmt.Errorf("could not subscribe as no subscription namespace was provided")
}

sm.logger.Info(fmt.Sprintf("Subscribing to event %s with %d clients", req.Params, len(clients)))
func (sm *SubscriptionManager) HandleNewSubscriptions(clients []rpc.Client, criteria filters.FilterCriteria, resp *interface{}, userConn userconn.UserConn) error {
sm.logger.Info(fmt.Sprintf("Subscribing to event %s with %d clients", criteria, len(clients)))

// create subscriptionID which will enable user to unsubscribe from all subscriptions
userSubscriptionID := gethrpc.NewID()
Expand All @@ -51,9 +49,9 @@ func (sm *SubscriptionManager) HandleNewSubscriptions(clients []rpc.Client, req

// iterate over all clients and subscribe for each of them
for _, client := range clients {
subscription, err := client.Subscribe(context.Background(), resp, rpc.SubscribeNamespace, funnelMultipleAccountsChan, req.Params...)
subscription, err := client.Subscribe(context.Background(), resp, rpc.SubscribeNamespace, funnelMultipleAccountsChan, rpc.SubscriptionTypeLogs, criteria)
if err != nil {
return fmt.Errorf("could not call %s with params %v. Cause: %w", req.Method, req.Params, err)
return fmt.Errorf("could not subscrbie for logs with params %v. Cause: %w", criteria, err)
}
sm.UpdateSubscriptionMapping(string(userSubscriptionID), subscription)

Expand Down
17 changes: 6 additions & 11 deletions tools/walletextension/wallet_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,17 @@ func (w *WalletExtension) ProxyEthRequest(request *common.RPCRequest, conn userc

err = selectedAccountManager.ProxyRequest(request, &rpcResp, conn)
if err != nil {
if rpcResp == nil {
// if err was for a nil response then we will return an RPC result of null to the caller (this is a valid "not-found" response for some methods)
response[common.JSONKeyResult] = nil
requestEndTime := time.Now()
duration := requestEndTime.Sub(requestStartTime)
w.fileLogger.Info(fmt.Sprintf("Request method: %s, request params: %s, encryptionToken of sender: %s, response: %s, duration: %d ", request.Method, request.Params, hexUserID, response, duration.Milliseconds()))
return response, nil
}
return nil, err
}

response[common.JSONKeyResult] = rpcResp

// todo (@ziga) - fix this upstream on the decode
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-658.md
adjustStateRoot(rpcResp, response)
if rpcResp != nil {
// todo (@ziga) - fix this upstream on the decode
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-658.md
adjustStateRoot(rpcResp, response)
}

requestEndTime := time.Now()
duration := requestEndTime.Sub(requestStartTime)
w.fileLogger.Info(fmt.Sprintf("Request method: %s, request params: %s, encryptionToken of sender: %s, response: %s, duration: %d ", request.Method, request.Params, hexUserID, response, duration.Milliseconds()))
Expand Down

0 comments on commit 3fa1306

Please sign in to comment.