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:
- I have a TonClient4 and my Address;
- Get last block info:
const lastBlockInfo = await client.getLastBlock();
- Get account on this block:
const accountInfo = await client.getAccount(lastBlockInfo.last.seqno, address);
- Get account transactions:
const accountTransactions = await client.getAccountTransactions(address, BigInt(accountInfo.account.last.lt), Buffer.from(accountInfo.account.last.hash, 'base64'));
- From the list of transactions I get any transaction, for example this index=1:
const targetTransaction = accountTransactions;
There is two fields:
targetTransaction.tx field there is
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
getAccount method requires block number on
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:
- Is it realy so complicated to get parent message, or I missed some method or something else?
- 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.