我有以下合同:
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;
}
}
当我使用 web3 购买带有 的产品时Store.buyProduct
,会进行产品购买,但该事件不会在前端触发。这是我的事件观察程序代码:
var eventFilter = Store.deployed().Purchase({from: "0xe02b4fc50f429624937e9425e1243292857291e2"}, {fromBlock: 0, toBlock: 'latest'});
eventFilter.watch(function(error, event){
console.log('hai');
console.log(event);
});