Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
Add relay service
Browse files Browse the repository at this point in the history
  • Loading branch information
amiromayer committed Dec 9, 2019
1 parent c98e931 commit 3a15aa3
Show file tree
Hide file tree
Showing 16 changed files with 4,907 additions and 96 deletions.
5 changes: 0 additions & 5 deletions .babelrc

This file was deleted.

3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@babel/preset-env']
}
5 changes: 0 additions & 5 deletions index.js

This file was deleted.

8 changes: 8 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"packages": [
"packages/*"
],
"version": "0.0.0",
"npmClient": "yarn",
"useWorkspaces": true
}
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
{
"name": "linkdrop-sdk",
"name": "@linkdrop/binance",
"version": "1.0.0",
"description": "Linkdrop SDK",
"description": "Linkdrop Binance Monorepo",
"main": "index.js",
"repository": "https://github.com/LinkdropProtocol/linkdrop-sdk",
"author": "Amir Jumaniyazov <[email protected]>",
"license": "MIT",
"dependencies": {
"@binance-chain/javascript-sdk": "https://github.com/Dobrokhvalov/javascript-sdk",
"axios": "^0.19.0",
"ethers": "^4.0.31"
"private": true,
"workspaces": {
"packages": [
"packages/*"
]
},
"scripts": {
"server": "npx babel-node packages/server/index"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/node": "^7.4.5",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@babel/register": "^7.4.4"
"@babel/register": "^7.4.4",
"lerna": "^3.16.4"
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions binance/index.js → packages/sdk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const signLinkParams = async ({ privateKey, asset, amount, linkId }) => {
)
let message = ethers.utils.arrayify(hash)

return await signer.signMessage(message)
return signer.signMessage(message)
}

/**
Expand All @@ -55,7 +55,7 @@ const signReceiverAddress = async ({ privateKey, receiverAddress }) => {
const signer = new ethers.Wallet(privateKey)
const hash = ethers.utils.solidityKeccak256(['string'], [receiverAddress])
const message = ethers.utils.arrayify(hash)
return await signer.signMessage(message)
return signer.signMessage(message)
}

/**
Expand Down
25 changes: 25 additions & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@linkdrop/binance-sdk",
"version": "1.0.0",
"description": "Linkdrop Binance SDK",
"main": "index.js",
"repository": "https://github.com/LinkdropProtocol/linkdrop-sdk",
"author": "Amir Jumaniyazov <[email protected]>",
"license": "MIT",
"dependencies": {
"@binance-chain/javascript-sdk": "https://github.com/Dobrokhvalov/javascript-sdk",
"axios": "^0.19.0",
"ethers": "^4.0.31"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/node": "^7.4.5",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@babel/register": "^7.4.4"
},
"babel": {
"extends": "../../babel.config.js"
}
}
28 changes: 14 additions & 14 deletions binance/utils/index.js → packages/sdk/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const axios = require('axios')
const BncClient = require('@binance-chain/javascript-sdk')
const { crypto } = BncClient

const apiHost = 'https://dex.binance.org'
const prefix = 'bnb'
const network = 'mainnet'
const transferFee = 37500
const API_HOST = 'https://dex.binance.org'
const PREFIX = 'bnb'
const NETWORK = 'mainnet'
const TRANSFER_FEE = 37500

/**
* @dev Function to retrieve balance of a given address
Expand All @@ -19,7 +19,7 @@ const getBalance = async ({ address, asset }) => {
throw new Error('Please provide valid address')
}

const result = await axios.get(`${apiHost}/api/v1/account/${address}`)
const result = await axios.get(`${API_HOST}/api/v1/account/${address}`)
const balances = result.data.balances

const balance = balances.find(
Expand Down Expand Up @@ -48,15 +48,15 @@ const getBalance = async ({ address, asset }) => {
* @return {String} Address corresponding to `privateKey`
*/
const getAddressFromPrivateKey = privateKey =>
crypto.getAddressFromPrivateKey(privateKey, prefix)
crypto.getAddressFromPrivateKey(privateKey, PREFIX)

/**
* @dev Returns a sequence for a given address
* @param {String} address
* @return {Number} Sequence
*/
const getSequence = async address => {
const url = `${apiHost}/api/v1/account/${address}/sequence`
const url = `${API_HOST}/api/v1/account/${address}/sequence`
const sequence = (await axios.get(url)).data.sequence || 0
return Number(sequence)
}
Expand Down Expand Up @@ -85,7 +85,7 @@ const formatUnits = value => {
* @return {Promise<Object>} Transaction metadata
*/
const getTransaction = async hash => {
const url = `${apiHost()}/api/v1/tx/${hash}?format=json`
const url = `${API_HOST()}/api/v1/tx/${hash}?format=json`
return (await axios.get(url)).data
}

Expand All @@ -95,8 +95,8 @@ const getTransaction = async hash => {
* @return {Object} Binance chain client
*/
const initBncClient = async privateKey => {
const bncClient = new BncClient(apiHost)
await bncClient.chooseNetwork(network)
const bncClient = new BncClient(API_HOST)
await bncClient.chooseNetwork(NETWORK)
await bncClient.setPrivateKey(privateKey)
await bncClient.initChain()
return bncClient
Expand All @@ -118,9 +118,9 @@ module.exports = {
parseUnits,
getSequence,
getAddressFromPrivateKey,
apiHost,
prefix,
network,
transferFee,
API_HOST,
PREFIX,
NETWORK,
TRANSFER_FEE,
getPrivateKeyFromMnemonic
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import ClaimTx from '../models/ClaimTx'
import { wrapAsync } from '../utils'
import sdk from '@linkdrop/binance-sdk'
import Table from 'cli-table'

const config = require('../../config/config.json')
import config from '../../config/config.json'

/**
* Function to check whether a `linkId` has already been claimed
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/server/api/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import wrapAsync from './wrapAsync'
export { wrapAsync }
13 changes: 13 additions & 0 deletions packages/server/api/utils/wrapAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import boom from '@hapi/boom'

export default fn => (req, res, next) => {
fn(req, res, next).catch(err => {
if (!err.isBoom) {
if (err.name === 'CastError' || err.kind === 'ObjectId') {
return next(boom.notFound('No valid entry found'))
}
return next(boom.badImplementation(err))
}
next(err)
})
}
6 changes: 3 additions & 3 deletions server/index.js → packages/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import express from 'express'
import morgan from 'morgan'
import mongoose from 'mongoose'
import boom from '@hapi/boom'
import claimController from './api/controllers/claim.controller'
import claimController from './api/controllers/claim'

require('dotenv').config()

const app = express()
const PORT = process.env.PORT || 5050
const PORT = process.env.PORT || 5000
const MONGODB_URI =
process.env.MONGODB_URI || 'mongodb://localhost:27017/linkdrop-binance'

Expand All @@ -20,7 +20,7 @@ app.use(morgan('dev'))
mongoose
.connect(
MONGODB_URI,
{ useNewUrlParser: true, useFindAndModify: false }
{ useNewUrlParser: true, useFindAndModify: false, useUnifiedTopology: true }
)
.then(() => {
console.log('Connected to database at', MONGODB_URI)
Expand Down
8 changes: 7 additions & 1 deletion server/package.json → packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"author": "Amir Jumaniyazov - <[email protected]>",
"license": "MIT",
"private": true,
"scripts": {
"start": "npx babel-node index"
},
"dependencies": {
"@binance-chain/javascript-sdk": "https://github.com/Dobrokhvalov/javascript-sdk",
"@hapi/boom": "^7.4.2",
Expand All @@ -29,6 +32,9 @@
"@babel/node": "^7.4.5",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@babel/register": "^7.4.4",
"@babel/register": "^7.4.4"
},
"babel": {
"extends": "../../babel.config.js"
}
}
Loading

0 comments on commit 3a15aa3

Please sign in to comment.