This commit is contained in:
Marek Kotewicz 2015-01-31 04:09:48 +01:00
parent 80c97ca21b
commit 0b82a05a75
6 changed files with 63 additions and 19 deletions

14
dist/ethereum.js vendored
View File

@ -580,11 +580,9 @@ var web3 = require('./web3'); // jshint ignore:line
/// should be used when we want to watch something
/// it's using inner polling mechanism and is notified about changes
/// TODO: change 'options' name cause it may be not the best matching one, since we have events
var Filter = function(options, indexed, impl) {
var Filter = function(options, impl) {
if (options._isEvent) {
return options(indexed);
} else if (typeof options !== "string") {
if (typeof options !== "string") {
// topics property is deprecated, warn about it!
if (options.topics) {
@ -1432,7 +1430,10 @@ var web3 = {
/// @param filter may be a string, object or event
/// @param indexed is optional, this may be an object with optional event indexed params
watch: function (filter, indexed) {
return new web3.filter(filter, indexed, ethWatch);
if (filter._isEvent) {
return filter(indexed);
}
return new web3.filter(filter, ethWatch);
}
},
@ -1443,9 +1444,8 @@ var web3 = {
shh: {
/// @param filter may be a string, object or event
/// @param indexed is optional, this may be an object with optional event indexed params
watch: function (filter, indexed) {
return new web3.filter(filter, indexed, shhWatch);
return new web3.filter(filter, shhWatch);
}
},

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -27,25 +27,57 @@
var contract = web3.eth.contract(address, desc);
function test1() {
// "{"topic":["0x83c9849c","0xc4d76332"],"address":"0x01"}"
web3.eth.watch(contract).changed(function (res) {
});
};
function test2() {
// "{"topic":["0x83c9849c"],"address":"0x01"}"
web3.eth.watch(contract.Event).changed(function (res) {
});
};
function test3() {
// "{"topic":["0x83c9849c"],"address":"0x01"}"
contract.Event().changed(function (res) {
});
};
function test4() {
// "{"topic":["0x83c9849c","0000000000000000000000000000000000000000000000000000000000000045"],"address":"0x01"}"
contract.Event({a: 69}).changed(function (res) {
});
};
function test5() {
// "{"topic":["0x83c9849c",["0000000000000000000000000000000000000000000000000000000000000045","000000000000000000000000000000000000000000000000000000000000002a"]],"address":"0x01"}"
contract.Event({a: [69, 42]}).changed(function (res) {
});
};
function test6() {
// "{"topic":["0x83c9849c","000000000000000000000000000000000000000000000000000000000000001e"],"max":100,"address":"0x01"}"
contract.Event({a: 30}, {max: 100}).changed(function (res) {
});
};
function test7() {
// "{"topic":["0x83c9849c","000000000000000000000000000000000000000000000000000000000000001e"],"address":"0x01"}"
web3.eth.watch(contract.Event, {a: 30}).changed(function (res) {
});
};
// not valid
// function test4() {
// function testX() {
// web3.eth.watch([contract.Event, contract.Event2]).changed(function (res) {
// });
// };
@ -63,5 +95,17 @@
<div>
<button type="button" onClick="test3();">test3</button>
</div>
<div>
<button type="button" onClick="test4();">test4</button>
</div>
<div>
<button type="button" onClick="test5();">test5</button>
</div>
<div>
<button type="button" onClick="test6();">test6</button>
</div>
<div>
<button type="button" onClick="test7();">test7</button>
</div>
</body>
</html>

View File

@ -28,11 +28,9 @@ var web3 = require('./web3'); // jshint ignore:line
/// should be used when we want to watch something
/// it's using inner polling mechanism and is notified about changes
/// TODO: change 'options' name cause it may be not the best matching one, since we have events
var Filter = function(options, indexed, impl) {
var Filter = function(options, impl) {
if (options._isEvent) {
return options(indexed);
} else if (typeof options !== "string") {
if (typeof options !== "string") {
// topics property is deprecated, warn about it!
if (options.topics) {

View File

@ -282,7 +282,10 @@ var web3 = {
/// @param filter may be a string, object or event
/// @param indexed is optional, this may be an object with optional event indexed params
watch: function (filter, indexed) {
return new web3.filter(filter, indexed, ethWatch);
if (filter._isEvent) {
return filter(indexed);
}
return new web3.filter(filter, ethWatch);
}
},
@ -293,9 +296,8 @@ var web3 = {
shh: {
/// @param filter may be a string, object or event
/// @param indexed is optional, this may be an object with optional event indexed params
watch: function (filter, indexed) {
return new web3.filter(filter, indexed, shhWatch);
return new web3.filter(filter, shhWatch);
}
},