github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/internal/abis/handle_many.go (about) 1 package abisPkg 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" 8 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output" 9 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc" 10 "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types" 11 ) 12 13 func (opts *AbisOptions) HandleMany(rCtx *output.RenderCtx) (err error) { 14 fetchData := func(modelChan chan types.Modeler, errorChan chan error) { 15 for _, addr := range opts.Addrs { 16 functions, which, err := opts.LoadAbis([]string{addr}, false /* known */) 17 if err != nil { 18 if errors.Is(err, rpc.ErrNotAContract) { 19 msg := fmt.Errorf("address %s is not a smart contract", which) 20 errorChan <- msg 21 // Report but don't quit processing 22 } else { 23 // Cancel on all other errors 24 errorChan <- err 25 rCtx.Cancel() 26 // } else if len(opts.ProxyFor) > 0 { 27 // TODO: We need to copy the proxied-to ABI to the proxy (replacing) 28 } 29 } 30 31 abi := types.Abi{} 32 abi.Address = base.HexToAddress(addr) 33 for _, f := range functions { 34 abi.Functions = append(abi.Functions, *f) 35 } 36 modelChan <- &abi 37 } 38 } 39 40 return output.StreamMany(rCtx, fetchData, opts.Globals.OutputOpts()) 41 }