xssnick / tonutils-go

TON SDK Library in pure Golang for interacting with The Open Network ecosystem using native protocols, such as ADNL, RLDP and etc.
Apache License 2.0
540 stars 109 forks source link

Missing Jetton Transfers in Transaction Query #262

Open keyliaran opened 1 month ago

keyliaran commented 1 month ago

I'm attempting to retrieve transactions, but I am only receiving a single transaction involving TON transfer. Is it possible to also retrieve transactions with Jetton (USDT) transfers?

Explorer Link: TONSCAN Explorer

There should be two USDT transfers and one TON transfer visible for the address.

Code Sample:

package main

import (
    "context"
    "encoding/base64"
    "log"

    "github.com/xssnick/tonutils-go/address"
    "github.com/xssnick/tonutils-go/liteclient"
    "github.com/xssnick/tonutils-go/ton"
)

const (
    num = 10
)

func main() {
    client := liteclient.NewConnectionPool()
    err := client.AddConnectionsFromConfigUrl(context.Background(), "https://ton.org/global.config.json")
    if err != nil {
        panic(err)
    }

    api := ton.NewAPIClient(client, ton.ProofCheckPolicyFast).WithRetry()

    accountAddr := address.MustParseAddr("UQC7CECsMMrNJVcxJH8TlR-tK8yTS3gOC2JVvQdYyeC1RVZA")

    // we need fresh block info to run get methods
    b, err := api.CurrentMasterchainInfo(context.Background())
    if err != nil {
        log.Fatal(err)
    }

    // we use WaitForBlock to make sure block is ready,
    // it is optional but escapes us from liteserver block not ready errors
    res, err := api.WaitForBlock(b.SeqNo).GetAccount(context.Background(), b, accountAddr)
    if err != nil {
        log.Fatal(err)
    }

    lastTransactionId := res.LastTxHash
    lastTransactionLT := res.LastTxLT

    headSeen := false

    for {
        trxs, err := api.ListTransactions(context.Background(), accountAddr, num, lastTransactionLT, lastTransactionId)

        if err != nil {
            log.Fatal(err)
        }

        log.Printf("transaction count %d", len(trxs))

        for i, tx := range trxs {
            // should include only first time lastTransactionLT
            if !headSeen {
                headSeen = true
            } else if i == 0 {
                continue
            }

            if tx.IO.In == nil || tx.IO.In.Msg.SenderAddr().IsAddrNone() {
                // external message should be omitted
                continue
            }

            if tx.IO.Out != nil {
                // no outgoing messages - this is incoming Toncoins
                continue
            }

            // process trx
            log.Printf("found in transaction hash %s", base64.StdEncoding.EncodeToString(tx.Hash))
        }

        if len(trxs) == 0 || (headSeen && len(trxs) == 1) {
            break
        }

        lastTransactionId = trxs[0].Hash
        lastTransactionLT = trxs[0].LT
    }
}

Can you help me understand how to modify the code to retrieve Jetton transfer transactions alongside the TON transfer? Thanks!

xssnick commented 1 month ago

Hi, as i see in explorer you have only one out transaction and you see it, if you want to see incoming then remove tx.IO.Out != nil

keyliaran commented 1 month ago

Currently, I have 8 transactions in total: 6 involving TON (5 incoming, 1 outgoing). image When I call the following method:

trxs, err := api.ListTransactions(context.Background(), accountAddr, num, lastTransactionLT, lastTransactionId)

And log the number of transactions (output will be 6) log.Printf("transaction count %d", len(trxs))

I also print the transaction hashes (5 in msgs where i have recieved ton, and 1 out msg):

for i, tx := range trxs {
    log.Printf("found transaction hash %s", base64.StdEncoding.EncodeToString(tx.Hash))
}

However, I'm not receiving two transactions where I received USDT. The hashes for these missing transactions are: (5c508c90aa472e06fa063b9d0396fec1975e1f5760d982363b3035f5bf0f7122, eDdYeBMSmHRDDeYyRzlhmUAFg/MqlbAOOiGT4W+PRdA=)

These transactions don't appear in the response, and I'm unsure why they're missing. Any ideas on what might be causing this?