Comments (11)
@forhas
we all left tron so maybe don't expected those issue to be fixed
from tronweb.
In case it might help anyone, this is the code I'm using instead of using contract.Method().watch
to discover the events due to this problem (seems to work reliably for recent events).
(Note that the 60 seconds on the first line is to allow for the fact that the newly loaded events will have timestamps in the past, and when onlyConfirmed is on, this gap will include the time it takes for the transaction to confirm on the solidity node. Even without onlyConfirmed there should still be at least 3 seconds because of waiting for the interval to trigger and this is also the maximum time since the previous block was mined.)
let last_event_timestamp = Date.now() - 60000;
let processing = false;
setInterval(async () => {
if (processing) return;
processing = true;
try {
let events = [];
let more_events =
await tronWeb.getEventResult(CONTRACT_ADDRESS, {
onlyConfirmed: true,
sinceTimestamp: last_event_timestamp + 1,
sort: 'block_timestamp'
});
while (more_events.length
&& more_events[more_events.length - 1].fingerprint) {
events = events.concat(more_events);
more_events =
await tronWeb.getEventResult(CONTRACT_ADDRESS, {
onlyConfirmed: true,
previousLastEventFingerprint:
more_events[more_events.length - 1].fingerprint,
sort: 'block_timestamp'
});
}
events = events.concat(more_events);
if (events.length) {
last_event_timestamp = events[events.length - 1].timestamp;
for (let i = 0; i < events.length; ++i) {
if (events[i].name == 'Method') {
/*...*/
} else if (events[i].name == /*...*/) {
/*...*/
/*...*/
} else {
console.error('Unrecognized event name:', events[i].name);
}
}
}
} catch (err) {
console.error('Error getting events:', err);
}
processing = false;
}, 3000);
This also has the advantage that it only does one request for all possible events that can be emitted by the contract. If you wanted you could add the eventName parameter to the options for getEventResult so you wouldn't have to check the name.
Maybe the contract.Method().watch
functionality could use logic similar to this to achieve the desired effect.
from tronweb.
If you want to be sure you get all the events in a block, you can use TronGridJS API and retrieve the events by block. Look at https://github.com/TRON-US/trongrid-js/blob/master/test/unit/lib/block.test.js for examples.
from tronweb.
To solve the issue we will add web sockets in the future.
from tronweb.
I'll take a look at your code.
from tronweb.
Hi @sullof,
Do you know if this one is expected to be resolved anytime soon?
from tronweb.
@UnforgivenZZZ thanks for clarifying.
Is the project still maintained (by anyone)?
from tronweb.
It looks like last merge was 21 days ago by @jeancky.
from tronweb.
@sullof , @forhas is there any update on this issue? For our poker game, event listening is still not working correctly. Some events get lost.
from tronweb.
@tigfamon I did not get the chance to test the latest version.
I've implemented my own manual solution:
setInterval(getEvents, tronBlockTime * pullCycle);
async function getEvents() {
if (isRunning) {
return;
}
isRunning = true;
try {
const latestBlock = await tronWeb.trx.getBlock('latest');
let start = latestEventsBlockNumber;
let end = latestBlock.block_header.raw_data.number;
const eventsArr = [];
for (let i = start; i < end; i++) {
eventsPullingOptions.block_number = i;
const events = await tronGrid.contract.getEvents(playzaContractAddress, eventsPullingOptions);
const blockEvents = await events.data;
if (blockEvents && blockEvents.length > 0) {
eventsArr.push(...blockEvents);
}
}
latestEventsBlockNumber = end;
handleEvents(eventsArr);
} catch (err) {
// handle errors
}
} finally {
isRunning = false;
}
}
from tronweb.
@sullof bro, is the problem still not fixed? Can you please correct this misunderstanding, this is a lot of problems 😔
from tronweb.
Related Issues (20)
- How to activate an account with this module? HOT 2
- Open DApp by Deeplink not work HOT 1
- how to estimate bandwidth and get same value as on tronscan HOT 4
- feature request: deserialize `raw_data_hex` into transaction HOT 4
- contract.send() option `pollTimes` not working in TronLink HOT 2
- check address by method isAddress return false HOT 7
- updateAccountPermissions fail Failed to sign transaction: Invalid transaction provided HOT 2
- Error: crypto.getRandomValues must be defined HOT 1
- Depends on vulnerable version of axios HOT 8
- `Assertion failed` during sign HOT 14
- `Failed to sign transaction by v2: Invalid transaction provided` when signing a hash message in browser HOT 7
- TransactionBuilder should not modify original params, please make a clone first HOT 1
- `TronWeb.sha3` result differs from `TronWeb.utils.ethersUtils.keccak256` when hashing hex string HOT 2
- How to detect usdt transaction from the block
- How to get info about TRC20 transaction HOT 1
- Cannot find module '@noble/hashes/sha3' (Yarn PnP) HOT 9
- error on call tronWeb.utils.abi.decodeParamsV2ByABI() HOT 1
- TronWeb and ethers lib generate different addresses HOT 1
- Todo List 'Activity
- Detect crypto payment (USDT TRC20) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tronweb.