Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit d04554c

Browse files
authored
Merge pull request #324 from 0xProject/v2.0.0-beta
Release V2.0.0 beta
2 parents a594359 + 0854143 commit d04554c

File tree

93 files changed

+12069
-931
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+12069
-931
lines changed

.circleci/config.yml

+13
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@ jobs:
4343
- run:
4444
name: Test installing Mesh without CGO
4545
command: CGO_ENABLED=0 go install ./...
46+
- run:
47+
name: Install TS RPC client dependencies
48+
command: cd rpc/clients/typescript && yarn install
49+
- run:
50+
name: Run TS RPC client linter
51+
command: cd rpc/clients/typescript && yarn lint
52+
- run:
53+
name: Build TS RPC client
54+
command: cd rpc/clients/typescript && yarn build
55+
- run:
56+
name: Run TS RPC client tests
57+
command: cd rpc/clients/typescript && yarn test
58+

.gitbook.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root: ./docs/
2+
3+
structure:
4+
readme: ../README.md
5+
summary: ./SUMMARY.md

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
.DS_Store
12
vendor/
23
node_modules/
34
TODO.md
45
0x_mesh/
56
examples/javascript_websocket_client/node_modules
67
examples/javascript_websocket_client/lib
8+
rpc/clients/typescript/node_modules
9+
rpc/clients/typescript/lib

Gopkg.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+4
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,7 @@
108108
[[constraint]]
109109
name = "github.com/libp2p/go-libp2p-autonat-svc"
110110
version = "0.0.6"
111+
112+
[[constraint]]
113+
name = "github.com/hashicorp/golang-lru"
114+
version = "0.5.1"

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test-all: test-go test-wasm
3333

3434
.PHONY: test-go
3535
test-go:
36-
go test ./... -race
36+
go test ./... -race -timeout 30s
3737

3838

3939
.PHONY: test-wasm
@@ -65,6 +65,10 @@ mesh-bootstrap:
6565
db-integrity-check:
6666
go install ./cmd/db-integrity-check
6767

68+
.PHONY: cut-release
69+
cut-release:
70+
go run ./cmd/cut-release/main.go
71+
6872

6973
.PHONY: all
7074
all: mesh mesh-keygen mesh-bootstrap db-integrity-check

README.md

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Version](https://img.shields.io/badge/version-1.0.6--beta-orange.svg)](https://github.com/0xProject/0x-mesh/releases)
1+
[![Version](https://img.shields.io/badge/version-2.0.0--beta-orange.svg)](https://github.com/0xProject/0x-mesh/releases)
22
[![Chat with us on Discord](https://img.shields.io/badge/chat-Discord-blueViolet.svg)](https://discord.gg/HF7fHwk)
33
[![GoDoc](https://godoc.org/github.com/0xProject/0x-mesh?status.svg)](https://godoc.org/github.com/0xProject/0x-mesh)
44
[![Circle CI](https://img.shields.io/circleci/project/0xProject/0x-mesh/master.svg)](https://circleci.com/gh/0xProject/0x-mesh/tree/master)
@@ -8,30 +8,24 @@
88
0x Mesh is a peer-to-peer network for sharing orders that adhere to the
99
[0x order message format](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#order-message-format).
1010

11-
:no_entry: WARNING: This project is still under active development. Expect breaking changes before the official release. :no_entry:
12-
13-
## Versions
14-
15-
You are looking at the documentation for version `1.0.6-beta`. To see the
16-
documentation for a different version, visit the
17-
[Releases Page](https://github.com/0xProject/0x-mesh/releases).
11+
WARNING: This project is still under active development. Expect breaking changes before the official release.
1812

1913
## Deployment
2014

21-
[The Deployment Guide](DEPLOYMENT.md)
15+
[The Deployment Guide](docs/DEPLOYMENT.md)
2216
will walk you through how to configure and deploy your own 0x Mesh node.
2317

2418
## Usage
2519

2620
Once you have deployed a 0x Mesh node, the
27-
[Usage Guide](USAGE.md)
21+
[Usage Guide](docs/USAGE.md)
2822
explains how to interact with it using the JSON-RPC API.
2923

3024
## Development
3125

3226
We love receiving contributions from the community :smile: If you are interested
3327
in helping develop 0x Mesh, please read the
34-
[Development Guide](DEVELOPMENT.md).
28+
[Development Guide](docs/DEVELOPMENT.md).
3529
If you are looking for a place to start, take a look at the
3630
[issues page](https://github.com/0xProject/0x-mesh/issues) and don't hesitate to
3731
[reach out to us on Discord](https://discord.gg/HF7fHwk).
File renamed without changes.

cmd/cut-release/main.go

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"log"
7+
"os"
8+
"os/exec"
9+
"regexp"
10+
"strings"
11+
12+
"github.com/plaid/go-envvar/envvar"
13+
)
14+
15+
type envVars struct {
16+
// Version is the new release version to use
17+
Version string `envvar:"VERSION"`
18+
}
19+
20+
func main() {
21+
env := envVars{}
22+
if err := envvar.Parse(&env); err != nil {
23+
log.Fatal(err)
24+
}
25+
26+
updateHardCodedVersions(env.Version)
27+
28+
generateTypescriptClientDocs()
29+
}
30+
31+
func generateTypescriptClientDocs() {
32+
// Run `yarn install` to make sure `TypeDoc` dep is installed
33+
cmd := exec.Command("yarn", "install", "--frozen-lockfile")
34+
cmd.Dir = "rpc/clients/typescript"
35+
stdoutStderr, err := cmd.CombinedOutput()
36+
if err != nil {
37+
log.Print(string(stdoutStderr))
38+
log.Fatal(err)
39+
}
40+
41+
// Run `yarn docs:md` to generate MD docs
42+
cmd = exec.Command("yarn", "docs:md")
43+
cmd.Dir = "rpc/clients/typescript"
44+
stdoutStderr, err = cmd.CombinedOutput()
45+
if err != nil {
46+
log.Print(string(stdoutStderr))
47+
log.Fatal(err)
48+
}
49+
50+
// Update SUMMARY.md
51+
tsClientSummaryPath := "docs/json_rpc_clients/typescript/SUMMARY.md"
52+
dat, err := ioutil.ReadFile(tsClientSummaryPath)
53+
if err != nil {
54+
log.Fatal(err)
55+
}
56+
// Modify the paths to be prefixed with `json_rpc_clients/typescript`
57+
modifiedDat := strings.Replace(string(dat), "](", "](json_rpc_clients/typescript/", -1)
58+
modifiedDat = strings.Replace(modifiedDat, "](json_rpc_clients/typescript/)", "]()", -1)
59+
finalTsClientSummary := strings.Replace(modifiedDat, "* [", " * [", -1)
60+
61+
// Replace the summary content nested under `Typescript client`
62+
mainSummaryPath := "docs/SUMMARY.md"
63+
dat, err = ioutil.ReadFile(mainSummaryPath)
64+
if err != nil {
65+
log.Fatal(err)
66+
}
67+
finalSummaryLines := []string{}
68+
lines := strings.Split(string(dat), "\n")
69+
isCutting := false
70+
for _, l := range lines {
71+
if strings.Contains(l, "<!-- END TYPEDOC GENERATED SUMMARY -->") {
72+
isCutting = false
73+
finalSummaryLines = append(finalSummaryLines, finalTsClientSummary)
74+
}
75+
if !isCutting {
76+
finalSummaryLines = append(finalSummaryLines, l)
77+
}
78+
if strings.Contains(l, "<!-- START TYPEDOC GENERATED SUMMARY -->") {
79+
isCutting = true
80+
}
81+
}
82+
finalSummary := strings.Join(finalSummaryLines, "\n")
83+
err = ioutil.WriteFile(mainSummaryPath, []byte(finalSummary), 0644)
84+
if err != nil {
85+
log.Fatal(err)
86+
}
87+
88+
// Remove the nested SUMMARY.MD file
89+
err = os.Remove(tsClientSummaryPath)
90+
if err != nil {
91+
log.Fatal(err)
92+
}
93+
}
94+
95+
// Update the version string in all files that must be updated for a new release
96+
func updateHardCodedVersions(version string) {
97+
98+
// Update `rpc/clients/typescript/package.json`
99+
tsClientPackageJSONPath := "rpc/clients/typescript/package.json"
100+
newVersionString := fmt.Sprintf(`"version": "%s"`, version)
101+
regex := `"version": "(.*)"`
102+
updateFileWithRegex(tsClientPackageJSONPath, regex, newVersionString)
103+
104+
// Update `core.go`
105+
corePath := "core/core.go"
106+
newVersionString = fmt.Sprintf(`version$1= "%s"`, version)
107+
regex = `version(.*)= "(.*)"`
108+
updateFileWithRegex(corePath, regex, newVersionString)
109+
110+
// Update badge in README.md
111+
pathToMDFilesWithBadges := []string{"README.md", "docs/USAGE.md", "docs/DEVELOPMENT.md", "docs/DEPLOYMENT.md"}
112+
doubleDashVersion := strings.Replace(version, "-", "--", -1)
113+
newSvgName := fmt.Sprintf("version-%s-orange.svg", doubleDashVersion)
114+
regex = `version-(.*)-orange.svg`
115+
for _, path := range pathToMDFilesWithBadges {
116+
updateFileWithRegex(path, regex, newSvgName)
117+
}
118+
}
119+
120+
func updateFileWithRegex(filePath string, regex string, replacement string) {
121+
dat, err := ioutil.ReadFile(filePath)
122+
if err != nil {
123+
log.Fatal(err)
124+
}
125+
126+
var re = regexp.MustCompile(regex)
127+
modifiedDat := []byte(re.ReplaceAllString(string(dat), replacement))
128+
err = ioutil.WriteFile(filePath, modifiedDat, 0644)
129+
if err != nil {
130+
log.Fatal(err)
131+
}
132+
}

cmd/mesh/main.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package main
77

88
import (
9+
"context"
10+
911
"github.com/0xProject/0x-mesh/core"
1012
"github.com/plaid/go-envvar/envvar"
1113
log "github.com/sirupsen/logrus"
@@ -39,17 +41,21 @@ func main() {
3941
if err != nil {
4042
log.WithField("error", err.Error()).Fatal("could not initialize app")
4143
}
42-
if err := app.Start(); err != nil {
43-
log.WithField("error", err.Error()).Fatal("fatal error while starting app")
44-
}
45-
defer app.Close()
44+
ctx, cancel := context.WithCancel(context.Background())
45+
defer cancel()
46+
47+
go func() {
48+
if err := app.Start(ctx); err != nil {
49+
cancel()
50+
log.WithField("error", err.Error()).Error("core app exited with error")
51+
}
52+
}()
4653

4754
// Start RPC server.
4855
go func() {
49-
err := listenRPC(app, config)
50-
if err != nil {
51-
app.Close()
52-
log.WithField("error", err.Error()).Fatal("RPC server returned error")
56+
if err := listenRPC(app, config, ctx); err != nil {
57+
cancel()
58+
log.WithField("error", err.Error()).Error("RPC server returned error")
5359
}
5460
}()
5561

cmd/mesh/rpc_handler.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type rpcHandler struct {
2525

2626
// listenRPC starts the RPC server and listens on config.RPCPort. It blocks
2727
// until there is an error or the RPC server is closed.
28-
func listenRPC(app *core.App, config standaloneConfig) error {
28+
func listenRPC(app *core.App, config standaloneConfig, ctx context.Context) error {
2929
// Initialize the JSON RPC WebSocket server (but don't start it yet).
3030
rpcAddr := fmt.Sprintf(":%d", config.RPCPort)
3131
rpcHandler := &rpcHandler{
@@ -38,11 +38,16 @@ func listenRPC(app *core.App, config standaloneConfig) error {
3838
go func() {
3939
// Wait for the server to start listening and select an address.
4040
for rpcServer.Addr() == nil {
41+
select {
42+
case <-ctx.Done():
43+
return
44+
default:
45+
}
4146
time.Sleep(10 * time.Millisecond)
4247
}
4348
log.WithField("address", rpcServer.Addr().String()).Info("started RPC server")
4449
}()
45-
return rpcServer.Listen()
50+
return rpcServer.Listen(ctx)
4651
}
4752

4853
// GetOrders is called when an RPC client calls GetOrders.
@@ -86,6 +91,17 @@ func (handler *rpcHandler) AddPeer(peerInfo peerstore.PeerInfo) error {
8691
return nil
8792
}
8893

94+
// GetStats is called when an RPC client calls GetStats,
95+
func (handler *rpcHandler) GetStats() (*rpc.GetStatsResponse, error) {
96+
log.Debug("received GetStats request via RPC")
97+
getStatsResponse, err := handler.app.GetStats()
98+
if err != nil {
99+
log.WithField("error", err.Error()).Error("internal error in GetStats RPC call")
100+
return nil, constants.ErrInternal
101+
}
102+
return getStatsResponse, nil
103+
}
104+
89105
// SubscribeToOrders is called when an RPC client sends a `mesh_subscribe` request with the `orders` topic parameter
90106
func (handler *rpcHandler) SubscribeToOrders(ctx context.Context) (*ethRpc.Subscription, error) {
91107
log.Debug("received order event subscription request via RPC")

0 commit comments

Comments
 (0)