|
|
@ -1,9 +1,10 @@ |
|
|
|
const SolExplore = require('sol-explore'); |
|
|
|
const SolExplore = require('sol-explore'); |
|
|
|
const SolidityParser = require('solidity-parser-sc'); |
|
|
|
const SolidityParser = require('solidity-parser-sc'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const crRegex = /[\r\n ]+$/g; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Splices enclosing brackets into `contract` around `expression`; |
|
|
|
* Splices enclosing brackets into `contract` around `expression`; |
|
|
|
* @param {String} contract solidity code |
|
|
|
* @param {String} contract solidity source |
|
|
|
* @param {Object} node AST node to bracket |
|
|
|
* @param {Object} node AST node to bracket |
|
|
|
* @return {String} contract |
|
|
|
* @return {String} contract |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -11,6 +12,20 @@ function blockWrap(contract, expression) { |
|
|
|
return contract.slice(0, expression.start) + '{' + contract.slice(expression.start, expression.end) + '}' + contract.slice(expression.end); |
|
|
|
return contract.slice(0, expression.start) + '{' + contract.slice(expression.start, expression.end) + '}' + contract.slice(expression.end); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Captures carriage returns at modifiers we'll remove. These need to be re-injected into the |
|
|
|
|
|
|
|
* source to keep line report alignments accurate. |
|
|
|
|
|
|
|
* @param {String} contract solidity source |
|
|
|
|
|
|
|
* @param {Object} modifier AST node |
|
|
|
|
|
|
|
* @return {String} whitespace around the modifier |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function getModifierWhitespace(contract, modifier){ |
|
|
|
|
|
|
|
const source = contract.slice(modifier.start, modifier.end); |
|
|
|
|
|
|
|
const whitespace = source.match(crRegex) || []; |
|
|
|
|
|
|
|
return whitespace.join(''); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Locates unbracketed singleton statements attached to if, else, for and while statements |
|
|
|
* Locates unbracketed singleton statements attached to if, else, for and while statements |
|
|
|
* and brackets them. Instrumenter needs to inject events at these locations and having |
|
|
|
* and brackets them. Instrumenter needs to inject events at these locations and having |
|
|
@ -55,7 +70,12 @@ module.exports.run = function r(contract) { |
|
|
|
// We want to remove constant / pure / view from functions
|
|
|
|
// We want to remove constant / pure / view from functions
|
|
|
|
for (let i = 0; i < node.modifiers.length; i++) { |
|
|
|
for (let i = 0; i < node.modifiers.length; i++) { |
|
|
|
if (['pure', 'constant', 'view'].indexOf(node.modifiers[i].name) > -1) { |
|
|
|
if (['pure', 'constant', 'view'].indexOf(node.modifiers[i].name) > -1) { |
|
|
|
contract = contract.slice(0, node.modifiers[i].start) + contract.slice(node.modifiers[i].end); |
|
|
|
let whitespace = getModifierWhitespace(contract, node.modifiers[i]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contract = contract.slice(0, node.modifiers[i].start) + |
|
|
|
|
|
|
|
whitespace + |
|
|
|
|
|
|
|
contract.slice(node.modifiers[i].end); |
|
|
|
|
|
|
|
|
|
|
|
keepRunning = true; |
|
|
|
keepRunning = true; |
|
|
|
this.stopTraversal(); |
|
|
|
this.stopTraversal(); |
|
|
|
} |
|
|
|
} |
|
|
|