quorum/cmd/mist/assets/ext/filter.js

67 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-10-23 06:48:53 -07:00
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301 USA
2014-09-13 15:13:47 -07:00
var ethx = {
prototype: Object,
watch: function(options) {
return new Filter(options);
},
note: function() {
var args = Array.prototype.slice.call(arguments, 0);
var o = []
for(var i = 0; i < args.length; i++) {
o.push(args[i].toString())
}
eth.notef(o);
},
};
2014-08-20 01:41:20 -07:00
var Filter = function(options) {
2014-09-13 15:13:47 -07:00
this.callbacks = [];
2014-08-20 01:41:20 -07:00
this.options = options;
2014-08-20 01:00:02 -07:00
2014-09-07 15:50:25 -07:00
if(options === "chain") {
2014-09-13 15:13:47 -07:00
this.id = eth.newFilterString(options);
2014-08-20 03:42:49 -07:00
} else if(typeof options === "object") {
2014-09-13 15:13:47 -07:00
this.id = eth.newFilter(options);
2014-08-20 03:42:49 -07:00
}
2014-08-20 01:00:02 -07:00
};
Filter.prototype.changed = function(callback) {
2014-09-13 15:13:47 -07:00
this.callbacks.push(callback);
2014-08-20 01:00:02 -07:00
var self = this;
2014-09-22 05:54:27 -07:00
messages.connect(function(messages, id) {
2014-09-13 15:13:47 -07:00
if(id == self.id) {
2014-09-22 05:54:27 -07:00
for(var i = 0; i < self.callbacks.length; i++) {
self.callbacks[i].call(self, messages);
}
2014-08-20 01:00:02 -07:00
}
});
};
Filter.prototype.uninstall = function() {
2014-09-13 15:13:47 -07:00
eth.uninstallFilter(this.id)
2014-08-20 01:00:02 -07:00
}
2014-08-20 01:41:20 -07:00
Filter.prototype.messages = function() {
2014-09-13 15:13:47 -07:00
return eth.messages(this.id)
2014-08-20 01:41:20 -07:00
}