mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-24 03:58:13 +00:00
picked watch change3
This commit is contained in:
parent
56d13f72fb
commit
c62f817cc6
23
dist/web3-light.js
vendored
23
dist/web3-light.js
vendored
@ -2109,8 +2109,7 @@ var Filter = function (options, methods, formatter) {
|
|||||||
|
|
||||||
Filter.prototype.watch = function (callback) {
|
Filter.prototype.watch = function (callback) {
|
||||||
this.callbacks.push(callback);
|
this.callbacks.push(callback);
|
||||||
var self = this,
|
var self = this;
|
||||||
requestmanager = RequestManager.getInstance();
|
|
||||||
|
|
||||||
var onMessage = function (error, messages) {
|
var onMessage = function (error, messages) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -2129,10 +2128,19 @@ Filter.prototype.watch = function (callback) {
|
|||||||
|
|
||||||
// call getFilterLogs on start
|
// call getFilterLogs on start
|
||||||
if (!utils.isString(this.options)) {
|
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,
|
method: this.implementation.poll.call,
|
||||||
params: [this.filterId],
|
params: [this.filterId],
|
||||||
}, this.filterId, onMessage, this.stopWatching.bind(this));
|
}, this.filterId, onMessage, this.stopWatching.bind(this));
|
||||||
@ -2148,12 +2156,13 @@ 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){
|
this.implementation.getLogs(this.filterId, function(err, res){
|
||||||
if(!err) {
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
} else {
|
||||||
callback(null, res.map(function (log) {
|
callback(null, res.map(function (log) {
|
||||||
return self.formatter ? self.formatter(log) : log;
|
return self.formatter ? self.formatter(log) : log;
|
||||||
}));
|
}));
|
||||||
} else
|
}
|
||||||
callback(err);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var logs = this.implementation.getLogs(this.filterId);
|
var logs = this.implementation.getLogs(this.filterId);
|
||||||
|
4
dist/web3-light.js.map
vendored
4
dist/web3-light.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/web3-light.min.js
vendored
2
dist/web3-light.min.js
vendored
File diff suppressed because one or more lines are too long
23
dist/web3.js
vendored
23
dist/web3.js
vendored
@ -2109,8 +2109,7 @@ var Filter = function (options, methods, formatter) {
|
|||||||
|
|
||||||
Filter.prototype.watch = function (callback) {
|
Filter.prototype.watch = function (callback) {
|
||||||
this.callbacks.push(callback);
|
this.callbacks.push(callback);
|
||||||
var self = this,
|
var self = this;
|
||||||
requestmanager = RequestManager.getInstance();
|
|
||||||
|
|
||||||
var onMessage = function (error, messages) {
|
var onMessage = function (error, messages) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -2129,10 +2128,19 @@ Filter.prototype.watch = function (callback) {
|
|||||||
|
|
||||||
// call getFilterLogs on start
|
// call getFilterLogs on start
|
||||||
if (!utils.isString(this.options)) {
|
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,
|
method: this.implementation.poll.call,
|
||||||
params: [this.filterId],
|
params: [this.filterId],
|
||||||
}, this.filterId, onMessage, this.stopWatching.bind(this));
|
}, this.filterId, onMessage, this.stopWatching.bind(this));
|
||||||
@ -2148,12 +2156,13 @@ 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){
|
this.implementation.getLogs(this.filterId, function(err, res){
|
||||||
if(!err) {
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
} else {
|
||||||
callback(null, res.map(function (log) {
|
callback(null, res.map(function (log) {
|
||||||
return self.formatter ? self.formatter(log) : log;
|
return self.formatter ? self.formatter(log) : log;
|
||||||
}));
|
}));
|
||||||
} else
|
}
|
||||||
callback(err);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var logs = this.implementation.getLogs(this.filterId);
|
var logs = this.implementation.getLogs(this.filterId);
|
||||||
|
4
dist/web3.js.map
vendored
4
dist/web3.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/web3.min.js
vendored
4
dist/web3.min.js
vendored
File diff suppressed because one or more lines are too long
@ -69,8 +69,7 @@ var Filter = function (options, methods, formatter) {
|
|||||||
|
|
||||||
Filter.prototype.watch = function (callback) {
|
Filter.prototype.watch = function (callback) {
|
||||||
this.callbacks.push(callback);
|
this.callbacks.push(callback);
|
||||||
var self = this,
|
var self = this;
|
||||||
requestmanager = RequestManager.getInstance();
|
|
||||||
|
|
||||||
var onMessage = function (error, messages) {
|
var onMessage = function (error, messages) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -89,10 +88,19 @@ Filter.prototype.watch = function (callback) {
|
|||||||
|
|
||||||
// call getFilterLogs on start
|
// call getFilterLogs on start
|
||||||
if (!utils.isString(this.options)) {
|
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,
|
method: this.implementation.poll.call,
|
||||||
params: [this.filterId],
|
params: [this.filterId],
|
||||||
}, this.filterId, onMessage, this.stopWatching.bind(this));
|
}, this.filterId, onMessage, this.stopWatching.bind(this));
|
||||||
@ -108,12 +116,13 @@ 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){
|
this.implementation.getLogs(this.filterId, function(err, res){
|
||||||
if(!err) {
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
} else {
|
||||||
callback(null, res.map(function (log) {
|
callback(null, res.map(function (log) {
|
||||||
return self.formatter ? self.formatter(log) : log;
|
return self.formatter ? self.formatter(log) : log;
|
||||||
}));
|
}));
|
||||||
} else
|
}
|
||||||
callback(err);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var logs = this.implementation.getLogs(this.filterId);
|
var logs = this.implementation.getLogs(this.filterId);
|
||||||
|
@ -67,7 +67,22 @@ describe('web3.eth.contract', function () {
|
|||||||
],
|
],
|
||||||
address: '0x1234567890123456789012345678901234567890'
|
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([[{
|
provider.injectBatchResults([[{
|
||||||
address: address,
|
address: address,
|
||||||
topics: [
|
topics: [
|
||||||
@ -89,12 +104,16 @@ describe('web3.eth.contract', function () {
|
|||||||
var Contract = web3.eth.contract(desc);
|
var Contract = web3.eth.contract(desc);
|
||||||
var contract = new Contract(address);
|
var contract = new Contract(address);
|
||||||
|
|
||||||
|
var res = 0;
|
||||||
contract.Changed({from: address}).watch(function(err, result) {
|
contract.Changed({from: address}).watch(function(err, result) {
|
||||||
assert.equal(result.args.from, address);
|
assert.equal(result.args.from, address);
|
||||||
assert.equal(result.args.amount, 1);
|
assert.equal(result.args.amount, 1);
|
||||||
assert.equal(result.args.t1, 1);
|
assert.equal(result.args.t1, 1);
|
||||||
assert.equal(result.args.t2, 8);
|
assert.equal(result.args.t2, 8);
|
||||||
|
res++;
|
||||||
|
if (res === 2) {
|
||||||
done();
|
done();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user