Merge branch 'develop' into cpp

Conflicts:
	dist/ethereum.js.map
	dist/ethereum.min.js
This commit is contained in:
Marek Kotewicz 2015-01-27 09:36:39 +01:00
commit 1f5a6f1341
20 changed files with 78 additions and 68 deletions

View File

@ -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

View File

@ -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 vendored
View File

@ -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 vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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">

View File

@ -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">

View File

@ -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);
});

View File

@ -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;
}; };

View File

@ -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;

View File

@ -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]);
}
} }
}; };

View File

@ -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 Normal file
View File

@ -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;

View File

@ -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?

View File

@ -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' }
]; ];
}; };

View File

@ -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"

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');