Giter Site home page Giter Site logo

Comments (7)

xssnick avatar xssnick commented on August 27, 2024 1

For master chain yes, it is constants

from tonutils-go.

xssnick avatar xssnick commented on August 27, 2024

Hi, you could use GetBlockTransactionsV2 method. Usage example can be found in block-scan.

from tonutils-go.

xssnick avatar xssnick commented on August 27, 2024

In TON, there could be many parallel blocks in the same time because of sharding. In block-scan example we taking latest masterchain block (and each next when available), then getting basechain shard blocks related to master block and getting transactions for each shard block.

from tonutils-go.

hlee4real avatar hlee4real commented on August 27, 2024

Hi, I've tried and follow your block-scan. It works for new blocks and new shards. but what exact i'm trying to find is scan transactions in the past of a block. you can follow this url for example:
https://tonwhales.com/explorer/block/30283112

from tonutils-go.

xssnick avatar xssnick commented on August 27, 2024

Prepared example for you, it is doing what you need:

func main() {
	client := liteclient.NewConnectionPool()

	// connect to mainnet lite servers
	err := client.AddConnectionsFromConfigUrl(context.Background(), "https://ton-blockchain.github.io/global.config.json")
	if err != nil {
		log.Fatalln("connection err: ", err.Error())
		return
	}

	// initialize ton api lite connection wrapper
	api := ton.NewAPIClient(client)

	// find master block
	master, err := api.LookupBlock(context.Background(), -1, -0x8000000000000000, 30283112)
	if err != nil {
		log.Fatalln("get masterchain info err: ", err.Error())
		return
	}

	// find it's shard blocks
	currentShards, err := api.GetBlockShardsInfo(context.Background(), master)
	if err != nil {
		log.Fatalln("get shards err:", err.Error())
		return
	}

	// we also want to see master block transactions
	currentShards = append(currentShards, master)

	for _, shard := range currentShards {
		var fetchedIDs []ton.TransactionShortInfo
		var after *ton.TransactionID3
		var more = true

		// load all transactions in batches with 100 transactions in each while exists
		for more {
			fetchedIDs, more, err = api.GetBlockTransactionsV2(context.Background(), shard, 100, after)
			if err != nil {
				log.Fatalln("get tx ids err:", err.Error())
				return
			}

			if more {
				// set load offset for next query (pagination)
				after = fetchedIDs[len(fetchedIDs)-1].ID3()
			}

			for _, id := range fetchedIDs {
				// get full transaction by id
				tx, err := api.GetTransaction(context.Background(), shard, address.NewAddress(0, byte(shard.Workchain), id.Account), id.LT)
				if err != nil {
					log.Fatalln("get tx data err:", err.Error())
					return
				}
				log.Println(tx.String())
			}
		}
	}
}

from tonutils-go.

hlee4real avatar hlee4real commented on August 27, 2024

Thank you so much for answering my question so quickly. but let me ask about shard and workchain when calling LookupBlock function. Is that the default set value and will it always be? workchain=-1 and shard=. -0x8000000000000000

from tonutils-go.

hlee4real avatar hlee4real commented on August 27, 2024

great. so that I just need to change seqno to scan another blocks from your example right?

from tonutils-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.