merged develop

This commit is contained in:
Fabian Vogelsteller 2015-09-15 15:43:41 +02:00
commit b1e91b48d6
7 changed files with 126 additions and 50 deletions

35
dist/web3-light.js vendored
View File

@ -3413,6 +3413,7 @@ var Filter = function (options, methods, formatter, callback) {
this.implementation = implementation;
this.filterId = null;
this.callbacks = [];
this.getLogsCallbacks = [];
this.pollFilters = [];
this.formatter = formatter;
this.implementation.newFilter(this.options, function(error, id){
@ -3423,6 +3424,13 @@ var Filter = function (options, methods, formatter, callback) {
} else {
self.filterId = id;
// check if there are get pending callbacks as a consequence
// of calling get() with filterId unassigned.
self.getLogsCallbacks.forEach(function (cb){
self.get(cb);
});
self.getLogsCallbacks = [];
// get filter logs for the already existing watch calls
self.callbacks.forEach(function(cb){
getLogsAtStart(self, cb);
@ -3461,16 +3469,25 @@ Filter.prototype.stopWatching = function () {
Filter.prototype.get = function (callback) {
var self = this;
if (utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){
if (err) {
callback(err);
} else {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
}
});
if (this.filterId === null) {
// If filterId is not set yet, call it back
// when newFilter() assigns it.
this.getLogsCallbacks.push(callback);
} else {
this.implementation.getLogs(this.filterId, function(err, res){
if (err) {
callback(err);
} else {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
}
});
}
} else {
if (this.filterId === null) {
throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.');
}
var logs = this.implementation.getLogs(this.filterId);
return logs.map(function (log) {
return self.formatter ? self.formatter(log) : log;

File diff suppressed because one or more lines are too long

35
dist/web3.js vendored
View File

@ -3413,6 +3413,7 @@ var Filter = function (options, methods, formatter, callback) {
this.implementation = implementation;
this.filterId = null;
this.callbacks = [];
this.getLogsCallbacks = [];
this.pollFilters = [];
this.formatter = formatter;
this.implementation.newFilter(this.options, function(error, id){
@ -3423,6 +3424,13 @@ var Filter = function (options, methods, formatter, callback) {
} else {
self.filterId = id;
// check if there are get pending callbacks as a consequence
// of calling get() with filterId unassigned.
self.getLogsCallbacks.forEach(function (cb){
self.get(cb);
});
self.getLogsCallbacks = [];
// get filter logs for the already existing watch calls
self.callbacks.forEach(function(cb){
getLogsAtStart(self, cb);
@ -3461,16 +3469,25 @@ Filter.prototype.stopWatching = function () {
Filter.prototype.get = function (callback) {
var self = this;
if (utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){
if (err) {
callback(err);
} else {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
}
});
if (this.filterId === null) {
// If filterId is not set yet, call it back
// when newFilter() assigns it.
this.getLogsCallbacks.push(callback);
} else {
this.implementation.getLogs(this.filterId, function(err, res){
if (err) {
callback(err);
} else {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
}
});
}
} else {
if (this.filterId === null) {
throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.');
}
var logs = this.implementation.getLogs(this.filterId);
return logs.map(function (log) {
return self.formatter ? self.formatter(log) : log;

4
dist/web3.js.map vendored

File diff suppressed because one or more lines are too long

7
dist/web3.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -141,6 +141,7 @@ var Filter = function (options, methods, formatter, callback) {
this.implementation = implementation;
this.filterId = null;
this.callbacks = [];
this.getLogsCallbacks = [];
this.pollFilters = [];
this.formatter = formatter;
this.implementation.newFilter(this.options, function(error, id){
@ -151,6 +152,13 @@ var Filter = function (options, methods, formatter, callback) {
} else {
self.filterId = id;
// check if there are get pending callbacks as a consequence
// of calling get() with filterId unassigned.
self.getLogsCallbacks.forEach(function (cb){
self.get(cb);
});
self.getLogsCallbacks = [];
// get filter logs for the already existing watch calls
self.callbacks.forEach(function(cb){
getLogsAtStart(self, cb);
@ -189,16 +197,25 @@ Filter.prototype.stopWatching = function () {
Filter.prototype.get = function (callback) {
var self = this;
if (utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){
if (err) {
callback(err);
} else {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
}
});
if (this.filterId === null) {
// If filterId is not set yet, call it back
// when newFilter() assigns it.
this.getLogsCallbacks.push(callback);
} else {
this.implementation.getLogs(this.filterId, function(err, res){
if (err) {
callback(err);
} else {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
}
});
}
} else {
if (this.filterId === null) {
throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.');
}
var logs = this.implementation.getLogs(this.filterId);
return logs.map(function (log) {
return self.formatter ? self.formatter(log) : log;

View File

@ -56,21 +56,44 @@ describe('web3.eth', function () {
it('property test: ' + index, function () {
// given
var provider = new FakeHttpProvider();
web3.setProvider(provider);
provider.injectResult(test.result);
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, test.call);
assert.deepEqual(payload.params, test.formattedArgs);
});
var provider = new FakeHttpProvider();
web3.setProvider(provider);
provider.injectResult(test.result);
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, test.call);
assert.deepEqual(payload.params, test.formattedArgs);
});
// call
web3.eth[method].apply(null, test.args);
// call
var filter = web3.eth[method].apply(null, test.args);
// test filter.get
if(typeof test.args === 'object') {
var logs = [{data: '0xb'}, {data: '0x11'}];
provider.injectResult(logs);
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_getFilterLogs');
assert.deepEqual(payload.params, [test.formattedResult]);
});
// sync should throw an error
try {
assert.throws(filter.get());
} catch(e){
assert.instanceOf(e, Error);
}
// async should get the fake logs
filter.get(function(e, res){
assert.equal(logs, res);
done();
});
}
});
});
});
});