parent
56b1067f73
commit
8432618b3d
File diff suppressed because one or more lines are too long
@ -0,0 +1,59 @@ |
||||
var remixLib = require('remix-lib') |
||||
|
||||
var EventManager = remixLib.EventManager |
||||
var executionContext = remixLib.execution.executionContext |
||||
var Web3Providers = remixLib.vm.Web3Providers |
||||
var DummyProvider = remixLib.vm.DummyProvider |
||||
var init = remixLib.init |
||||
|
||||
class ContextManager { |
||||
constructor () { |
||||
this.executionContext = executionContext |
||||
this.web3 = this.executionContext.web3() |
||||
this.event = new EventManager() |
||||
} |
||||
|
||||
initProviders () { |
||||
this.web3Providers = new Web3Providers() |
||||
this.addProvider('DUMMYWEB3', new DummyProvider()) |
||||
this.switchProvider('DUMMYWEB3') |
||||
|
||||
this.addProvider('vm', this.executionContext.vm()) |
||||
this.addProvider('injected', this.executionContext.internalWeb3()) |
||||
this.addProvider('web3', this.executionContext.internalWeb3()) |
||||
this.switchProvider(this.executionContext.getProvider()) |
||||
} |
||||
|
||||
getWeb3 () { |
||||
return this.web3 |
||||
} |
||||
|
||||
addProvider (type, obj) { |
||||
this.web3Providers.addProvider(type, obj) |
||||
this.event.trigger('providerAdded', [type]) |
||||
} |
||||
|
||||
switchProvider (type) { |
||||
var self = this |
||||
this.web3Providers.get(type, function (error, obj) { |
||||
if (error) { |
||||
console.log('provider ' + type + ' not defined') |
||||
} else { |
||||
self.web3 = obj |
||||
self.executionContext.detectNetwork((error, network) => { |
||||
if (error || !network) { |
||||
self.web3 = obj |
||||
} else { |
||||
var webDebugNode = init.web3DebugNode(network.name) |
||||
self.web3 = (!webDebugNode ? obj : webDebugNode) |
||||
} |
||||
self.event.trigger('providerChanged', [type, self.web3]) |
||||
}) |
||||
self.event.trigger('providerChanged', [type, self.web3]) |
||||
} |
||||
}) |
||||
} |
||||
|
||||
} |
||||
|
||||
module.exports = ContextManager |
@ -0,0 +1,87 @@ |
||||
|
||||
// options
|
||||
// * executionContext
|
||||
// * offsetToLineColumnConverter
|
||||
// *** disable for now
|
||||
// * compiler
|
||||
// ** lastCompilationResult
|
||||
|
||||
var remixLib = require('remix-lib') |
||||
//var executionContext = remixLib.execution.executionContext
|
||||
|
||||
var Debugger = require('./src/debugger/debugger.js') |
||||
|
||||
var compilation = { |
||||
} |
||||
|
||||
compilation.lastCompilationResult = require('./compilation.json') |
||||
|
||||
// connecting to a node
|
||||
// var Web3 = require('web3')
|
||||
// web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
|
||||
// global.my_web3 = web3
|
||||
|
||||
// with vm
|
||||
var ContextManager = require('./contextManager.js') |
||||
var contextManager = new ContextManager() |
||||
|
||||
_debugger = new Debugger({ |
||||
//web3: web3,
|
||||
web3: contextManager.getWeb3(), |
||||
//executionContext: executionContext,
|
||||
//offsetToLineColumnConverter: this.registry.get('offsettolinecolumnconverter').api,
|
||||
compiler: compilation |
||||
}) |
||||
|
||||
// with vm
|
||||
contextManager.initProviders() |
||||
contextManager.event.register('providerChanged', () => { |
||||
_debugger.updateWeb3(contextManager.getWeb3()) |
||||
}) |
||||
|
||||
contextManager.switchProvider('vm') |
||||
|
||||
_debugger.event.register('debuggerStatus', function (isActive) { |
||||
console.dir("debugger status") |
||||
console.dir(isActive) |
||||
}); |
||||
|
||||
_debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) { |
||||
console.dir("newSourceLocation") |
||||
}); |
||||
|
||||
_debugger.event.register('debuggerUnloaded', function() { |
||||
console.dir("debugger unloaded") |
||||
}); |
||||
|
||||
let _web3 = _debugger.debugger.web3 |
||||
// let web3 = _debugger.debugger.executionContext.web3()
|
||||
|
||||
|
||||
|
||||
let blockNumber = null |
||||
let txNumber = null |
||||
let tx = null |
||||
|
||||
// let code = compilation.lastCompilationResult.data.contracts['browser/ballot.sol'].Ballot.evm.bytecode.object
|
||||
// _web3.eth.sendTransaction({data: "0x" + code, from: _web3.eth.accounts[0], gas: 800000}, (err, txHash) => {
|
||||
// console.dir(err)
|
||||
// console.dir(txHash)
|
||||
//
|
||||
// txNumber = txHash
|
||||
//
|
||||
// _debugger.debug(blockNumber, txNumber, tx, () => {
|
||||
// console.dir('debugger started')
|
||||
// })
|
||||
//
|
||||
// })
|
||||
|
||||
//_debugger.debug(blockNumber, txNumber, tx, () => {
|
||||
// console.dir('debugger started')
|
||||
//})
|
||||
|
||||
//_debugger.debugger.web3.eth.accounts()
|
||||
|
||||
console.dir("done!") |
||||
|
||||
module.exports = _debugger |
Loading…
Reference in new issue