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.implementation = implementation;
this.filterId = null; this.filterId = null;
this.callbacks = []; this.callbacks = [];
this.getLogsCallbacks = [];
this.pollFilters = []; this.pollFilters = [];
this.formatter = formatter; this.formatter = formatter;
this.implementation.newFilter(this.options, function(error, id){ this.implementation.newFilter(this.options, function(error, id){
@ -3423,6 +3424,13 @@ var Filter = function (options, methods, formatter, callback) {
} else { } else {
self.filterId = id; 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 // get filter logs for the already existing watch calls
self.callbacks.forEach(function(cb){ self.callbacks.forEach(function(cb){
getLogsAtStart(self, cb); getLogsAtStart(self, cb);
@ -3461,16 +3469,25 @@ Filter.prototype.stopWatching = function () {
Filter.prototype.get = function (callback) { Filter.prototype.get = function (callback) {
var self = this; var self = this;
if (utils.isFunction(callback)) { if (utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){ if (this.filterId === null) {
if (err) { // If filterId is not set yet, call it back
callback(err); // when newFilter() assigns it.
} else { this.getLogsCallbacks.push(callback);
callback(null, res.map(function (log) { } else {
return self.formatter ? self.formatter(log) : log; 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 { } 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); var logs = this.implementation.getLogs(this.filterId);
return logs.map(function (log) { return logs.map(function (log) {
return self.formatter ? self.formatter(log) : 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.implementation = implementation;
this.filterId = null; this.filterId = null;
this.callbacks = []; this.callbacks = [];
this.getLogsCallbacks = [];
this.pollFilters = []; this.pollFilters = [];
this.formatter = formatter; this.formatter = formatter;
this.implementation.newFilter(this.options, function(error, id){ this.implementation.newFilter(this.options, function(error, id){
@ -3423,6 +3424,13 @@ var Filter = function (options, methods, formatter, callback) {
} else { } else {
self.filterId = id; 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 // get filter logs for the already existing watch calls
self.callbacks.forEach(function(cb){ self.callbacks.forEach(function(cb){
getLogsAtStart(self, cb); getLogsAtStart(self, cb);
@ -3461,16 +3469,25 @@ Filter.prototype.stopWatching = function () {
Filter.prototype.get = function (callback) { Filter.prototype.get = function (callback) {
var self = this; var self = this;
if (utils.isFunction(callback)) { if (utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){ if (this.filterId === null) {
if (err) { // If filterId is not set yet, call it back
callback(err); // when newFilter() assigns it.
} else { this.getLogsCallbacks.push(callback);
callback(null, res.map(function (log) { } else {
return self.formatter ? self.formatter(log) : log; 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 { } 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); var logs = this.implementation.getLogs(this.filterId);
return logs.map(function (log) { return logs.map(function (log) {
return self.formatter ? self.formatter(log) : 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.implementation = implementation;
this.filterId = null; this.filterId = null;
this.callbacks = []; this.callbacks = [];
this.getLogsCallbacks = [];
this.pollFilters = []; this.pollFilters = [];
this.formatter = formatter; this.formatter = formatter;
this.implementation.newFilter(this.options, function(error, id){ this.implementation.newFilter(this.options, function(error, id){
@ -151,6 +152,13 @@ var Filter = function (options, methods, formatter, callback) {
} else { } else {
self.filterId = id; 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 // get filter logs for the already existing watch calls
self.callbacks.forEach(function(cb){ self.callbacks.forEach(function(cb){
getLogsAtStart(self, cb); getLogsAtStart(self, cb);
@ -189,16 +197,25 @@ Filter.prototype.stopWatching = function () {
Filter.prototype.get = function (callback) { Filter.prototype.get = function (callback) {
var self = this; var self = this;
if (utils.isFunction(callback)) { if (utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){ if (this.filterId === null) {
if (err) { // If filterId is not set yet, call it back
callback(err); // when newFilter() assigns it.
} else { this.getLogsCallbacks.push(callback);
callback(null, res.map(function (log) { } else {
return self.formatter ? self.formatter(log) : log; 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 { } 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); var logs = this.implementation.getLogs(this.filterId);
return logs.map(function (log) { return logs.map(function (log) {
return self.formatter ? self.formatter(log) : log; return self.formatter ? self.formatter(log) : log;

View File

@ -54,23 +54,46 @@ describe('web3.eth', function () {
describe(method, function () { describe(method, function () {
tests.forEach(function (test, index) { tests.forEach(function (test, index) {
it('property test: ' + index, 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);
});
// call // given
web3.eth[method].apply(null, test.args); 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
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();
});
}
}); });
}); });
}); });
}); });