dbet-channels-backend
v0.1.1
Published
Module conforming to Decent.bet state channel protocol specs used to manage state channels for slots running on Decent.bet
Maintainers
Readme
Decent.bet channels backend module
Module used to manage state channels on the backend for slots running on the Decent.bet platform.
Requirements
- node.js
- redis
- mongodb
- Running Vechain Thor node
Prerequisites
To run the games API you will need to have the following setup
- A running redis instance
- A running MongoDB instance
- A running Vechain Thor node
Usage
const {
SlotsChannelHandler,
SlotsValidator
} = require('dbet-channels-backend')
const Web3 = require('web3')
const {thorify} = require('thorify')
const web3 = thorify(new Web3(), 'http://localhost:8669')
const mongodb = require('mongodb')
const MongoClient = mongodb.MongoClient
const redis = require('ioredis')
const db = await initDb()
const redisClient = await initRedisClient()
// Initialize config variables
const config = {
privateKey: '',
channelTx: {
expiration: 32,
gas: 1000000,
nonce: 11111111
}
}
const slotsChannelHandler = new SlotsChannelHandler({
web3,
db,
redisClient,
config
})
const slotsValidator = new SlotsValidator({
web3,
db,
config
})
try {
slotsChannelHandler.watchEvents()
slotsChannelHandler.watchPastEvents()
slotsChannelHandler.watchExpiredChannels()
await slotsValidator.initChannel(data)
await slotsHandler.initChannel(
initialDeposit,
channelNonce,
initialUserNumber,
finalUserHash,
userTxs,
blockRef,
blockNumber,
address
)
} catch (e) {
console.error(`Received error: ${e.message}, ${e.stack}`)
}Tests
Deploy test contracts to testnet and copy contract JSONs to ./build/contracts.
To run tests run npm test. For module specific tests:
npm run test-slots-channel-handlerfor SlotsChannelHandlernpm run test-slots-validatorfor SlotsValidator
