I currently am using Oraclize in my contract and I make a call to a contract function from my front-end and don't want to continue onto the next call until the Oraclize function has returned. So I decided to use an event with a filter, and it works perfectly the first time, then on the next calls it doesn't actually wait for the Oraclize function to return again, it just takes the return value from the previous Oraclize function and uses that because its using the old logged event, and not waiting for the newest one.
This leads me to question why my filter is listening/uses the event emitted from the smart contract in the last call, instead of waiting on the new event to be called. It later returns the new Oraclize value if I don't use myEvent.stopListening() so I know Oraclize is still working after the first call.
My question is how do you only listen/react to the last event? Right now it's taking whatever event was fired before and being triggered off that.
Here's my front-end code watching the event:
I've tried also using various combinations for the filter such as: {fromBlock: 'latest', toBlock:'latest} or {fromBlock: 'latest'}
neither actually work at all, they don't ever fire the first time, then if I call the function again they have the same problem and instantly fire on the previous logged event.
Can someone explain to me what 'latest' does, for I seem to have a bad understanding. Also if this makes any difference my Event call in my smart contract takes place in the __callback() from Oraclize, and my front-end watching code is placed in a callback where the user clicks a button and enters a number and sends the transaction. Is the placement inside a callback function causing this weird error?
Thanks for any help or understanding, I have gone through the documentation on both contract events and web3.eth.filters but have been unable to figure this out. Sorry for the massive wall of text.
TL:DR How do you get your watch() to only look for new event logs, not react to past event logs that were triggered? Thank you!
num.watch
notcontractInstance.watch