Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add jsonrpc gateway support #1183

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9ea6e5d
feat: implement JSON-RPC for Pactus
b00f Mar 26, 2024
91214ce
fix: fix issues
b00f Mar 26, 2024
b216f54
feat: add JSON-RPC gateway support for gRPC
alidevjimmy Mar 28, 2024
e4cd41d
chore: remove extra tab in Makefile
alidevjimmy Mar 28, 2024
ada1abe
doc: updtae example_config.toml for json-rpc
alidevjimmy Mar 29, 2024
d3620e7
chore: remove handlers from json-rpc server
alidevjimmy Mar 29, 2024
45c23f8
chore: fix format and unused parameter
alidevjimmy Mar 29, 2024
edc7558
chore: remove unused Printf method
alidevjimmy Mar 29, 2024
4c83311
chore: revert go.mod
alidevjimmy Mar 29, 2024
6bb1fb1
test: fix config test
alidevjimmy Mar 29, 2024
381dbc8
feat: listen and then server for http server
alidevjimmy Mar 29, 2024
0ee6587
fix: assign listener to struct
alidevjimmy Mar 29, 2024
389e25b
chore: remove jrpc opt
alidevjimmy Mar 29, 2024
0a16db2
test: fix config test issue
b00f Mar 29, 2024
15fa879
refactor: wallet tests get refactored
b00f Mar 29, 2024
4d445ba
Merge pull request #1 from b00f/feat-add-jsonrpc-gateway-support
alidevjimmy Mar 30, 2024
75c3a06
chore: add blank line
alidevjimmy Mar 30, 2024
b91481a
Merge branch 'feat-add-jsonrpc-gateway-support' of github.com:alidevj…
alidevjimmy Mar 30, 2024
882407b
fix: remove undefined targets
alidevjimmy Mar 30, 2024
a89973c
refactor: remove enableHttpAuth flag
alidevjimmy Mar 30, 2024
dc72850
test: fix config test issue
b00f Mar 30, 2024
456b274
Merge pull request #2 from b00f/feat-add-jsonrpc-gateway-support
alidevjimmy Mar 30, 2024
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
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ devtools:
go install github.com/bufbuild/buf/cmd/buf@v1.25.0
go install mvdan.cc/gofumpt@latest
go install github.com/rakyll/statik@v0.1
go install github.com/pacviewer/jrpc-gateway/protoc-gen-jrpc-gateway@v0.1.3

########################################
### Building
build:
build:
go build -o ./build/pactus-daemon$(EXE) ./cmd/daemon
go build -o ./build/pactus-wallet$(EXE) ./cmd/wallet
go build -o ./build/pactus-shell$(EXE) ./cmd/shell
go build -o ./build/pactus-shell$(EXE) ./cmd/shell


build_race:
go build -race -o ./build/pactus-daemon$(EXE) ./cmd/daemon
Expand Down
12 changes: 12 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"github.com/pactus-project/pactus/util/logger"
"github.com/pactus-project/pactus/www/grpc"
"github.com/pactus-project/pactus/www/http"
"github.com/pactus-project/pactus/www/jsonrpc"
"github.com/pactus-project/pactus/www/nanomsg"
"github.com/pelletier/go-toml"
)
Expand All @@ -38,6 +39,7 @@
Consensus *consensus.Config `toml:"-"`
Logger *logger.Config `toml:"logger"`
GRPC *grpc.Config `toml:"grpc"`
JSONRPC *jsonrpc.Config `toml:"jsonrpc"`
HTTP *http.Config `toml:"http"`
Nanomsg *nanomsg.Config `toml:"nanomsg"`
}
Expand Down Expand Up @@ -89,6 +91,7 @@
Consensus: consensus.DefaultConfig(),
Logger: logger.DefaultConfig(),
GRPC: grpc.DefaultConfig(),
JSONRPC: jsonrpc.DefaultConfig(),
HTTP: http.DefaultConfig(),
Nanomsg: nanomsg.DefaultConfig(),
}
Expand Down Expand Up @@ -119,6 +122,8 @@
conf.GRPC.BasicAuthCredential = ""
conf.GRPC.Gateway.Enable = false
conf.GRPC.Gateway.Listen = "127.0.0.1:8080"
conf.JSONRPC.Enable = false
b00f marked this conversation as resolved.
Show resolved Hide resolved
conf.JSONRPC.Listen = "127.0.0.1:8545"
conf.HTTP.Enable = false
conf.HTTP.Listen = "127.0.0.1:80"
conf.Nanomsg.Enable = false
Expand All @@ -145,6 +150,8 @@
conf.GRPC.Listen = "[::]:50052"
conf.GRPC.Gateway.Enable = true
conf.GRPC.Gateway.Listen = "[::]:8080"
conf.JSONRPC.Enable = false
conf.JSONRPC.Listen = "127.0.0.1:8545"
conf.HTTP.Enable = false
conf.HTTP.Listen = "[::]:80"
conf.Nanomsg.Enable = false
Expand All @@ -170,6 +177,8 @@
conf.GRPC.Listen = "[::]:50052"
conf.GRPC.Gateway.Enable = true
conf.GRPC.Gateway.Listen = "[::]:8080"
conf.JSONRPC.Enable = true
conf.JSONRPC.Listen = "127.0.0.1:8545"
conf.HTTP.Enable = true
conf.HTTP.Listen = "[::]:0"
conf.Nanomsg.Enable = true
Expand Down Expand Up @@ -243,6 +252,9 @@
if err := conf.Nanomsg.BasicCheck(); err != nil {
return err
}
if err := conf.JSONRPC.BasicCheck(); err != nil {
return err

Check warning on line 256 in config/config.go

View check run for this annotation

Codecov / codecov/patch

config/config.go#L256

Added line #L256 was not covered by tests
}

return conf.HTTP.BasicCheck()
}
12 changes: 11 additions & 1 deletion config/example_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,24 @@
# Default is `false`.
## enable_cors = false

# `jsonrpc` configuration.
[jsonrpc]

# `enable` indicates whether JSON-RPC service should be enabled or not.
# Default is `false`.
## enable = false

# `listen` is the address to listen for incoming connections for JSON-RPC server.
b00f marked this conversation as resolved.
Show resolved Hide resolved
## listen = "127.0.0.1:8545"

# `http` configuration.
[http]

# `enable` indicates whether HTTP service should be enabled or not.
# Default is `false`.
## enable = false

# `listen` is the address address to listen for incoming connections for HTTP server.
# `listen` is the address to listen for incoming connections for HTTP server.
## listen = "127.0.0.1:80"

# Nanomsg configuration.
Expand Down
23 changes: 13 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/NathanBaulch/protoc-gen-cobra v1.2.1
github.com/fxamacker/cbor/v2 v2.5.0
github.com/gofrs/flock v0.8.1
github.com/google/uuid v1.4.0
github.com/google/uuid v1.6.0
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/gotk3/gotk3 v0.6.2
Expand All @@ -24,13 +24,14 @@ require (
github.com/rakyll/statik v0.1.7
github.com/rs/zerolog v1.30.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tyler-smith/go-bip39 v1.1.0
go.nanomsg.org/mangos/v3 v3.4.2
golang.org/x/crypto v0.17.0
golang.org/x/crypto v0.18.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
google.golang.org/grpc v1.58.3
google.golang.org/grpc v1.62.1
google.golang.org/protobuf v1.33.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)
Expand All @@ -43,6 +44,8 @@ require (
github.com/chzyer/readline v1.5.1 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/creachadair/jrpc2 v1.1.2 // indirect
github.com/creachadair/mds v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
Expand All @@ -56,7 +59,7 @@ require (
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a // indirect
Expand Down Expand Up @@ -114,6 +117,7 @@ require (
github.com/onsi/ginkgo/v2 v2.13.1 // indirect
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pacviewer/jrpc-gateway v0.1.3 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
Expand All @@ -127,7 +131,6 @@ require (
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.opencensus.io v0.24.0 // indirect
Expand All @@ -140,14 +143,14 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.15.0 // indirect
gonum.org/v1/gonum v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230911183012-2d3300fd4832 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230911183012-2d3300fd4832 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
)
Loading
Loading