Skip to content

Commit b8ef2ba

Browse files
committed
Initial layout
0 parents  commit b8ef2ba

File tree

10 files changed

+1194
-0
lines changed

10 files changed

+1194
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2017 Project Wyvern Developers
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
![Project Wyvern Logo](https://media.githubusercontent.com/media/ProjectWyvern/wyvern-branding/master/logo/logo-square-red-transparent-200x200.png?raw=true "Project Wyvern Logo")
2+
3+
## Example Wyvern Protocol Orderbook Server
4+
5+
[![https://badges.frapsoft.com/os/mit/mit.svg?v=102](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://opensource.org/licenses/MIT)
6+
7+
### Synopsis
8+
9+
Example orderbook server for use with the Wyvern Protocol.
10+
11+
Three-layer architecture: Varnish cache up front, Express for HTTP, PostgreSQL as the backing datastore. The Varnish cache layer is optional.
12+
13+
### Development Information
14+
15+
Install [Yarn](https://yarnpkg.com) and fetch dependencies:
16+
17+
```
18+
yarn
19+
```
20+
21+
#### Contributing
22+
23+
Contributions welcome! Please use GitHub issues for suggestions/concerns - if you prefer to express your intentions in code, feel free to submit a pull request.

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const server = require('./server/index.js')
2+
3+
server.go({
4+
port: 8080
5+
})

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "example-orderbook-server",
3+
"version": "0.1.0",
4+
"description": "Example Wyvern Protocol orderbook server.",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "test"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/ProjectWyvern/example-orderbook-server.git"
12+
},
13+
"keywords": [
14+
"Project Wyvern",
15+
"Ethereum",
16+
"Smart Contracts"
17+
],
18+
"author": "Project Wyvern Developers",
19+
"license": "MIT",
20+
"bugs": {
21+
"url": "https://github.com/ProjectWyvern/example-orderbook-server/issues"
22+
},
23+
"homepage": "https://github.com/ProjectWyvern/example-orderbook-server#readme",
24+
"dependencies": {
25+
"body-parser": "^1.18.2",
26+
"bunyan": "^1.8.12",
27+
"express": "^4.16.2",
28+
"sequelize": "^4.31.2",
29+
"sqlite3": "^3.1.13"
30+
}
31+
}

run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
while true; do
4+
node index.js | bunyan -o short
5+
sleep 1
6+
done

server/db.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const Sequelize = require('sequelize')
2+
3+
const log = require('./logging.js')
4+
5+
const sequelize = new Sequelize('wyvernOrderbook', null, null, {
6+
host: 'localhost',
7+
dialect: 'sqlite',
8+
storage: './db.sqlite',
9+
pool: {max: 10, min: 0, acquire: 30000, idle: 10000},
10+
operatorsAliases: false,
11+
logging: (msg) => log.debug({origin: 'sequelize'}, msg)
12+
})
13+
14+
const Order = sequelize.define('order', {
15+
})
16+
17+
module.exports = {
18+
sequelize: sequelize,
19+
Order: Order
20+
}

server/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const express = require('express')
2+
const bodyParser = require('body-parser')
3+
4+
const { sequelize } = require('./db.js')
5+
const log = require('./logging.js')
6+
7+
const app = express()
8+
app.use(bodyParser.json())
9+
app.use((req, res, next) => {
10+
log.debug({path: req.path, method: req.method, ip: req.headers['X-Forwarded-For']}, 'Request received')
11+
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
12+
next()
13+
})
14+
15+
const go = ({ port }) => {
16+
sequelize
17+
.sync()
18+
.then(() => {
19+
app.listen(port, () => {
20+
log.debug({port: port}, 'Server started')
21+
})
22+
})
23+
}
24+
25+
module.exports = {
26+
go: go
27+
}

server/logging.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const bunyan = require('bunyan')
2+
3+
const log = bunyan.createLogger({name: 'server', level: 'debug'})
4+
5+
module.exports = log

0 commit comments

Comments
 (0)