You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.3 KiB
76 lines
2.3 KiB
5 years ago
|
const RemixLib = require('remix-lib')
|
||
|
const executionContext = RemixLib.execution.executionContext
|
||
6 years ago
|
|
||
7 years ago
|
const log = require('./utils/logs.js')
|
||
7 years ago
|
const merge = require('merge')
|
||
|
|
||
7 years ago
|
const Accounts = require('./methods/accounts.js')
|
||
|
const Blocks = require('./methods/blocks.js')
|
||
6 years ago
|
const Filters = require('./methods/filters.js')
|
||
7 years ago
|
const Misc = require('./methods/misc.js')
|
||
7 years ago
|
const Net = require('./methods/net.js')
|
||
7 years ago
|
const Transactions = require('./methods/transactions.js')
|
||
7 years ago
|
|
||
6 years ago
|
const generateBlock = require('./genesis.js')
|
||
|
|
||
6 years ago
|
var Provider = function (options) {
|
||
5 years ago
|
this.options = options || {}
|
||
5 years ago
|
// TODO: init executionContext here
|
||
|
this.executionContext = executionContext
|
||
5 years ago
|
this.Accounts = new Accounts(this.executionContext)
|
||
5 years ago
|
this.Transactions = new Transactions(this.executionContext)
|
||
7 years ago
|
|
||
7 years ago
|
this.methods = {}
|
||
7 years ago
|
this.methods = merge(this.methods, this.Accounts.methods())
|
||
5 years ago
|
this.methods = merge(this.methods, (new Blocks(this.executionContext, options)).methods())
|
||
7 years ago
|
this.methods = merge(this.methods, (new Misc()).methods())
|
||
5 years ago
|
this.methods = merge(this.methods, (new Filters(this.executionContext)).methods())
|
||
7 years ago
|
this.methods = merge(this.methods, (new Net()).methods())
|
||
5 years ago
|
this.methods = merge(this.methods, this.Transactions.methods())
|
||
6 years ago
|
|
||
5 years ago
|
generateBlock(this.executionContext)
|
||
5 years ago
|
this.init()
|
||
7 years ago
|
}
|
||
|
|
||
6 years ago
|
Provider.prototype.init = async function () {
|
||
|
await this.Accounts.init()
|
||
|
this.Transactions.init(this.Accounts.accounts)
|
||
|
}
|
||
|
|
||
7 years ago
|
Provider.prototype.sendAsync = function (payload, callback) {
|
||
7 years ago
|
log.info('payload method is ', payload.method)
|
||
7 years ago
|
|
||
5 years ago
|
const method = this.methods[payload.method]
|
||
5 years ago
|
if (this.options.logDetails) {
|
||
|
log.info(payload)
|
||
|
}
|
||
7 years ago
|
if (method) {
|
||
|
return method.call(method, payload, (err, result) => {
|
||
5 years ago
|
if (this.options.logDetails) {
|
||
|
log.info(err)
|
||
|
log.info(result)
|
||
|
}
|
||
7 years ago
|
if (err) {
|
||
7 years ago
|
return callback(err)
|
||
7 years ago
|
}
|
||
5 years ago
|
const response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result}
|
||
7 years ago
|
callback(null, response)
|
||
|
})
|
||
7 years ago
|
}
|
||
7 years ago
|
callback(new Error('unknown method ' + payload.method))
|
||
7 years ago
|
}
|
||
|
|
||
6 years ago
|
Provider.prototype.send = function (payload, callback) {
|
||
|
this.sendAsync(payload, callback || function () {})
|
||
6 years ago
|
}
|
||
|
|
||
7 years ago
|
Provider.prototype.isConnected = function () {
|
||
|
return true
|
||
|
}
|
||
|
|
||
6 years ago
|
Provider.prototype.on = function (type, cb) {
|
||
5 years ago
|
this.executionContext.logsManager.addListener(type, cb)
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
module.exports = Provider
|