I have the following contract:
Contract Store{
event Purchase(address buyer, int item_id);
struct Product {
string name;
uint price;
string desc;
uint quantity;
bool enabled;
}
mapping (address => int) balances;
function buyProduct(uint id) returns(bool){
if(products[id].quantity <= 0){ return false; }
balances[msg.sender] = balances[msg.sender] - int(products[id].price);
products[id].quantity--;
Purchase(msg.sender, id);
return true;
}
}
When I use web3 to purchase a product with Store.buyProduct, the product purchase is made, but the event doesn't fire on the front-end. Here is my event watcher code:
var eventFilter = Store.deployed().Purchase({from: "0xe02b4fc50f429624937e9425e1243292857291e2"}, {fromBlock: 0, toBlock: 'latest'});
eventFilter.watch(function(error, event){
console.log('hai');
console.log(event);
});