以太坊事件未显示但功能完成
Ethereum event not showing up but function completing
我有以下合同:
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);
});
唉。它刚刚开始工作,我正在向事件传递 uint
但它期待 int
.
我有以下合同:
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);
});
唉。它刚刚开始工作,我正在向事件传递 uint
但它期待 int
.