|
|
@ -4,34 +4,51 @@ |
|
|
|
* Just because of security reasons |
|
|
|
*/ |
|
|
|
|
|
|
|
/// helper variable used by 'copyToGlobalContext' function to copy everything to global context
|
|
|
|
var _eth_global = this; |
|
|
|
|
|
|
|
/// Should be called to copy values from object to global context
|
|
|
|
var copyToGlobalContext = function (obj) { |
|
|
|
var copyToContext = function (obj, context) { |
|
|
|
var keys = Object.keys(obj); |
|
|
|
keys.forEach(function (key) { |
|
|
|
_eth_global[key] = obj[key]; |
|
|
|
context[key] = obj[key]; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/// Function called to get all contract's storage values
|
|
|
|
/// In future can be improved be getting storage values on demand
|
|
|
|
/// @returns hashmap with contract storage
|
|
|
|
var getContractStorage = function () { |
|
|
|
return {}; |
|
|
|
/// @returns hashmap with contract properties which are used
|
|
|
|
var getContractProperties = function (expression, abi) { |
|
|
|
var keys = ['test']; |
|
|
|
|
|
|
|
return keys.reduce(function (acc, current) { |
|
|
|
acc[current] = natspec.stateAt(current); |
|
|
|
return acc; |
|
|
|
}, {}); |
|
|
|
}; |
|
|
|
|
|
|
|
/// Function called to get all contract's methods
|
|
|
|
/// @returns hashmap with used contract's methods
|
|
|
|
var getContractMethods = function (expression, abi) { |
|
|
|
var keys = ['testMethod']; |
|
|
|
|
|
|
|
return keys.reduce(function (acc, current) { |
|
|
|
acc[current] = function () { |
|
|
|
// TODO: connect parser
|
|
|
|
}; |
|
|
|
return acc; |
|
|
|
}, {}); |
|
|
|
}; |
|
|
|
|
|
|
|
/// Should be called to evaluate single expression
|
|
|
|
/// Is internally using javascript's 'eval' method
|
|
|
|
/// Should be checked if it is safe
|
|
|
|
var evaluateExpression = function (expression) { |
|
|
|
|
|
|
|
// in future may be replaced with getting storage values based on expression
|
|
|
|
var storage = getContractStorage(); |
|
|
|
var self = this; |
|
|
|
var abi = web3._currentAbi; |
|
|
|
|
|
|
|
var storage = getContractProperties(expression, abi); |
|
|
|
var methods = getContractMethods(expression, abi); |
|
|
|
|
|
|
|
copyToGlobalContext(storage); |
|
|
|
copyToContext(storage, self); |
|
|
|
copyToContext(methods, self); |
|
|
|
|
|
|
|
// TODO: check if it is safe
|
|
|
|
return eval(expression).toString(); |
|
|
|