From 3d2dbb461fb88bb616f9401ad59ec511cae039d1 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 16 Oct 2018 12:37:34 -0400 Subject: [PATCH] update lib; remove various console logs --- remix-debug/index.js | 4 +- remix-debug/package.json | 4 ++ remix-debug/rdb.js | 66 +++++++++++++++++-- remix-debug/src/cmdline/contextManager.js | 2 +- remix-debug/src/cmdline/index.js | 2 +- remix-debug/src/debugger/VmDebugger.js | 10 +-- .../src/solidity-decoder/internalCallTree.js | 1 - remix-debug/test/sol/ballot.sol | 65 ++++++++++++++++++ remix-debug/test/sol/simple_storage.sol | 22 +++++++ remix-lib/src/code/codeResolver.js | 1 - 10 files changed, 162 insertions(+), 15 deletions(-) create mode 100644 remix-debug/test/sol/ballot.sol create mode 100644 remix-debug/test/sol/simple_storage.sol diff --git a/remix-debug/index.js b/remix-debug/index.js index 3ea8d98482..6c90d8fb0c 100644 --- a/remix-debug/index.js +++ b/remix-debug/index.js @@ -1,6 +1,7 @@ 'use strict' var EthDebugger = require('./src/Ethdebugger') var TransactionDebugger = require('./src/debugger/debugger') +var CmdLine = require('./src/cmdline') var StorageViewer = require('./src/storage/storageViewer') var StorageResolver = require('./src/storage/storageResolver') @@ -32,6 +33,7 @@ module.exports = { storage: { StorageViewer: StorageViewer, StorageResolver: StorageResolver - } + }, + CmdLine: CmdLine } diff --git a/remix-debug/package.json b/remix-debug/package.json index 097640ec00..3e7c3de0b2 100644 --- a/remix-debug/package.json +++ b/remix-debug/package.json @@ -10,6 +10,10 @@ { "name": "Liana Husikyan", "email": "liana@ethdev.com" + }, + { + "name": "Iuri Matias", + "email": "iuri.matias@gmail.com" } ], "main": "./index.js", diff --git a/remix-debug/rdb.js b/remix-debug/rdb.js index 3eb2bf55af..d0b14be406 100644 --- a/remix-debug/rdb.js +++ b/remix-debug/rdb.js @@ -1,7 +1,46 @@ var CmdLine = require('./src/cmdline/index.js') - var compilation = require('./compilation.json') +var solc = require('solc') +var fs = require('fs') + +//var filename = 'test/sol/ballot.sol' +var filename = 'test/sol/simple_storage.sol' +//var filename = 'browser/ballot.sol' + +var input_json = { + language: 'Solidity', + sources: { + //"test/sol/ballot.sol": {content: fs.readFileSync('test/sol/ballot.sol').toString()} + }, + settings: { + optimizer: { + enabled: true, + runs: 200 + }, + outputSelection: { + '*': { + '': [ 'legacyAST' ], + '*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ] + } + } + } +} + +input_json.sources[filename] = {content: fs.readFileSync(filename).toString()} + +console.dir(input_json) + +console.log("compiling...") + +let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(input_json))) +console.dir(Object.keys(compilationData)) +var compilation = {} +compilation.data = compilationData +compilation.source = { sources: input_json.sources } +console.dir(compilation) +console.dir(compilation.data.errors) + var cmd_line = new CmdLine() cmd_line.connect("http", "http://localhost:8545") cmd_line.loadCompilationResult(compilation) @@ -14,13 +53,27 @@ var deployContract = function (cb) { let txNumber = null let tx = null - let code = compilation.data.contracts['browser/ballot.sol'].Ballot.evm.bytecode.object + let code = compilation.data.contracts[filename].SimpleStorage.evm.bytecode.object + console.dir("deploying...") + console.dir(code) _web3.eth.sendTransaction({data: "0x" + code, from: _web3.eth.accounts[0], gas: 800000}, cb) } -deployContract((err, tx) => { - cmd_line.startDebug(tx, "browser/ballot.sol") -}) +let _web3 = cmd_line.debugger.debugger.web3 +// var tx = "0x8c44e1b6bcb557512184f851502e43160f415e2e12b2b98ba12b96b699b85859" +// var tx = "0xae365458de8c6669eb146ce2ade4c7767c0edddaee98f5c1878c7c5e5510a0de" +// var tx = "0x04aa74287b3c52e2ecab1cb066d22116317155503681870c516c95cdb148fa28" +// var tx = "0x04aa74287b3c52e2ecab1cb066d22116317155503681870c516c95cdb148fa28" +// var tx = "0x28bd66d99bc45b3f8d959126a26b8c97092892e63fc8ed90eb1598ebedf600ef" +// var tx = "0x3a7355c59f95db494872f33890dbabaceae1ca5330db86db49d24a5c29cd829a" +// _web3.eth.getTransactionReceipt(tx, (err, data) => { +// console.dir(err) +// console.dir(data) + + deployContract((err, tx) => { + cmd_line.startDebug(tx, filename) + }) +//}) const repl = require('repl') @@ -57,3 +110,6 @@ const r = repl.start({ } }); +module.exports = cmd_line + + diff --git a/remix-debug/src/cmdline/contextManager.js b/remix-debug/src/cmdline/contextManager.js index 8a1b1b70d2..82e165df34 100644 --- a/remix-debug/src/cmdline/contextManager.js +++ b/remix-debug/src/cmdline/contextManager.js @@ -37,7 +37,7 @@ class ContextManager { var self = this this.web3Providers.get(type, function (error, obj) { if (error) { - console.log('provider ' + type + ' not defined') + // console.log('provider ' + type + ' not defined') } else { self.web3 = obj self.executionContext.detectNetwork((error, network) => { diff --git a/remix-debug/src/cmdline/index.js b/remix-debug/src/cmdline/index.js index bb27b6fdab..56d5044e77 100644 --- a/remix-debug/src/cmdline/index.js +++ b/remix-debug/src/cmdline/index.js @@ -44,7 +44,7 @@ class CmdLine { self.debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) { if (!lineColumnPos || !lineColumnPos.start) return; - let content = self.compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n") + let content = self.compilation.lastCompilationResult.source.sources[filename].content.split("\n") let line line = content[lineColumnPos.start.line - 2] diff --git a/remix-debug/src/debugger/VmDebugger.js b/remix-debug/src/debugger/VmDebugger.js index 32562d5a86..a21e5c5f61 100644 --- a/remix-debug/src/debugger/VmDebugger.js +++ b/remix-debug/src/debugger/VmDebugger.js @@ -64,7 +64,7 @@ class VmDebuggerLogic { self._traceManager.getCallDataAt(index, function (error, calldata) { if (error) { - console.log(error) + // console.log(error) self.event.trigger('traceManagerCallDataUpdate', [{}]) } else if (self.stepManager.currentStepIndex === index) { self.event.trigger('traceManagerCallDataUpdate', [calldata]) @@ -73,7 +73,7 @@ class VmDebuggerLogic { self._traceManager.getMemoryAt(index, function (error, memory) { if (error) { - console.log(error) + // console.log(error) self.event.trigger('traceManagerMemoryUpdate', [{}]) } else if (self.stepManager.currentStepIndex === index) { self.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)]) @@ -82,7 +82,7 @@ class VmDebuggerLogic { self._traceManager.getCallStackAt(index, function (error, callstack) { if (error) { - console.log(error) + // console.log(error) self.event.trigger('traceManagerCallStackUpdate', [{}]) } else if (self.stepManager.currentStepIndex === index) { self.event.trigger('traceManagerCallStackUpdate', [callstack]) @@ -91,7 +91,7 @@ class VmDebuggerLogic { self._traceManager.getStackAt(index, function (error, callstack) { if (error) { - console.log(error) + // console.log(error) self.event.trigger('traceManagerStackUpdate', [{}]) } else if (self.stepManager.currentStepIndex === index) { self.event.trigger('traceManagerStackUpdate', [callstack]) @@ -106,7 +106,7 @@ class VmDebuggerLogic { storageViewer.storageRange((error, storage) => { if (error) { - console.log(error) + // console.log(error) self.event.trigger('traceManagerStorageUpdate', [{}]) } else if (self.stepManager.currentStepIndex === index) { var header = storageViewer.isComplete(address) ? 'completely loaded' : 'partially loaded...' diff --git a/remix-debug/src/solidity-decoder/internalCallTree.js b/remix-debug/src/solidity-decoder/internalCallTree.js index 974241de97..16e1c2bb3d 100644 --- a/remix-debug/src/solidity-decoder/internalCallTree.js +++ b/remix-debug/src/solidity-decoder/internalCallTree.js @@ -38,7 +38,6 @@ class InternalCallTree { if (result.error) { this.event.trigger('callTreeBuildFailed', [result.error]) } else { - console.log('ready') createReducedTrace(this, traceManager.trace.length - 1) this.event.trigger('callTreeReady', [this.scopes, this.scopeStarts]) } diff --git a/remix-debug/test/sol/ballot.sol b/remix-debug/test/sol/ballot.sol new file mode 100644 index 0000000000..ec43956ce9 --- /dev/null +++ b/remix-debug/test/sol/ballot.sol @@ -0,0 +1,65 @@ +pragma solidity ^0.4.0; +contract Ballot { + + struct Voter { + uint weight; + bool voted; + uint8 vote; + address delegate; + } + struct Proposal { + uint voteCount; + } + + address chairperson; + mapping(address => Voter) voters; + Proposal[] proposals; + + /// Create a new ballot with $(_numProposals) different proposals. + function Ballot(uint8 _numProposals) public { + chairperson = msg.sender; + voters[chairperson].weight = 1; + proposals.length = _numProposals; + } + + /// Give $(toVoter) the right to vote on this ballot. + /// May only be called by $(chairperson). + function giveRightToVote(address toVoter) public { + if (msg.sender != chairperson || voters[toVoter].voted) return; + voters[toVoter].weight = 1; + } + + /// Delegate your vote to the voter $(to). + function delegate(address to) public { + Voter storage sender = voters[msg.sender]; // assigns reference + if (sender.voted) return; + while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender) + to = voters[to].delegate; + if (to == msg.sender) return; + sender.voted = true; + sender.delegate = to; + Voter storage delegateTo = voters[to]; + if (delegateTo.voted) + proposals[delegateTo.vote].voteCount += sender.weight; + else + delegateTo.weight += sender.weight; + } + + /// Give a single vote to proposal $(toProposal). + function vote(uint8 toProposal) public { + Voter storage sender = voters[msg.sender]; + if (sender.voted || toProposal >= proposals.length) return; + sender.voted = true; + sender.vote = toProposal; + proposals[toProposal].voteCount += sender.weight; + } + + function winningProposal() public constant returns (uint8 _winningProposal) { + uint256 winningVoteCount = 0; + for (uint8 prop = 0; prop < proposals.length; prop++) + if (proposals[prop].voteCount > winningVoteCount) { + winningVoteCount = proposals[prop].voteCount; + _winningProposal = prop; + } + } +} diff --git a/remix-debug/test/sol/simple_storage.sol b/remix-debug/test/sol/simple_storage.sol new file mode 100644 index 0000000000..00b1554807 --- /dev/null +++ b/remix-debug/test/sol/simple_storage.sol @@ -0,0 +1,22 @@ +pragma solidity ^0.4.25; + +contract SimpleStorage { + uint public storedData; + address owner; + + constructor(uint initialValue) public { + storedData = initialValue; + owner = msg.sender; + } + + function set(uint x) public { + storedData = x; + require(msg.sender != owner); + storedData = x + 2; + } + + function get() public view returns (uint retVal) { + return storedData; + } + +} diff --git a/remix-lib/src/code/codeResolver.js b/remix-lib/src/code/codeResolver.js index 363fb5aaff..da52a74d3c 100644 --- a/remix-lib/src/code/codeResolver.js +++ b/remix-lib/src/code/codeResolver.js @@ -29,7 +29,6 @@ CodeResolver.prototype.resolveCode = function (address, callBack) { } CodeResolver.prototype.loadCode = function (address, callback) { - console.log('loading new code from web3 ' + address) this.web3.eth.getCode(address, function (error, result) { if (error) { console.log(error)