mirror of https://github.com/status-im/web3.js.git
Merge pull request #94 from ethereum/signature
signature methods separated from abi.js
This commit is contained in:
commit
4f9aaec191
|
@ -22,7 +22,6 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof requ
|
|||
* @date 2014
|
||||
*/
|
||||
|
||||
var web3 = require('./web3');
|
||||
var utils = require('./utils');
|
||||
var types = require('./types');
|
||||
var c = require('./const');
|
||||
|
@ -190,27 +189,15 @@ var outputParser = function (json) {
|
|||
return parser;
|
||||
};
|
||||
|
||||
/// @param function/event name for which we want to get signature
|
||||
/// @returns signature of function/event with given name
|
||||
var signatureFromAscii = function (name) {
|
||||
return web3.sha3(web3.fromAscii(name)).slice(0, 2 + c.ETH_SIGNATURE_LENGTH * 2);
|
||||
};
|
||||
|
||||
var eventSignatureFromAscii = function (name) {
|
||||
return web3.sha3(web3.fromAscii(name));
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputParser: inputParser,
|
||||
outputParser: outputParser,
|
||||
formatInput: formatInput,
|
||||
formatOutput: formatOutput,
|
||||
signatureFromAscii: signatureFromAscii,
|
||||
eventSignatureFromAscii: eventSignatureFromAscii
|
||||
formatOutput: formatOutput
|
||||
};
|
||||
|
||||
|
||||
},{"./const":2,"./formatters":8,"./types":14,"./utils":15,"./web3":17}],2:[function(require,module,exports){
|
||||
},{"./const":2,"./formatters":8,"./types":15,"./utils":16}],2:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
|
@ -296,6 +283,7 @@ var web3 = require('./web3');
|
|||
var abi = require('./abi');
|
||||
var utils = require('./utils');
|
||||
var eventImpl = require('./event');
|
||||
var signature = require('./signature');
|
||||
|
||||
var exportNatspecGlobals = function (vars) {
|
||||
// it's used byt natspec.js
|
||||
|
@ -343,12 +331,12 @@ var addFunctionsToContract = function (contract, desc, address) {
|
|||
var impl = function () {
|
||||
/*jshint maxcomplexity:7 */
|
||||
var params = Array.prototype.slice.call(arguments);
|
||||
var signature = abi.signatureFromAscii(method.name);
|
||||
var sign = signature.functionSignatureFromAscii(method.name);
|
||||
var parsed = inputParser[displayName][typeName].apply(null, params);
|
||||
|
||||
var options = contract._options || {};
|
||||
options.to = address;
|
||||
options.data = signature + parsed;
|
||||
options.data = sign + parsed;
|
||||
|
||||
var isTransact = contract._isTransact === true || (contract._isTransact !== false && !method.constant);
|
||||
var collapse = options.collapse !== false;
|
||||
|
@ -402,7 +390,7 @@ var addEventRelatedPropertiesToContract = function (contract, desc, address) {
|
|||
Object.defineProperty(contract, 'topic', {
|
||||
get: function() {
|
||||
return utils.filterEvents(desc).map(function (e) {
|
||||
return abi.eventSignatureFromAscii(e.name);
|
||||
return signature.eventSignatureFromAscii(e.name);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -415,8 +403,8 @@ var addEventsToContract = function (contract, desc, address) {
|
|||
|
||||
var impl = function () {
|
||||
var params = Array.prototype.slice.call(arguments);
|
||||
var signature = abi.eventSignatureFromAscii(e.name);
|
||||
var event = eventImpl.inputParser(address, signature, e);
|
||||
var sign = signature.eventSignatureFromAscii(e.name);
|
||||
var event = eventImpl.inputParser(address, sign, e);
|
||||
var o = event.apply(null, params);
|
||||
var outputFormatter = function (data) {
|
||||
var parser = eventImpl.outputParser(e);
|
||||
|
@ -489,7 +477,7 @@ var contract = function (address, desc) {
|
|||
module.exports = contract;
|
||||
|
||||
|
||||
},{"./abi":1,"./event":6,"./utils":15,"./web3":17}],4:[function(require,module,exports){
|
||||
},{"./abi":1,"./event":6,"./signature":14,"./utils":16,"./web3":18}],4:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
|
@ -638,6 +626,7 @@ module.exports = {
|
|||
|
||||
var abi = require('./abi');
|
||||
var utils = require('./utils');
|
||||
var signature = require('./signature');
|
||||
|
||||
/// filter inputs array && returns only indexed (or not) inputs
|
||||
/// @param inputs array
|
||||
|
@ -676,14 +665,14 @@ var indexedParamsToTopics = function (event, indexed) {
|
|||
});
|
||||
};
|
||||
|
||||
var inputParser = function (address, signature, event) {
|
||||
var inputParser = function (address, sign, event) {
|
||||
|
||||
// valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch'
|
||||
return function (indexed, options) {
|
||||
var o = options || {};
|
||||
o.address = address;
|
||||
o.topic = [];
|
||||
o.topic.push(signature);
|
||||
o.topic.push(sign);
|
||||
if (indexed) {
|
||||
o.topic = o.topic.concat(indexedParamsToTopics(event, indexed));
|
||||
}
|
||||
|
@ -735,8 +724,8 @@ var outputParser = function (event) {
|
|||
|
||||
var getMatchingEvent = function (events, payload) {
|
||||
for (var i = 0; i < events.length; i++) {
|
||||
var signature = abi.eventSignatureFromAscii(events[i].name);
|
||||
if (signature === payload.topic[0]) {
|
||||
var sign = signature.eventSignatureFromAscii(events[i].name);
|
||||
if (sign === payload.topic[0]) {
|
||||
return events[i];
|
||||
}
|
||||
}
|
||||
|
@ -751,7 +740,7 @@ module.exports = {
|
|||
};
|
||||
|
||||
|
||||
},{"./abi":1,"./utils":15}],7:[function(require,module,exports){
|
||||
},{"./abi":1,"./signature":14,"./utils":16}],7:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
|
@ -1023,7 +1012,7 @@ module.exports = {
|
|||
};
|
||||
|
||||
|
||||
},{"./const":2,"./utils":15}],9:[function(require,module,exports){
|
||||
},{"./const":2,"./utils":16}],9:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
|
@ -1345,6 +1334,50 @@ module.exports = {
|
|||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @file signature.js
|
||||
* @authors:
|
||||
* Marek Kotewicz <marek@ethdev.com>
|
||||
* @date 2015
|
||||
*/
|
||||
|
||||
var web3 = require('./web3');
|
||||
var c = require('./const');
|
||||
|
||||
/// @param function name for which we want to get signature
|
||||
/// @returns signature of function with given name
|
||||
var functionSignatureFromAscii = function (name) {
|
||||
return web3.sha3(web3.fromAscii(name)).slice(0, 2 + c.ETH_SIGNATURE_LENGTH * 2);
|
||||
};
|
||||
|
||||
/// @param event name for which we want to get signature
|
||||
/// @returns signature of event with given name
|
||||
var eventSignatureFromAscii = function (name) {
|
||||
return web3.sha3(web3.fromAscii(name));
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
functionSignatureFromAscii: functionSignatureFromAscii,
|
||||
eventSignatureFromAscii: eventSignatureFromAscii
|
||||
};
|
||||
|
||||
|
||||
},{"./const":2,"./web3":18}],15:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
ethereum.js is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ethereum.js is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @file types.js
|
||||
* @authors:
|
||||
* Marek Kotewicz <marek@ethdev.com>
|
||||
|
@ -1409,7 +1442,7 @@ module.exports = {
|
|||
};
|
||||
|
||||
|
||||
},{"./formatters":8}],15:[function(require,module,exports){
|
||||
},{"./formatters":8}],16:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
|
@ -1554,7 +1587,7 @@ module.exports = {
|
|||
};
|
||||
|
||||
|
||||
},{"./const":2}],16:[function(require,module,exports){
|
||||
},{"./const":2}],17:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
|
@ -1605,7 +1638,7 @@ module.exports = {
|
|||
};
|
||||
|
||||
|
||||
},{}],17:[function(require,module,exports){
|
||||
},{}],18:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
|
@ -1796,7 +1829,7 @@ setupMethods(shhWatch, watches.shh());
|
|||
module.exports = web3;
|
||||
|
||||
|
||||
},{"./db":4,"./eth":5,"./filter":7,"./requestmanager":12,"./shh":13,"./utils":15,"./watches":16}],"web3":[function(require,module,exports){
|
||||
},{"./db":4,"./eth":5,"./filter":7,"./requestmanager":12,"./shh":13,"./utils":16,"./watches":17}],"web3":[function(require,module,exports){
|
||||
var web3 = require('./lib/web3');
|
||||
web3.providers.HttpSyncProvider = require('./lib/httpsync');
|
||||
web3.providers.QtSyncProvider = require('./lib/qtsync');
|
||||
|
@ -1805,7 +1838,7 @@ web3.abi = require('./lib/abi');
|
|||
|
||||
module.exports = web3;
|
||||
|
||||
},{"./lib/abi":1,"./lib/contract":3,"./lib/httpsync":9,"./lib/qtsync":11,"./lib/web3":17}]},{},["web3"])
|
||||
},{"./lib/abi":1,"./lib/contract":3,"./lib/httpsync":9,"./lib/qtsync":11,"./lib/web3":18}]},{},["web3"])
|
||||
|
||||
|
||||
//# sourceMappingURL=ethereum.js.map
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
15
lib/abi.js
15
lib/abi.js
|
@ -21,7 +21,6 @@
|
|||
* @date 2014
|
||||
*/
|
||||
|
||||
var web3 = require('./web3');
|
||||
var utils = require('./utils');
|
||||
var types = require('./types');
|
||||
var c = require('./const');
|
||||
|
@ -189,22 +188,10 @@ var outputParser = function (json) {
|
|||
return parser;
|
||||
};
|
||||
|
||||
/// @param function/event name for which we want to get signature
|
||||
/// @returns signature of function/event with given name
|
||||
var signatureFromAscii = function (name) {
|
||||
return web3.sha3(web3.fromAscii(name)).slice(0, 2 + c.ETH_SIGNATURE_LENGTH * 2);
|
||||
};
|
||||
|
||||
var eventSignatureFromAscii = function (name) {
|
||||
return web3.sha3(web3.fromAscii(name));
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputParser: inputParser,
|
||||
outputParser: outputParser,
|
||||
formatInput: formatInput,
|
||||
formatOutput: formatOutput,
|
||||
signatureFromAscii: signatureFromAscii,
|
||||
eventSignatureFromAscii: eventSignatureFromAscii
|
||||
formatOutput: formatOutput
|
||||
};
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ var web3 = require('./web3');
|
|||
var abi = require('./abi');
|
||||
var utils = require('./utils');
|
||||
var eventImpl = require('./event');
|
||||
var signature = require('./signature');
|
||||
|
||||
var exportNatspecGlobals = function (vars) {
|
||||
// it's used byt natspec.js
|
||||
|
@ -71,12 +72,12 @@ var addFunctionsToContract = function (contract, desc, address) {
|
|||
var impl = function () {
|
||||
/*jshint maxcomplexity:7 */
|
||||
var params = Array.prototype.slice.call(arguments);
|
||||
var signature = abi.signatureFromAscii(method.name);
|
||||
var sign = signature.functionSignatureFromAscii(method.name);
|
||||
var parsed = inputParser[displayName][typeName].apply(null, params);
|
||||
|
||||
var options = contract._options || {};
|
||||
options.to = address;
|
||||
options.data = signature + parsed;
|
||||
options.data = sign + parsed;
|
||||
|
||||
var isTransact = contract._isTransact === true || (contract._isTransact !== false && !method.constant);
|
||||
var collapse = options.collapse !== false;
|
||||
|
@ -130,7 +131,7 @@ var addEventRelatedPropertiesToContract = function (contract, desc, address) {
|
|||
Object.defineProperty(contract, 'topic', {
|
||||
get: function() {
|
||||
return utils.filterEvents(desc).map(function (e) {
|
||||
return abi.eventSignatureFromAscii(e.name);
|
||||
return signature.eventSignatureFromAscii(e.name);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -143,8 +144,8 @@ var addEventsToContract = function (contract, desc, address) {
|
|||
|
||||
var impl = function () {
|
||||
var params = Array.prototype.slice.call(arguments);
|
||||
var signature = abi.eventSignatureFromAscii(e.name);
|
||||
var event = eventImpl.inputParser(address, signature, e);
|
||||
var sign = signature.eventSignatureFromAscii(e.name);
|
||||
var event = eventImpl.inputParser(address, sign, e);
|
||||
var o = event.apply(null, params);
|
||||
var outputFormatter = function (data) {
|
||||
var parser = eventImpl.outputParser(e);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
var abi = require('./abi');
|
||||
var utils = require('./utils');
|
||||
var signature = require('./signature');
|
||||
|
||||
/// filter inputs array && returns only indexed (or not) inputs
|
||||
/// @param inputs array
|
||||
|
@ -60,14 +61,14 @@ var indexedParamsToTopics = function (event, indexed) {
|
|||
});
|
||||
};
|
||||
|
||||
var inputParser = function (address, signature, event) {
|
||||
var inputParser = function (address, sign, event) {
|
||||
|
||||
// valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch'
|
||||
return function (indexed, options) {
|
||||
var o = options || {};
|
||||
o.address = address;
|
||||
o.topic = [];
|
||||
o.topic.push(signature);
|
||||
o.topic.push(sign);
|
||||
if (indexed) {
|
||||
o.topic = o.topic.concat(indexedParamsToTopics(event, indexed));
|
||||
}
|
||||
|
@ -119,8 +120,8 @@ var outputParser = function (event) {
|
|||
|
||||
var getMatchingEvent = function (events, payload) {
|
||||
for (var i = 0; i < events.length; i++) {
|
||||
var signature = abi.eventSignatureFromAscii(events[i].name);
|
||||
if (signature === payload.topic[0]) {
|
||||
var sign = signature.eventSignatureFromAscii(events[i].name);
|
||||
if (sign === payload.topic[0]) {
|
||||
return events[i];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
ethereum.js is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ethereum.js is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @file signature.js
|
||||
* @authors:
|
||||
* Marek Kotewicz <marek@ethdev.com>
|
||||
* @date 2015
|
||||
*/
|
||||
|
||||
var web3 = require('./web3');
|
||||
var c = require('./const');
|
||||
|
||||
/// @param function name for which we want to get signature
|
||||
/// @returns signature of function with given name
|
||||
var functionSignatureFromAscii = function (name) {
|
||||
return web3.sha3(web3.fromAscii(name)).slice(0, 2 + c.ETH_SIGNATURE_LENGTH * 2);
|
||||
};
|
||||
|
||||
/// @param event name for which we want to get signature
|
||||
/// @returns signature of event with given name
|
||||
var eventSignatureFromAscii = function (name) {
|
||||
return web3.sha3(web3.fromAscii(name));
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
functionSignatureFromAscii: functionSignatureFromAscii,
|
||||
eventSignatureFromAscii: eventSignatureFromAscii
|
||||
};
|
||||
|
Loading…
Reference in New Issue