UNPKG

2.98 kBJavaScriptView Raw
1// TODO: this file shoudl be removed at some point
2var CmdLine = require('./src/cmdline/index.js')
3// var compilation = require('./compilation.json')
4
5var solc = require('solc')
6var fs = require('fs')
7
8var filename = 'test/sol/simple_storage.sol'
9var shortFilename = 'simple_storage.sol'
10
11var inputJson = {
12 language: 'Solidity',
13 sources: {
14 },
15 settings: {
16 optimizer: {
17 enabled: true,
18 runs: 200
19 },
20 outputSelection: {
21 '*': {
22 '': [ 'legacyAST' ],
23 '*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ]
24 }
25 }
26 }
27}
28
29inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString()}
30
31console.dir(inputJson)
32
33console.log('compiling...')
34
35let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson)))
36console.dir(Object.keys(compilationData))
37var compilation = {}
38compilation.data = compilationData
39compilation.source = { sources: inputJson.sources }
40console.dir(compilation)
41console.dir(compilation.data.errors)
42
43var cmdLine = new CmdLine()
44cmdLine.connect('http', 'http://localhost:8545')
45cmdLine.loadCompilationResult(compilation)
46cmdLine.initDebugger()
47
48// var deployContract = function (cb) {
49// let _web3 = cmdLine.debugger.debugger.web3
50//
51// let blockNumber = null
52// let txNumber = null
53// let tx = null
54//
55// let code = compilation.data.contracts[shortFilename].SimpleStorage.evm.bytecode.object
56// console.dir('deploying...')
57// console.dir(code)
58// _web3.eth.sendTransaction({data: '0x' + code, from: _web3.eth.accounts[0], gas: 800000}, cb)
59// }
60
61// let _web3 = cmdLine.debugger.debugger.web3
62var tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa'
63
64// deployContract((err, tx) => {
65cmdLine.startDebug(tx, shortFilename)
66
67cmdLine.events.on('source', () => {
68 cmdLine.getSource().forEach(console.dir)
69})
70 // })
71// })
72
73const repl = require('repl')
74
75repl.start({
76 prompt: '> ',
77 eval: (cmd, context, filename, cb) => {
78 let command = cmd.trim()
79 if (command === 'next' || command === 'n') {
80 cmdLine.stepOverForward(true)
81 }
82 if (command === 'previous' || command === 'p' || command === 'prev') {
83 cmdLine.stepOverBack(true)
84 }
85 if (command === 'step' || command === 's') {
86 cmdLine.stepIntoForward(true)
87 }
88 if (command === 'stepback' || command === 'sb') {
89 cmdLine.stepIntoBack(true)
90 }
91 if (command === 'exit' || command === 'quit') {
92 process.exit(0)
93 }
94 if (command === 'var local' || command === 'v l' || command === 'vl') {
95 cmdLine.displayLocals()
96 }
97 if (command === 'var global' || command === 'v g' || command === 'vg') {
98 cmdLine.displayGlobals()
99 }
100 if (command.split(' ')[0] === 'jump') {
101 let stepIndex = parseInt(command.split(' ')[1], 10)
102 cmdLine.jumpTo(stepIndex)
103 }
104 cb(null, '')
105 }
106})
107
108module.exports = cmdLine
109