picked watch change3

This commit is contained in:
Marek Kotewicz 2015-04-09 09:15:04 +02:00 committed by Fabian Vogelsteller
parent 56d13f72fb
commit c62f817cc6
8 changed files with 79 additions and 33 deletions

23
dist/web3-light.js vendored
View File

@ -2109,8 +2109,7 @@ var Filter = function (options, methods, formatter) {
Filter.prototype.watch = function (callback) {
this.callbacks.push(callback);
var self = this,
requestmanager = RequestManager.getInstance();
var self = this;
var onMessage = function (error, messages) {
if (error) {
@ -2129,10 +2128,19 @@ Filter.prototype.watch = function (callback) {
// call getFilterLogs on start
if (!utils.isString(this.options)) {
this.get(onMessage);
this.get(function (err, messages) {
// don't send all the responses to all the watches again... just to this one
if (err) {
callback(err);
}
requestmanager.startPolling({
messages.forEach(function (message) {
callback(null, message);
});
});
}
RequestManager.getInstance().startPolling({
method: this.implementation.poll.call,
params: [this.filterId],
}, this.filterId, onMessage, this.stopWatching.bind(this));
@ -2148,12 +2156,13 @@ Filter.prototype.get = function (callback) {
var self = this;
if (utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){
if(!err) {
if (err) {
callback(err);
} else {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
} else
callback(err);
}
});
} else {
var logs = this.implementation.getLogs(this.filterId);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

23
dist/web3.js vendored
View File

@ -2109,8 +2109,7 @@ var Filter = function (options, methods, formatter) {
Filter.prototype.watch = function (callback) {
this.callbacks.push(callback);
var self = this,
requestmanager = RequestManager.getInstance();
var self = this;
var onMessage = function (error, messages) {
if (error) {
@ -2129,10 +2128,19 @@ Filter.prototype.watch = function (callback) {
// call getFilterLogs on start
if (!utils.isString(this.options)) {
this.get(onMessage);
this.get(function (err, messages) {
// don't send all the responses to all the watches again... just to this one
if (err) {
callback(err);
}
requestmanager.startPolling({
messages.forEach(function (message) {
callback(null, message);
});
});
}
RequestManager.getInstance().startPolling({
method: this.implementation.poll.call,
params: [this.filterId],
}, this.filterId, onMessage, this.stopWatching.bind(this));
@ -2148,12 +2156,13 @@ Filter.prototype.get = function (callback) {
var self = this;
if (utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){
if(!err) {
if (err) {
callback(err);
} else {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
} else
callback(err);
}
});
} else {
var logs = this.implementation.getLogs(this.filterId);

4
dist/web3.js.map vendored

File diff suppressed because one or more lines are too long

4
dist/web3.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -69,8 +69,7 @@ var Filter = function (options, methods, formatter) {
Filter.prototype.watch = function (callback) {
this.callbacks.push(callback);
var self = this,
requestmanager = RequestManager.getInstance();
var self = this;
var onMessage = function (error, messages) {
if (error) {
@ -89,10 +88,19 @@ Filter.prototype.watch = function (callback) {
// call getFilterLogs on start
if (!utils.isString(this.options)) {
this.get(onMessage);
this.get(function (err, messages) {
// don't send all the responses to all the watches again... just to this one
if (err) {
callback(err);
}
requestmanager.startPolling({
messages.forEach(function (message) {
callback(null, message);
});
});
}
RequestManager.getInstance().startPolling({
method: this.implementation.poll.call,
params: [this.filterId],
}, this.filterId, onMessage, this.stopWatching.bind(this));
@ -108,12 +116,13 @@ Filter.prototype.get = function (callback) {
var self = this;
if (utils.isFunction(callback)) {
this.implementation.getLogs(this.filterId, function(err, res){
if(!err) {
if (err) {
callback(err);
} else {
callback(null, res.map(function (log) {
return self.formatter ? self.formatter(log) : log;
}));
} else
callback(err);
}
});
} else {
var logs = this.implementation.getLogs(this.filterId);

View File

@ -67,7 +67,22 @@ describe('web3.eth.contract', function () {
],
address: '0x1234567890123456789012345678901234567890'
});
} else if (step === 2 && utils.isArray(payload)) {
} else if (step === 2) {
step = 3;
provider.injectResult([{
address: address,
topics: [
sha3,
'0x0000000000000000000000001234567890123456789012345678901234567890',
'0x0000000000000000000000000000000000000000000000000000000000000001'
],
number: 2,
data: '0x0000000000000000000000000000000000000000000000000000000000000001' +
'0000000000000000000000000000000000000000000000000000000000000008'
}]);
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_getFilterLogs');
} else if (step === 3 && utils.isArray(payload)) {
provider.injectBatchResults([[{
address: address,
topics: [
@ -89,12 +104,16 @@ describe('web3.eth.contract', function () {
var Contract = web3.eth.contract(desc);
var contract = new Contract(address);
var res = 0;
contract.Changed({from: address}).watch(function(err, result) {
assert.equal(result.args.from, address);
assert.equal(result.args.amount, 1);
assert.equal(result.args.t1, 1);
assert.equal(result.args.t2, 8);
res++;
if (res === 2) {
done();
}
});
});