Browse Source

Merge pull request #750 from debris/ethereumjs

latest changes from ethereumjs, sha3 method signature
cl-refactor
Gav Wood 10 years ago
parent
commit
d219de6935
  1. 133
      libjsqrc/ethereumjs/dist/ethereum.js
  2. 16
      libjsqrc/ethereumjs/dist/ethereum.js.map
  3. 2
      libjsqrc/ethereumjs/dist/ethereum.min.js
  4. 2
      libjsqrc/ethereumjs/example/contract.html
  5. 2
      libjsqrc/ethereumjs/index.js
  6. 5
      libjsqrc/ethereumjs/index_qt.js
  7. 16
      libjsqrc/ethereumjs/lib/abi.js
  8. 2
      libjsqrc/ethereumjs/lib/autoprovider.js
  9. 9
      libjsqrc/ethereumjs/lib/contract.js
  10. 5
      libjsqrc/ethereumjs/lib/web3.js
  11. 3
      libjsqrc/ethereumjs/lib/websocket.js
  12. 2
      libjsqrc/ethereumjs/package.json

133
libjsqrc/ethereumjs/dist/ethereum.js

@ -141,7 +141,6 @@ var toAbiInput = function (json, methodName, params) {
return;
}
bytes = "0x" + padLeft(index.toString(16), 2);
var method = json[index];
for (var i = 0; i < method.inputs.length; i++) {
@ -260,9 +259,22 @@ var outputParser = function (json) {
return parser;
};
var methodSignature = function (json, name) {
var method = json[findMethodIndex(json, name)];
var result = name + '(';
var inputTypes = method.inputs.map(function (inp) {
return inp.type;
});
result += inputTypes.join(',');
result += ')';
return web3.sha3(web3.fromAscii(result));
};
module.exports = {
inputParser: inputParser,
outputParser: outputParser
outputParser: outputParser,
methodSignature: methodSignature
};
},{}],2:[function(require,module,exports){
@ -298,7 +310,7 @@ module.exports = {
// TODO: is these line is supposed to be here?
if ("build" !== 'build') {/*
var WebSocket = require('ws'); // jshint ignore:line
var web3 = require('./main.js'); // jshint ignore:line
var web3 = require('./web3'); // jshint ignore:line
*/}
var AutoProvider = function (userOptions) {
@ -399,6 +411,9 @@ if ("build" !== 'build') {/*
var abi = require('./abi');
// method signature length in bytes
var ETH_METHOD_SIGNATURE_LENGTH = 4;
var contract = function (address, desc) {
var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc);
@ -418,8 +433,10 @@ var contract = function (address, desc) {
call: function (extra) {
extra = extra || {};
extra.to = address;
extra.data = parsed;
return web3.eth.call(extra).then(onSuccess);
return abi.methodSignature(desc, method.name).then(function (signature) {
extra.data = signature.slice(0, 2 + ETH_METHOD_SIGNATURE_LENGTH * 2) + parsed;
return web3.eth.call(extra).then(onSuccess);
});
},
transact: function (extra) {
extra = extra || {};
@ -549,6 +566,53 @@ module.exports = HttpRpcProvider;
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 qt.js
* @authors:
* Jeffrey Wilcke <jeff@ethdev.com>
* Marek Kotewicz <marek@ethdev.com>
* @date 2014
*/
var QtProvider = function() {
this.handlers = [];
var self = this;
navigator.qt.onmessage = function (message) {
self.handlers.forEach(function (handler) {
handler.call(self, JSON.parse(message.data));
});
};
};
QtProvider.prototype.send = function(payload) {
navigator.qt.postMessage(JSON.stringify(payload));
};
Object.defineProperty(QtProvider.prototype, "onmessage", {
set: function(handler) {
this.handlers.push(handler);
}
});
module.exports = QtProvider;
},{}],6:[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 main.js
* @authors:
* Jeffrey Wilcke <jeff@ethdev.com>
@ -791,7 +855,7 @@ var web3 = {
},
fromAscii: function(str, pad) {
pad = pad === undefined ? 32 : pad;
pad = pad === undefined ? 0 : pad;
var hex = this.toHex(str);
while(hex.length < pad*2)
hex += "00";
@ -1040,54 +1104,8 @@ function messageHandler(data) {
}
}
module.exports = web3;
},{}],6:[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 qt.js
* @authors:
* Jeffrey Wilcke <jeff@ethdev.com>
* Marek Kotewicz <marek@ethdev.com>
* @date 2014
*/
var QtProvider = function() {
this.handlers = [];
var self = this;
navigator.qt.onmessage = function (message) {
self.handlers.forEach(function (handler) {
handler.call(self, JSON.parse(message.data));
});
};
};
QtProvider.prototype.send = function(payload) {
navigator.qt.postMessage(JSON.stringify(payload));
};
Object.defineProperty(QtProvider.prototype, "onmessage", {
set: function(handler) {
this.handlers.push(handler);
}
});
module.exports = QtProvider;
if (typeof(module) !== "undefined")
module.exports = web3;
},{}],7:[function(require,module,exports){
/*
@ -1166,10 +1184,11 @@ Object.defineProperty(WebSocketProvider.prototype, "onmessage", {
set: function(provider) { this.onMessage(provider); }
});
module.exports = WebSocketProvider;
if (typeof(module) !== "undefined")
module.exports = WebSocketProvider;
},{}],"web3":[function(require,module,exports){
var web3 = require('./lib/main');
var web3 = require('./lib/web3');
web3.providers.WebSocketProvider = require('./lib/websocket');
web3.providers.HttpRpcProvider = require('./lib/httprpc');
web3.providers.QtProvider = require('./lib/qt');
@ -1178,7 +1197,7 @@ web3.contract = require('./lib/contract');
module.exports = web3;
},{"./lib/autoprovider":2,"./lib/contract":3,"./lib/httprpc":4,"./lib/main":5,"./lib/qt":6,"./lib/websocket":7}]},{},["web3"])
},{"./lib/autoprovider":2,"./lib/contract":3,"./lib/httprpc":4,"./lib/qt":5,"./lib/web3":6,"./lib/websocket":7}]},{},["web3"])
//# sourceMappingURL=ethereum.js.map

16
libjsqrc/ethereumjs/dist/ethereum.js.map

File diff suppressed because one or more lines are too long

2
libjsqrc/ethereumjs/dist/ethereum.min.js

File diff suppressed because one or more lines are too long

2
libjsqrc/ethereumjs/example/contract.html

@ -50,7 +50,7 @@
function callExampleContract() {
// this should be generated by ethereum
var param = document.getElementById('value').value;
var param = parseInt(document.getElementById('value').value);
// call the contract
contract.multiply(param).call().then(function(res) {

2
libjsqrc/ethereumjs/index.js

@ -1,4 +1,4 @@
var web3 = require('./lib/main');
var web3 = require('./lib/web3');
web3.providers.WebSocketProvider = require('./lib/websocket');
web3.providers.HttpRpcProvider = require('./lib/httprpc');
web3.providers.QtProvider = require('./lib/qt');

5
libjsqrc/ethereumjs/index_qt.js

@ -1,5 +0,0 @@
var web3 = require('./lib/main');
web3.providers.QtProvider = require('./lib/qt');
web3.contract = require('./lib/contract');
module.exports = web3;

16
libjsqrc/ethereumjs/lib/abi.js

@ -140,7 +140,6 @@ var toAbiInput = function (json, methodName, params) {
return;
}
bytes = "0x" + padLeft(index.toString(16), 2);
var method = json[index];
for (var i = 0; i < method.inputs.length; i++) {
@ -259,7 +258,20 @@ var outputParser = function (json) {
return parser;
};
var methodSignature = function (json, name) {
var method = json[findMethodIndex(json, name)];
var result = name + '(';
var inputTypes = method.inputs.map(function (inp) {
return inp.type;
});
result += inputTypes.join(',');
result += ')';
return web3.sha3(web3.fromAscii(result));
};
module.exports = {
inputParser: inputParser,
outputParser: outputParser
outputParser: outputParser,
methodSignature: methodSignature
};

2
libjsqrc/ethereumjs/lib/autoprovider.js

@ -30,7 +30,7 @@
// TODO: is these line is supposed to be here?
if (process.env.NODE_ENV !== 'build') {
var WebSocket = require('ws'); // jshint ignore:line
var web3 = require('./main.js'); // jshint ignore:line
var web3 = require('./web3'); // jshint ignore:line
}
var AutoProvider = function (userOptions) {

9
libjsqrc/ethereumjs/lib/contract.js

@ -27,6 +27,9 @@ if (process.env.NODE_ENV !== 'build') {
var abi = require('./abi');
// method signature length in bytes
var ETH_METHOD_SIGNATURE_LENGTH = 4;
var contract = function (address, desc) {
var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc);
@ -46,8 +49,10 @@ var contract = function (address, desc) {
call: function (extra) {
extra = extra || {};
extra.to = address;
extra.data = parsed;
return web3.eth.call(extra).then(onSuccess);
return abi.methodSignature(desc, method.name).then(function (signature) {
extra.data = signature.slice(0, 2 + ETH_METHOD_SIGNATURE_LENGTH * 2) + parsed;
return web3.eth.call(extra).then(onSuccess);
});
},
transact: function (extra) {
extra = extra || {};

5
libjsqrc/ethereumjs/lib/main.js → libjsqrc/ethereumjs/lib/web3.js

@ -256,7 +256,7 @@ var web3 = {
},
fromAscii: function(str, pad) {
pad = pad === undefined ? 32 : pad;
pad = pad === undefined ? 0 : pad;
var hex = this.toHex(str);
while(hex.length < pad*2)
hex += "00";
@ -505,4 +505,5 @@ function messageHandler(data) {
}
}
module.exports = web3;
if (typeof(module) !== "undefined")
module.exports = web3;

3
libjsqrc/ethereumjs/lib/websocket.js

@ -74,4 +74,5 @@ Object.defineProperty(WebSocketProvider.prototype, "onmessage", {
set: function(provider) { this.onMessage(provider); }
});
module.exports = WebSocketProvider;
if (typeof(module) !== "undefined")
module.exports = WebSocketProvider;

2
libjsqrc/ethereumjs/package.json

@ -1,7 +1,7 @@
{
"name": "ethereum.js",
"namespace": "ethereum",
"version": "0.0.5",
"version": "0.0.7",
"description": "Ethereum Compatible JavaScript API",
"main": "./index.js",
"directories": {

Loading…
Cancel
Save