mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 19:48:13 +00:00
Merge branch 'master' into develop
Conflicts: dist/ethereum.js dist/ethereum.js.map dist/ethereum.min.js lib/abi.js
This commit is contained in:
commit
d9d190ec33
@ -75,14 +75,13 @@ npm test
|
||||
|
||||
**Please note this repo is in it's early stage.**
|
||||
|
||||
If you'd like to run a WebSocket ethereum node check out
|
||||
[go-ethereum](https://github.com/ethereum/go-ethereum).
|
||||
If you'd like to run a Http ethereum node check out
|
||||
[cpp-ethereum](https://github.com/ethereum/cpp-ethereum).
|
||||
|
||||
To install ethereum and spawn a node:
|
||||
Install ethereum and spawn a node:
|
||||
|
||||
```
|
||||
go get github.com/ethereum/go-ethereum/ethereum
|
||||
ethereum -ws -loglevel=4
|
||||
eth -j
|
||||
```
|
||||
|
||||
[npm-image]: https://badge.fury.io/js/ethereum.js.png
|
||||
|
108
dist/ethereum.js
vendored
108
dist/ethereum.js
vendored
@ -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');
|
||||
@ -76,6 +75,8 @@ var formatInput = function (inputs, params) {
|
||||
toAppendArrayContent += params[i].reduce(function (acc, curr) {
|
||||
return acc + formatter(curr);
|
||||
}, "");
|
||||
else if (inputs[i].type === 'string')
|
||||
toAppendArrayContent += formatter(params[i]);
|
||||
else
|
||||
toAppendConstant += formatter(params[i]);
|
||||
});
|
||||
@ -192,26 +193,14 @@ 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.
|
||||
|
||||
@ -297,6 +286,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
|
||||
@ -352,12 +342,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 isTransaction = contract._isTransaction === true || (contract._isTransaction !== false && !method.constant);
|
||||
var collapse = options.collapse !== false;
|
||||
@ -411,7 +401,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);
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -424,8 +414,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);
|
||||
@ -514,7 +504,7 @@ function Contract(abi, address) {
|
||||
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.
|
||||
|
||||
@ -683,6 +673,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
|
||||
@ -721,14 +712,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.filter'
|
||||
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));
|
||||
}
|
||||
@ -780,8 +771,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];
|
||||
}
|
||||
}
|
||||
@ -796,7 +787,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.
|
||||
|
||||
@ -1230,7 +1221,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.
|
||||
|
||||
@ -1418,6 +1409,7 @@ var c = require('./const');
|
||||
*/
|
||||
var requestManager = function() {
|
||||
var polls = [];
|
||||
var timeout = null;
|
||||
var provider;
|
||||
|
||||
var send = function (data) {
|
||||
@ -1474,6 +1466,12 @@ var requestManager = function() {
|
||||
poll.uninstall(poll.id);
|
||||
});
|
||||
polls = [];
|
||||
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
poll();
|
||||
};
|
||||
|
||||
var poll = function () {
|
||||
@ -1484,7 +1482,7 @@ var requestManager = function() {
|
||||
}
|
||||
data.callback(result);
|
||||
});
|
||||
setTimeout(poll, c.ETH_POLLING_TIMEOUT);
|
||||
timeout = setTimeout(poll, c.ETH_POLLING_TIMEOUT);
|
||||
};
|
||||
|
||||
poll();
|
||||
@ -1560,6 +1558,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>
|
||||
@ -1624,7 +1666,7 @@ module.exports = {
|
||||
};
|
||||
|
||||
|
||||
},{"./formatters":8}],15:[function(require,module,exports){
|
||||
},{"./formatters":8}],16:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
@ -1932,7 +1974,7 @@ module.exports = {
|
||||
};
|
||||
|
||||
|
||||
},{"./const":2}],16:[function(require,module,exports){
|
||||
},{"./const":2}],17:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
@ -1983,7 +2025,7 @@ module.exports = {
|
||||
};
|
||||
|
||||
|
||||
},{}],17:[function(require,module,exports){
|
||||
},{}],18:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
@ -2226,7 +2268,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');
|
||||
@ -2235,7 +2277,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
|
12
dist/ethereum.js.map
vendored
12
dist/ethereum.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/ethereum.min.js
vendored
2
dist/ethereum.min.js
vendored
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');
|
||||
@ -193,21 +192,9 @@ 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
|
||||
@ -79,12 +80,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 isTransaction = contract._isTransaction === true || (contract._isTransaction !== false && !method.constant);
|
||||
var collapse = options.collapse !== false;
|
||||
@ -138,7 +139,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);
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -151,8 +152,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.filter'
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ var c = require('./const');
|
||||
*/
|
||||
var requestManager = function() {
|
||||
var polls = [];
|
||||
var timeout = null;
|
||||
var provider;
|
||||
|
||||
var send = function (data) {
|
||||
@ -89,6 +90,12 @@ var requestManager = function() {
|
||||
poll.uninstall(poll.id);
|
||||
});
|
||||
polls = [];
|
||||
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
poll();
|
||||
};
|
||||
|
||||
var poll = function () {
|
||||
@ -99,7 +106,7 @@ var requestManager = function() {
|
||||
}
|
||||
data.callback(result);
|
||||
});
|
||||
setTimeout(poll, c.ETH_POLLING_TIMEOUT);
|
||||
timeout = setTimeout(poll, c.ETH_POLLING_TIMEOUT);
|
||||
};
|
||||
|
||||
poll();
|
||||
|
42
lib/signature.js
Normal file
42
lib/signature.js
Normal file
@ -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…
x
Reference in New Issue
Block a user