Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ GIT_ROOT ?= $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
GIT_AUTHOR ?= $(shell git config user.email || echo $$USER)

BUILD_TAGS ?= gowaku_no_rln
BUILD_TAGS ?= gowaku_no_rln rpc_panic

ifeq ($(USE_NWAKU), true)
BUILD_TAGS += use_nwaku
endif

BUILD_FLAGS ?= -ldflags=""
BUILD_FLAGS_MOBILE ?=

networkid ?= StatusChain
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ require (
github.com/btcsuite/btcd/btcutil v1.1.6
github.com/cenkalti/backoff/v4 v4.2.1
github.com/getsentry/sentry-go v0.29.1
github.com/gorilla/rpc v1.2.1
github.com/gorilla/sessions v1.2.1
github.com/gorilla/websocket v1.5.3
github.com/ipfs/go-log/v2 v2.5.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,8 @@ github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/rpc v1.2.1 h1:yC+LMV5esttgpVvNORL/xX4jvTTEUE30UZhZ5JF7K9k=
github.com/gorilla/rpc v1.2.1/go.mod h1:uNpOihAlF5xRFLuTYhfR0yfCTm0WTQSQttkMSptRfGk=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
Expand Down
9 changes: 9 additions & 0 deletions mobile/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@
return callWithResponse(statusBackend.StatusNode().CallInProcessRPC, inputJSON)
}

func CallGorillaRPC(inputJSON string) string {
return callGorillaRPC(inputJSON)
}

//

Check failure on line 327 in mobile/status.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (goimports)
func callGorillaRPC(inputJSON string) string {
return callWithResponse(statusBackend.StatusNode().CallInProcessGorillaRPC, inputJSON)
}

// Deprecated: Use CallRPC instead, the behaviour is the same.
func CallPrivateRPC(inputJSON string) string {
return callRPC(inputJSON)
Expand Down
53 changes: 50 additions & 3 deletions node/get_status_node.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package node

import "C"
import (
"bytes"
"context"
"database/sql"
"errors"
"fmt"
"io"
"net/http/httptest"
"os"
"path/filepath"
"reflect"
Expand All @@ -16,8 +20,12 @@

"go.uber.org/zap"

"github.com/ethereum/go-ethereum/event"

Check failure on line 23 in node/get_status_node.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (goimports)
gethrpc "github.com/ethereum/go-ethereum/rpc"
gorillarpc "github.com/gorilla/rpc/v2"
gorillajson "github.com/gorilla/rpc/v2/json"

_ "github.com/gorilla/rpc"

accsmanagement "github.com/status-im/status-go/accounts-management"
common2 "github.com/status-im/status-go/common"
Expand Down Expand Up @@ -77,8 +85,9 @@
config *params.NodeConfig // Status node configuration
rpcClient *rpc.Client // reference to an RPC client

services []common2.StatusService
rpcServer *gethrpc.Server
services []common2.StatusService
rpcServer *gethrpc.Server
gorillaRPCServer *gorillarpc.Server

downloader *ipfs.Downloader

Expand Down Expand Up @@ -128,14 +137,20 @@
// New makes new instance of StatusNode.
func New(transactor *transactions.Transactor, gethAccountsManager *accsmanagement.AccountsManager, logger *zap.Logger) *StatusNode {
logger = logger.Named("StatusNode")

gorillaRPCServer := gorillarpc.NewServer()
gorillaRPCServer.RegisterCodec(gorillajson.NewCodec(), "application/json")

return &StatusNode{
transactor: transactor,
gethAccountsManager: gethAccountsManager,
logger: logger,
publicMethods: make(map[string]bool),
accountsPublisher: pubsub.NewPublisher(),
rpcServer: gethrpc.NewServer(),
gorillaRPCServer: gorillaRPCServer,
}

}

// Config exposes reference to running node's configuration
Expand Down Expand Up @@ -339,9 +354,14 @@
}
}

err := n.gorillaRPCServer.RegisterService(n.ethSrvc.GorillaAPI(), "eth")
if err != nil {
return errorspkg.Wrap(err, "failed to register eth service")
}

// Start services

err := n.timeSourceSrvc.Start(context.Background())
err = n.timeSourceSrvc.Start(context.Background())
if err != nil {
return errorspkg.Wrap(err, "failed to start time source")
}
Expand Down Expand Up @@ -474,6 +494,33 @@
return codec.Output()
}

func (n *StatusNode) CallInProcessGorillaRPC(inputJSON string) string {
//n.gorillaRPCServer.ServeHTTP()

payloadBytes := []byte(inputJSON)

// Create a fake HTTP request
req := httptest.NewRequest("POST", "/CallInProcessGorillaRPC", bytes.NewBuffer(payloadBytes))
req.Header.Set("Content-Type", "application/json")

// Create a fake HTTP response writer
rr := httptest.NewRecorder()

// Call the server's ServeHTTP method
n.gorillaRPCServer.ServeHTTP(rr, req)

// Read and return the response body
resp := rr.Result()
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}

return string(body)
}

// RPCClient exposes reference to RPC client connected to the running node.
func (n *StatusNode) RPCClient() *rpc.Client {
n.mu.RLock()
Expand Down
30 changes: 30 additions & 0 deletions services/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import (
"context"
"fmt"
"net/http"

accounts "github.com/status-im/status-go/accounts-management"

Expand Down Expand Up @@ -29,3 +31,31 @@
err = client.CallContext(ctx, &result, "eth_estimateGas", payload)
return
}

type GorillaArgs struct {
A string `json:"a"`
}

type GorillaReply struct {
B string `json:"b"`
}

func (a *API) TestGorilla(request *http.Request, args *GorillaArgs, reply *GorillaReply) error {
reply.B = fmt.Sprintf("a: %s", args.A)
return nil
}

func (a *API) TestGorilla2(request *http.Request, args *GorillaArgs) (*GorillaReply, error) {
reply := &GorillaReply{
B: fmt.Sprintf("a: %s", args.A),
}
return reply, nil
}

func (a *API) TestPanic(request *http.Request, args *GorillaArgs, reply *GorillaReply) error {
panic("test panic")
}

func (a *API) IntendedPanic() error {
panic("intended panic")
}

Check failure on line 61 in services/eth/api.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (goimports)
4 changes: 4 additions & 0 deletions services/eth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ func (s *Service) APIs() []gethrpc.API {
},
}
}

func (s *Service) GorillaAPI() *API {
return NewAPI(s.client, s.accountsManager)
}
2 changes: 1 addition & 1 deletion tests-functional/clients/status_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def init_status_backend(self):
"apiLoggingEnabled": True,
"wakuFleetsConfigFilePath": Config.waku_fleets_config,
"pushFleetsConfigFilePath": Config.push_fleets_config,
"mediaServerAddress": f"""{"0.0.0.0" if self.container else "localhost"}:{constants.STATUS_MEDIA_SERVER_PORT}""",
"mediaServerAddress": f"""{"0.0.0.0" if self.container else "127.0.0.1"}:{constants.STATUS_MEDIA_SERVER_PORT}""",
"mediaServerAdvertizeHost": "localhost" if self.container else "",
"mediaServerAdvertizePort": self.container.media_server_port if self.container else 0,
}
Expand Down
49 changes: 49 additions & 0 deletions tests-functional/tests/test_gorilla_rpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pytest

import utils.fake as fake
from clients.signals import SignalType


@pytest.mark.rpc
@pytest.mark.ethclient
@pytest.mark.xdist_group(name="Eth")
class TestEth:
await_signals = [
SignalType.NODE_LOGIN.value,
SignalType.WALLET.value,
SignalType.WALLET_SUGGESTED_ROUTES.value,
SignalType.WALLET_ROUTER_SIGN_TRANSACTIONS.value,
SignalType.WALLET_ROUTER_SENDING_TRANSACTIONS_STARTED.value,
SignalType.WALLET_ROUTER_TRANSACTIONS_SENT.value,
]

def test_gorilla_rpc(self, backend_new_profile):
backend = backend_new_profile("sender")

testvalue = fake.profile_name()
args = {"a": testvalue}

request = {"jsonrpc": "2.0", "method": "eth.TestGorilla", "id": 1, "params": args}
reply = backend.api_request_json("CallGorillaRPC", request)
result = reply.get("result")

assert result is not None
assert result.get("b") == ("a: " + testvalue)

request = {"jsonrpc": "2.0", "method": "eth_testGorilla2", "id": 2, "params": [args]}
reply = backend.api_request_json("CallRPC", request)
result = reply.get("result")

assert result is not None
assert result.get("b") == ("a: " + testvalue)

request = {"jsonrpc": "2.0", "method": "eth_testGorilla2", "id": 3, "params": args}
reply = backend.api_request_json("CallRPC", request)
result = reply.get("result")

assert result is not None
assert result.get("b") == ("a: " + testvalue)

# request = {"jsonrpc": "2.0", "method": "eth.TestPanic", "id": 4, "params": [args]}
# reply = backend.api_request_json("CallGorillaRPC", request)
# logging.debug(f"<<< reply {reply}")
23 changes: 23 additions & 0 deletions vendor/github.com/ethereum/go-ethereum/rpc/recover.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/github.com/ethereum/go-ethereum/rpc/recover_nop.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 2 additions & 12 deletions vendor/github.com/ethereum/go-ethereum/rpc/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/gorilla/rpc/.editorconfig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/gorilla/rpc/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/github.com/gorilla/rpc/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading