github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/slurp/handle_show.go (about)

     1  package slurpPkg
     2  
     3  import (
     4  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/articulate"
     5  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
     6  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
     7  )
     8  
     9  func (opts *SlurpOptions) HandleShow(rCtx *output.RenderCtx) error {
    10  	abiCache := articulate.NewAbiCache(opts.Conn, opts.Articulate)
    11  
    12  	provider, err := opts.Provider()
    13  	if err != nil {
    14  		return err
    15  	}
    16  	provider.SetPrintProgress(opts.Globals.ShowProgress())
    17  
    18  	fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
    19  		txChan := provider.TransactionsByAddress(rCtx.Ctx, opts.Query(), errorChan)
    20  		for tx := range txChan {
    21  			if opts.Articulate {
    22  				if err := abiCache.ArticulateSlurp(&tx); err != nil {
    23  					errorChan <- err // continue even with an error
    24  				}
    25  			}
    26  			modelChan <- &tx
    27  		}
    28  	}
    29  
    30  	extraOpts := map[string]any{
    31  		"articulate": opts.Articulate,
    32  	}
    33  
    34  	return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOptsWithExtra(extraOpts))
    35  }