github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/decache/locations_from_blocks.go (about) 1 package decache 2 3 import ( 4 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 5 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/cache" 6 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers" 7 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 9 ) 10 11 func LocationsFromBlocks(conn *rpc.Connection, ids []identifiers.Identifier) ([]cache.Locator, error) { 12 locations := make([]cache.Locator, 0) 13 for _, br := range ids { 14 blockNums, err := br.ResolveBlocks(conn.Chain) 15 if err != nil { 16 return nil, err 17 } 18 for _, bn := range blockNums { 19 block, err := conn.GetBlockHeaderByNumber(bn) 20 if err != nil { 21 return nil, err 22 } 23 // walk.Cache_Blocks 24 locations = append(locations, &types.LightBlock{ 25 BlockNumber: bn, 26 }) 27 28 // walk.Cache_Receipts 29 receiptGroup := &types.ReceiptGroup{ 30 BlockNumber: bn, 31 TransactionIndex: base.NOPOSN, 32 } 33 locations = append(locations, receiptGroup) 34 35 for index := range block.Transactions { 36 // walk.Cache_Transactions 37 locations = append(locations, &types.Transaction{ 38 BlockNumber: bn, 39 TransactionIndex: base.Txnum(index), 40 }) 41 42 // walk.Cache_Traces 43 locations = append(locations, &types.TraceGroup{ 44 BlockNumber: bn, 45 TransactionIndex: base.Txnum(index), 46 }) 47 } 48 } 49 } 50 return locations, nil 51 }