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

     1  package transactionsPkg
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
     7  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
     8  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
     9  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
    10  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/uniq"
    11  	"github.com/ethereum/go-ethereum"
    12  )
    13  
    14  func (opts *TransactionsOptions) HandleUniq(rCtx *output.RenderCtx) (err error) {
    15  	chain := opts.Globals.Chain
    16  
    17  	fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
    18  		showProgress := opts.Globals.ShowProgress()
    19  		bar := logger.NewBar(logger.BarOptions{
    20  			Type:    logger.Expanding,
    21  			Enabled: showProgress,
    22  			Total:   250, // estimate since we have no idea how many there are
    23  		})
    24  		procFunc := func(s *types.Appearance) error {
    25  			bar.Tick()
    26  			modelChan <- s
    27  			return nil
    28  		}
    29  
    30  		for _, rng := range opts.TransactionIds {
    31  			apps, err := rng.ResolveTxs(chain)
    32  			if err != nil && !errors.Is(err, ethereum.NotFound) {
    33  				errorChan <- err
    34  				rCtx.Cancel()
    35  			}
    36  
    37  			for _, app := range apps {
    38  				app := types.Appearance{
    39  					BlockNumber:      app.BlockNumber,
    40  					TransactionIndex: app.TransactionIndex,
    41  				}
    42  				bn := base.Blknum(app.BlockNumber)
    43  				ts := opts.Conn.GetBlockTimestamp(bn)
    44  				addrMap := make(uniq.AddressBooleanMap)
    45  				if trans, err := opts.Conn.GetTransactionByAppearance(&app, true); err != nil {
    46  					errorChan <- err
    47  				} else {
    48  					if err = uniq.GetUniqAddressesInTransaction(chain, procFunc, opts.Flow, trans, ts, addrMap, opts.Conn); err != nil {
    49  						errorChan <- err
    50  					}
    51  				}
    52  			}
    53  		}
    54  		bar.Finish(true /* newLine */)
    55  	}
    56  
    57  	extraOpts := map[string]any{
    58  		"uniq": true,
    59  	}
    60  	return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOptsWithExtra(extraOpts))
    61  }