diff options
Diffstat (limited to 'ethereal/assets/ext')
-rw-r--r-- | ethereal/assets/ext/ethereum.js | 32 | ||||
-rw-r--r-- | ethereal/assets/ext/test.html | 30 |
2 files changed, 60 insertions, 2 deletions
diff --git a/ethereal/assets/ext/ethereum.js b/ethereal/assets/ext/ethereum.js index 5b8fb54f3..5891fb9f9 100644 --- a/ethereal/assets/ext/ethereum.js +++ b/ethereal/assets/ext/ethereum.js @@ -137,6 +137,7 @@ window.eth = { postData({call: "getSecretToAddress", args: [sec]}, cb); }, + /* watch: function(address, storageAddrOrCb, cb) { var ev; if(cb === undefined) { @@ -166,6 +167,16 @@ window.eth = { postData({call: "disconnect", args: [address, storageAddrOrCb]}); }, + */ + + watch: function(options) { + var filter = new Filter(options); + filter.number = newWatchNum().toString() + + postData({call: "watch", args: [options, filter.number]}) + + return filter; + }, set: function(props) { postData({call: "set", args: props}); @@ -208,11 +219,28 @@ window.eth = { } } }, - - } + window.eth._callbacks = {} window.eth._onCallbacks = {} + +var Filter = function(options) { + this.options = options; +}; + +Filter.prototype.changed = function(callback) { + eth.on("watched:"+this.number, callback) +} + +Filter.prototype.getMessages = function(cb) { + return eth.getMessages(this.options, cb) +} + +var watchNum = 0; +function newWatchNum() { + return watchNum++; +} + function postData(data, cb) { data._seed = Math.floor(Math.random() * 1000000) if(cb) { diff --git a/ethereal/assets/ext/test.html b/ethereal/assets/ext/test.html new file mode 100644 index 000000000..b605e8dbd --- /dev/null +++ b/ethereal/assets/ext/test.html @@ -0,0 +1,30 @@ +<!doctype> +<html> +<head> +<title>Tests</title> +</head> + +<body> +<button onclick="test();">Test me</button> + +<script type="text/javascript"> +function test() { + var filter = eth.watch({ + latest: -1, + from: "e6716f9544a56c530d868e4bfbacb172315bdead", + }); + + filter.changed(function(messages) { + console.log("messages", messages) + }) + + filter.getMessages(function(messages) { + console.log("getMessages", messages) + }); + +} +</script> + +</body> + +</html> |