diff --git a/tools/walletextension/common/common.go b/tools/walletextension/common/common.go index d2e974beec..500981fe30 100644 --- a/tools/walletextension/common/common.go +++ b/tools/walletextension/common/common.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "os" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/ecies" @@ -78,3 +79,20 @@ func (r *RPCRequest) Clone() *RPCRequest { Params: r.Params, } } + +// NewFileLogger is a logger factory function +func NewFileLogger() gethlog.Logger { + // Open or create your log file + file, err := os.OpenFile("gateway_logs.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644) + if err != nil { + panic(err) + } + + // Create a new logger instance + logger := gethlog.New() + + // Set the handler to the file + logger.SetHandler(gethlog.StreamHandler(file, gethlog.TerminalFormat(false))) + + return logger +} diff --git a/tools/walletextension/wallet_extension.go b/tools/walletextension/wallet_extension.go index edbd9f7160..58bb40ba0a 100644 --- a/tools/walletextension/wallet_extension.go +++ b/tools/walletextension/wallet_extension.go @@ -37,6 +37,7 @@ type WalletExtension struct { unsignedVKs map[gethcommon.Address]*viewingkey.ViewingKey // Map temporarily holding VKs that have been generated but not yet signed storage storage.Storage logger gethlog.Logger + fileLogger gethlog.Logger stopControl *stopcontrol.StopControl version string config *config.Config @@ -59,6 +60,7 @@ func New( panic(err) } newTenClient := obsclient.NewObsClient(rpcClient) + newFileLogger := common.NewFileLogger() return &WalletExtension{ hostAddrHTTP: hostAddrHTTP, hostAddrWS: hostAddrWS, @@ -66,6 +68,7 @@ func New( unsignedVKs: map[gethcommon.Address]*viewingkey.ViewingKey{}, storage: storage, logger: logger, + fileLogger: newFileLogger, stopControl: stopControl, version: version, config: config, @@ -92,11 +95,13 @@ func (w *WalletExtension) ProxyEthRequest(request *common.RPCRequest, conn userc // proxyRequest will find the correct client to proxy the request (or try them all if appropriate) var rpcResp interface{} + w.fileLogger.Info(fmt.Sprintf("Request method: %s, request params: %s, encryptionToken of sender: %s", request.Method, request.Params, hexUserID)) // wallet extension can override the GetStorageAt to retrieve the current userID if request.Method == rpc.GetStorageAt { if interceptedResponse := w.getStorageAtInterceptor(request, hexUserID); interceptedResponse != nil { w.logger.Info("interception successful for getStorageAt, returning userID response") + w.fileLogger.Info(fmt.Sprintf("Request method: %s, request params: %s, encryptionToken of sender: %s, response: %s", request.Method, request.Params, hexUserID, interceptedResponse)) return interceptedResponse, nil } } @@ -113,6 +118,7 @@ func (w *WalletExtension) ProxyEthRequest(request *common.RPCRequest, conn userc if errors.Is(err, rpc.ErrNilResponse) { // 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 + w.fileLogger.Info(fmt.Sprintf("Request method: %s, request params: %s, encryptionToken of sender: %s, response: %s", request.Method, request.Params, hexUserID, response)) return response, nil } return nil, err @@ -123,6 +129,7 @@ func (w *WalletExtension) ProxyEthRequest(request *common.RPCRequest, conn userc // todo (@ziga) - fix this upstream on the decode // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-658.md adjustStateRoot(rpcResp, response) + w.fileLogger.Info(fmt.Sprintf("Request method: %s, request params: %s, encryptionToken of sender: %s, response: %s", request.Method, request.Params, hexUserID, response)) return response, nil }