Browse Source

Squashed 'libjsqrc/ethereumjs/' changes from d223ac0..1f5a6f1

1f5a6f1 Merge branch 'develop' into cpp
da4c2d5 removed promise dependency, updated readme, fixed node.js version of lib
5b70196 upgraded version to 0.0.9
c595632 gulp
c561039 Merge branch 'master' into sync
a7f4448 Merge branch 'develop' into sync
7807a4f polling every second
e5d294d return null instead of undefined, if not provider is set
d0b6f36 watches are calling callback with a single result object, not a full jsonrpc response
fa93480 added addressbook
063f69d added local
b2d23b9 Merge pull request #32 from kumavis/patch-1
e97478c WebsocketProvider - fixed incorrect variable name
507241f shh getMessage => getMessages

git-subtree-dir: libjsqrc/ethereumjs
git-subtree-split: 1f5a6f13419415b4c05519e126eedcdf815aff7c
cl-refactor
Marek Kotewicz 10 years ago
parent
commit
ec71f23423
  1. 15
      README.md
  2. 3
      bower.json
  3. 32
      dist/ethereum.js
  4. 14
      dist/ethereum.js.map
  5. 2
      dist/ethereum.min.js
  6. 1
      example/balance.html
  7. 1
      example/contract.html
  8. 18
      example/node-app.js
  9. 4
      lib/abi.js
  10. 6
      lib/contract.js
  11. 6
      lib/filter.js
  12. 4
      lib/httpsync.js
  13. 18
      lib/local.js
  14. 10
      lib/providermanager.js
  15. 2
      lib/web3.js
  16. 3
      package.json
  17. 1
      test/db.methods.js
  18. 2
      test/eth.methods.js
  19. 2
      test/shh.methods.js
  20. 2
      test/web3.methods.js

15
README.md

@ -1,6 +1,6 @@
# Ethereum JavaScript API # Ethereum JavaScript API
This is the Ethereum compatible JavaScript API using `Promise`s This is the Ethereum compatible [JavaScript API](https://github.com/ethereum/wiki/wiki/JavaScript-API)
which implements the [Generic JSON RPC](https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC) spec. It's available on npm as a node module and also for bower and component as an embeddable js which implements the [Generic JSON RPC](https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC) spec. It's available on npm as a node module and also for bower and component as an embeddable js
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![dependency status][dep-image]][dep-url] [![dev dependency status][dep-dev-image]][dep-dev-url] [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![dependency status][dep-image]][dep-url] [![dev dependency status][dep-dev-image]][dep-dev-url]
@ -23,7 +23,7 @@ Component
component install ethereum/ethereum.js component install ethereum/ethereum.js
* Include `ethereum.min.js` in your html file. * Include `ethereum.min.js` in your html file.
* Include [es6-promise](https://github.com/jakearchibald/es6-promise) or another ES6-Shim if your browser doesn't support ECMAScript 6. * Include [bignumber.js](https://github.com/MikeMcl/bignumber.js/)
## Usage ## Usage
Require the library: Require the library:
@ -37,14 +37,8 @@ Set a provider (QtProvider, WebSocketProvider, HttpRpcProvider)
There you go, now you can use it: There you go, now you can use it:
``` ```
web3.eth.coinbase.then(function(result){ var coinbase = web3.eth.coinbase;
console.log(result); var balance = web3.eth.balanceAt(coinbase);
return web3.eth.balanceAt(result);
}).then(function(balance){
console.log(web3.toDecimal(balance));
}).catch(function(err){
console.log(err);
});
``` ```
@ -99,3 +93,4 @@ ethereum -ws -loglevel=4
[dep-url]: https://david-dm.org/ethereum/ethereum.js [dep-url]: https://david-dm.org/ethereum/ethereum.js
[dep-dev-image]: https://david-dm.org/ethereum/ethereum.js/dev-status.svg [dep-dev-image]: https://david-dm.org/ethereum/ethereum.js/dev-status.svg
[dep-dev-url]: https://david-dm.org/ethereum/ethereum.js#info=devDependencies [dep-dev-url]: https://david-dm.org/ethereum/ethereum.js#info=devDependencies

3
bower.json

@ -1,11 +1,10 @@
{ {
"name": "ethereum.js", "name": "ethereum.js",
"namespace": "ethereum", "namespace": "ethereum",
"version": "0.0.8", "version": "0.0.10",
"description": "Ethereum Compatible JavaScript API", "description": "Ethereum Compatible JavaScript API",
"main": ["./dist/ethereum.js", "./dist/ethereum.min.js"], "main": ["./dist/ethereum.js", "./dist/ethereum.min.js"],
"dependencies": { "dependencies": {
"es6-promise": "#master",
"bignumber.js": ">=2.0.0" "bignumber.js": ">=2.0.0"
}, },
"repository": { "repository": {

32
dist/ethereum.js

@ -129,7 +129,7 @@ var formatInputReal = function (value) {
var dynamicTypeBytes = function (type, value) { var dynamicTypeBytes = function (type, value) {
// TODO: decide what to do with array of strings // TODO: decide what to do with array of strings
if (arrayType(type) || type == 'string') // only string itself that is dynamic; stringX is static length. if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.
return formatInputInt(value.length); return formatInputInt(value.length);
return ""; return "";
}; };
@ -252,7 +252,7 @@ var formatOutputAddress = function (value) {
}; };
var dynamicBytesLength = function (type) { var dynamicBytesLength = function (type) {
if (arrayType(type) || type == 'string') // only string itself that is dynamic; stringX is static length. if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.
return ETH_PADDING * 2; return ETH_PADDING * 2;
return 0; return 0;
}; };
@ -464,7 +464,7 @@ var contract = function (address, desc) {
// prototype, so we make it so as a workaround. // prototype, so we make it so as a workaround.
if (method.name.indexOf('(') === -1) { if (method.name.indexOf('(') === -1) {
var displayName = method.name; var displayName = method.name;
var typeName = method.inputs.map(function(i){return i.type}).join(); var typeName = method.inputs.map(function(i){return i.type; }).join();
method.name = displayName + '(' + typeName + ')'; method.name = displayName + '(' + typeName + ')';
} }
}); });
@ -531,9 +531,9 @@ var contract = function (address, desc) {
var ret = outputParser[displayName][typeName](output); var ret = outputParser[displayName][typeName](output);
if (collapse) if (collapse)
{ {
if (ret.length == 1) if (ret.length === 1)
ret = ret[0]; ret = ret[0];
else if (ret.length == 0) else if (ret.length === 0)
ret = null; ret = null;
} }
return ret; return ret;
@ -603,8 +603,10 @@ Filter.prototype.changed = function(callback) {
/// trigger calling new message from people /// trigger calling new message from people
Filter.prototype.trigger = function(messages) { Filter.prototype.trigger = function(messages) {
for(var i = 0; i < this.callbacks.length; i++) { for (var i = 0; i < this.callbacks.length; i++) {
this.callbacks[i].call(this, messages); for (var j = 0; j < messages; j++) {
this.callbacks[i].call(this, messages[j]);
}
} }
}; };
@ -650,6 +652,10 @@ module.exports = Filter;
* @date 2014 * @date 2014
*/ */
if ("build" !== 'build') {/*
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line
*/}
var HttpSyncProvider = function (host) { var HttpSyncProvider = function (host) {
this.handlers = []; this.handlers = [];
this.host = host || 'http://localhost:8080'; this.host = host || 'http://localhost:8080';
@ -746,15 +752,15 @@ var ProviderManager = function() {
result = JSON.parse(result); result = JSON.parse(result);
// dont call the callback if result is an error, empty array or false // dont call the callback if result is not an array, or empty one
if (result.error || (result.result instanceof Array ? result.result.length === 0 : !result.result)) { if (result.error || !(result.result instanceof Array) || result.result.length === 0) {
return; return;
} }
data.callback(result); data.callback(result.result);
}); });
} }
setTimeout(poll, 12000); setTimeout(poll, 1000);
}; };
poll(); poll();
}; };
@ -767,7 +773,7 @@ ProviderManager.prototype.send = function(data) {
if (this.provider === undefined) { if (this.provider === undefined) {
console.error('provider is not set'); console.error('provider is not set');
return undefined; return null;
} }
//TODO: handle error here? //TODO: handle error here?
@ -982,7 +988,7 @@ var shhWatchMethods = function () {
return [ return [
{ name: 'newFilter', call: 'shh_newFilter' }, { name: 'newFilter', call: 'shh_newFilter' },
{ name: 'uninstallFilter', call: 'shh_uninstallFilter' }, { name: 'uninstallFilter', call: 'shh_uninstallFilter' },
{ name: 'getMessage', call: 'shh_getMessages' } { name: 'getMessages', call: 'shh_getMessages' }
]; ];
}; };

14
dist/ethereum.js.map

File diff suppressed because one or more lines are too long

2
dist/ethereum.min.js

File diff suppressed because one or more lines are too long

1
example/balance.html

@ -2,7 +2,6 @@
<html> <html>
<head> <head>
<script type="text/javascript" src="js/es6-promise/promise.min.js"></script>
<script type="text/javascript" src="js/bignumber.js/bignumber.min.js"></script> <script type="text/javascript" src="js/bignumber.js/bignumber.min.js"></script>
<script type="text/javascript" src="../dist/ethereum.js"></script> <script type="text/javascript" src="../dist/ethereum.js"></script>
<script type="text/javascript"> <script type="text/javascript">

1
example/contract.html

@ -2,7 +2,6 @@
<html> <html>
<head> <head>
<script type="text/javascript" src="js/es6-promise/promise.min.js"></script>
<script type="text/javascript" src="js/bignumber.js/bignumber.min.js"></script> <script type="text/javascript" src="js/bignumber.js/bignumber.min.js"></script>
<script type="text/javascript" src="../dist/ethereum.js"></script> <script type="text/javascript" src="../dist/ethereum.js"></script>
<script type="text/javascript"> <script type="text/javascript">

18
example/node-app.js

@ -1,16 +1,12 @@
#!/usr/bin/env node #!/usr/bin/env node
require('es6-promise').polyfill();
var web3 = require("../index.js"); var web3 = require("../index.js");
web3.setProvider(new web3.providers.HttpRpcProvider('http://localhost:8080')); web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080'));
var coinbase = web3.eth.coinbase;
console.log(coinbase);
var balance = web3.eth.balanceAt(coinbase);
console.log(balance);
web3.eth.coinbase.then(function(result){
console.log(result);
return web3.eth.balanceAt(result);
}).then(function(balance){
console.log(web3.toDecimal(balance));
}).catch(function(err){
console.log(err);
});

4
lib/abi.js

@ -128,7 +128,7 @@ var formatInputReal = function (value) {
var dynamicTypeBytes = function (type, value) { var dynamicTypeBytes = function (type, value) {
// TODO: decide what to do with array of strings // TODO: decide what to do with array of strings
if (arrayType(type) || type == 'string') // only string itself that is dynamic; stringX is static length. if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.
return formatInputInt(value.length); return formatInputInt(value.length);
return ""; return "";
}; };
@ -251,7 +251,7 @@ var formatOutputAddress = function (value) {
}; };
var dynamicBytesLength = function (type) { var dynamicBytesLength = function (type) {
if (arrayType(type) || type == 'string') // only string itself that is dynamic; stringX is static length. if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.
return ETH_PADDING * 2; return ETH_PADDING * 2;
return 0; return 0;
}; };

6
lib/contract.js

@ -53,7 +53,7 @@ var contract = function (address, desc) {
// prototype, so we make it so as a workaround. // prototype, so we make it so as a workaround.
if (method.name.indexOf('(') === -1) { if (method.name.indexOf('(') === -1) {
var displayName = method.name; var displayName = method.name;
var typeName = method.inputs.map(function(i){return i.type}).join(); var typeName = method.inputs.map(function(i){return i.type; }).join();
method.name = displayName + '(' + typeName + ')'; method.name = displayName + '(' + typeName + ')';
} }
}); });
@ -120,9 +120,9 @@ var contract = function (address, desc) {
var ret = outputParser[displayName][typeName](output); var ret = outputParser[displayName][typeName](output);
if (collapse) if (collapse)
{ {
if (ret.length == 1) if (ret.length === 1)
ret = ret[0]; ret = ret[0];
else if (ret.length == 0) else if (ret.length === 0)
ret = null; ret = null;
} }
return ret; return ret;

6
lib/filter.js

@ -47,8 +47,10 @@ Filter.prototype.changed = function(callback) {
/// trigger calling new message from people /// trigger calling new message from people
Filter.prototype.trigger = function(messages) { Filter.prototype.trigger = function(messages) {
for(var i = 0; i < this.callbacks.length; i++) { for (var i = 0; i < this.callbacks.length; i++) {
this.callbacks[i].call(this, messages); for (var j = 0; j < messages; j++) {
this.callbacks[i].call(this, messages[j]);
}
} }
}; };

4
lib/httpsync.js

@ -21,6 +21,10 @@
* @date 2014 * @date 2014
*/ */
if (process.env.NODE_ENV !== 'build') {
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line
}
var HttpSyncProvider = function (host) { var HttpSyncProvider = function (host) {
this.handlers = []; this.handlers = [];
this.host = host || 'http://localhost:8080'; this.host = host || 'http://localhost:8080';

18
lib/local.js

@ -0,0 +1,18 @@
var addressName = {"0x12378912345789": "Gav", "0x57835893478594739854": "Jeff"};
var nameAddress = {};
for (var prop in addressName) {
if (addressName.hasOwnProperty(prop)) {
nameAddress[addressName[prop]] = prop;
}
}
var local = {
addressBook:{
byName: addressName,
byAddress: nameAddress
}
};
if (typeof(module) !== "undefined")
module.exports = local;

10
lib/providermanager.js

@ -49,15 +49,15 @@ var ProviderManager = function() {
result = JSON.parse(result); result = JSON.parse(result);
// dont call the callback if result is an error, empty array or false // dont call the callback if result is not an array, or empty one
if (result.error || (result.result instanceof Array ? result.result.length === 0 : !result.result)) { if (result.error || !(result.result instanceof Array) || result.result.length === 0) {
return; return;
} }
data.callback(result); data.callback(result.result);
}); });
} }
setTimeout(poll, 12000); setTimeout(poll, 1000);
}; };
poll(); poll();
}; };
@ -70,7 +70,7 @@ ProviderManager.prototype.send = function(data) {
if (this.provider === undefined) { if (this.provider === undefined) {
console.error('provider is not set'); console.error('provider is not set');
return undefined; return null;
} }
//TODO: handle error here? //TODO: handle error here?

2
lib/web3.js

@ -145,7 +145,7 @@ var shhWatchMethods = function () {
return [ return [
{ name: 'newFilter', call: 'shh_newFilter' }, { name: 'newFilter', call: 'shh_newFilter' },
{ name: 'uninstallFilter', call: 'shh_uninstallFilter' }, { name: 'uninstallFilter', call: 'shh_uninstallFilter' },
{ name: 'getMessage', call: 'shh_getMessages' } { name: 'getMessages', call: 'shh_getMessages' }
]; ];
}; };

3
package.json

@ -1,14 +1,13 @@
{ {
"name": "ethereum.js", "name": "ethereum.js",
"namespace": "ethereum", "namespace": "ethereum",
"version": "0.0.8", "version": "0.0.10",
"description": "Ethereum Compatible JavaScript API", "description": "Ethereum Compatible JavaScript API",
"main": "./index.js", "main": "./index.js",
"directories": { "directories": {
"lib": "./lib" "lib": "./lib"
}, },
"dependencies": { "dependencies": {
"es6-promise": "*",
"ws": "*", "ws": "*",
"xmlhttprequest": "*", "xmlhttprequest": "*",
"bignumber.js": ">=2.0.0" "bignumber.js": ">=2.0.0"

1
test/db.methods.js

@ -1,4 +1,3 @@
require('es6-promise').polyfill();
var assert = require('assert'); var assert = require('assert');
var web3 = require('../index.js'); var web3 = require('../index.js');

2
test/eth.methods.js

@ -1,5 +1,3 @@
require('es6-promise').polyfill();
var assert = require('assert'); var assert = require('assert');
var web3 = require('../index.js'); var web3 = require('../index.js');
var u = require('./utils.js'); var u = require('./utils.js');

2
test/shh.methods.js

@ -1,5 +1,3 @@
require('es6-promise').polyfill();
var assert = require('assert'); var assert = require('assert');
var web3 = require('../index.js'); var web3 = require('../index.js');
var u = require('./utils.js'); var u = require('./utils.js');

2
test/web3.methods.js

@ -1,5 +1,3 @@
require('es6-promise').polyfill();
var assert = require('assert'); var assert = require('assert');
var web3 = require('../index.js'); var web3 = require('../index.js');
var u = require('./utils.js'); var u = require('./utils.js');

Loading…
Cancel
Save