From 3fa13068fa2c5bf31aab1a9edef1972bfac06346 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Tue, 19 Mar 2024 16:05:45 +0000 Subject: [PATCH] fix --- .../accountmanager/account_manager.go | 11 ++++++++++- .../subscriptions/subscriptions.go | 14 ++++++-------- tools/walletextension/wallet_extension.go | 17 ++++++----------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/tools/walletextension/accountmanager/account_manager.go b/tools/walletextension/accountmanager/account_manager.go index 67aefc9931..a4bad822cf 100644 --- a/tools/walletextension/accountmanager/account_manager.go +++ b/tools/walletextension/accountmanager/account_manager.go @@ -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 diff --git a/tools/walletextension/subscriptions/subscriptions.go b/tools/walletextension/subscriptions/subscriptions.go index 7d3fe3f7a4..9405a524ce 100644 --- a/tools/walletextension/subscriptions/subscriptions.go +++ b/tools/walletextension/subscriptions/subscriptions.go @@ -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" @@ -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() @@ -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) diff --git a/tools/walletextension/wallet_extension.go b/tools/walletextension/wallet_extension.go index 73e8375f1c..cf0ee4da57 100644 --- a/tools/walletextension/wallet_extension.go +++ b/tools/walletextension/wallet_extension.go @@ -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()))