You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

10 years ago
/**
10 years ago
* This plugin exposes 'evaluateExpression' method which should be used
* to evaluate natspec description
* It should be reloaded each time we want to evaluate set of expressions
10 years ago
* Just because of security reasons
10 years ago
* TODO: make use of sync api (once it's finished) and remove unnecessary
* code from 'getContractMethods'
* TODO: unify method signature creation with abi.js (and make a separate method from it)
10 years ago
*/
/// Should be called to copy values from object to global context
10 years ago
var copyToContext = function (obj, context) {
10 years ago
var keys = Object.keys(obj);
keys.forEach(function (key) {
10 years ago
context[key] = obj[key];
10 years ago
});
}
/// Function called to get all contract's storage values
10 years ago
/// @returns hashmap with contract properties which are used
var getContractProperties = function (expression, abi) {
10 years ago
return {};
10 years ago
};
10 years ago
/// Function called to get all contract's methods
/// @returns hashmap with used contract's methods
10 years ago
var getContractMethods = function (address, abi) {
return web3.eth.contract(address, abi);
10 years ago
};
10 years ago
/// 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) {
10 years ago
var self = this;
10 years ago
var abi = web3._currentContractAbi;
var address = web3._currentContractAddress;
10 years ago
var storage = getContractProperties(expression, abi);
10 years ago
var methods = getContractMethods(address, abi);
10 years ago
10 years ago
copyToContext(storage, self);
copyToContext(methods, self);
10 years ago
10 years ago
// TODO: test if it is safe
10 years ago
return eval(expression).toString();
};