github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/rpc/get_traces_parts.go (about) 1 // Copyright 2021 The TrueBlocks Authors. All rights reserved. 2 // Use of this source code is governed by a license that can 3 // be found in the LICENSE file. 4 5 package rpc 6 7 import ( 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 10 ) 11 12 // GetTracesByTransactionId returns a slice of traces in a given transaction 13 func (conn *Connection) GetTracesByTransactionId(bn base.Blknum, txid base.Txnum) ([]types.Trace, error) { 14 if conn.StoreReadable() { 15 // walk.Cache_Traces 16 traceGroup := &types.TraceGroup{ 17 BlockNumber: bn, 18 TransactionIndex: txid, 19 } 20 if err := conn.Store.Read(traceGroup, nil); err == nil { 21 return traceGroup.Traces, nil 22 } 23 } 24 25 tx, err := conn.GetTransactionByNumberAndId(bn, txid) 26 if err != nil { 27 return []types.Trace{{ 28 Action: &types.TraceAction{}, 29 Result: &types.TraceResult{}, 30 }}, err 31 } 32 33 return conn.GetTracesByTransactionHash(tx.Hash.Hex(), tx) 34 } 35 36 // GetTracesCountInBlock returns the number of traces in a block 37 func (conn *Connection) GetTracesCountInBlock(bn base.Blknum) (uint64, error) { 38 if traces, err := conn.GetTracesByBlockNumber(bn); err != nil { 39 return base.NOPOS, err 40 } else { 41 return uint64(len(traces)), nil 42 } 43 }