UNPKG

@ocap/statedb-memory

Version:

OCAP statedb adapter that uses memory as backend statedb, just for test purpose

41 lines (34 loc) 1.64 kB
const { StateDB } = require('@ocap/statedb'); const Table = require('./table/base'); const Account = require('./table/account'); const Token = require('./table/token'); const Rollup = require('./table/rollup'); const Balance = require('./table/balance'); const { name, version } = require('../package.json'); class MemoryStateDB extends StateDB { constructor() { super(); this.name = name; this.version = version; this.balance = new Balance({ name: 'balance', uniqIndex: ['address', 'tokenAddress'] }); this.account = new Account({ name: 'account', uniqIndex: 'address', balanceTable: this.balance, syncBalance: true, }); this.factory = new Table({ name: 'factory', uniqIndex: 'address', syncBalance: true, balanceTable: this.balance }); this.stake = new Table({ name: 'stake', uniqIndex: 'address', syncBalance: true, balanceTable: this.balance }); this.asset = new Table({ name: 'asset', uniqIndex: 'address' }); this.delegation = new Table({ name: 'delegation', uniqIndex: 'address' }); this.tx = new Table({ name: 'tx', uniqIndex: 'hash' }); this.token = new Token({ name: 'token', uniqIndex: 'address' }); this.chain = new Table({ name: 'chain', uniqIndex: 'address' }); this.rollup = new Rollup({ name: 'rollup', uniqIndex: 'address' }); this.rollupBlock = new Table({ name: 'rollupBlock', uniqIndex: 'hash' }); this.evidence = new Table({ name: 'evidence', uniqIndex: 'hash' }); this.tokenFactory = new Table({ name: 'tokenFactory', uniqIndex: 'address' }); this.attachReadyListeners(); } } module.exports = MemoryStateDB;