Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
How to correct parse full message-graph for smart-contract call?

Hi everione

I try to understand logic of work API v4.
In general I have a aim to get full graph of messages for some smart-contract call.

I use next algorithm:

  1. I have a TonClient4 and my Address;
  2. Get last block info: const lastBlockInfo = await client.getLastBlock();
  3. Get account on this block: const accountInfo = await client.getAccount(lastBlockInfo.last.seqno, address);
  4. Get account transactions: const accountTransactions = await client.getAccountTransactions(address, BigInt(accountInfo.account.last.lt), Buffer.from(accountInfo.account.last.hash, 'base64'));
  5. From the list of transactions I get any transaction, for example this index=1: const targetTransaction = accountTransactions[1];

There is two fields: targetTransaction.tx and targetTransaction.block.
In targetTransaction.tx field there is targetTransaction.tx.inMessage field.
If type of this message is internal, I have to find "parent" message of this, message. But it looks that I have only address of source of this message and it logical time.
So I need get list of transaction of source account and in this list find transaction which has outMessage with the same logical time.
But for this I have to call client.getAccount(???, targetTransaction.tx.inMessage.src) - here ??? - it's a block number.
Of course I can use lastBlockInfo.last.seqno, but it is not universal solution for historical messages.
At first I thought, that I can use targetTransaction.block.seqno, but as I understud it's a number of block on workchain=0, but getAccount method requires block number on workchain=-1;

I decided to check method getBlockByUtime: const blockByTime = await client.getBlockByUtime(targetTransaction.tx.inMessage.info.createdAt);
In the result I see two shards: one for workchain=0, and one for workchain=-1. It seems that seqno from shard with workchain=-1 can be used, but I surprised that for workchain=0 I see block number not equal to targetTransaction.block.seqno, but previous one.

So from this point I have a questions:

  1. Is it realy so complicated to get parent message, or I missed some method or something else?
  2. How much can I trust method getBlockByUtime? Is it possible that for some unix time I will (not get block)/(get next block)/(any options)?

Thanks for your attention. I will be grateful for any help.

Votes Newest

Answers


1/ Is it realy so complicated to get parent message, or I missed some method or something else?

=> This is out of my knowledge.

2/ How much can I trust method getBlockByUtime? Is it possible that for some unix time I will (not get block)/(get next block)/(any options)?

=> getBlockByUtime is a method used to fetch a block that was produced closest to a given Unix time. It's not 100% precise due to the fact that block times are not strictly enforced in the protocol, and there's network latency and other factors at play.

So while you can generally trust getBlockByUtime to give you a block close to the specified Unix time, you should not rely on it to provide a perfectly accurate block for a precise moment in time. It's always a good practice to handle edge cases where you might not get a block or get a subsequent block.

Also note that this method might return blocks from different shardchains for the same time since different shardchains are essentially separate blockchains running in parallel.

  
  
Posted 6 months ago
Edited 6 months ago
9K Views
1 Answer
6 months ago
6 months ago
Tags