Skip to content

Commit

Permalink
Merge pull request #3446 from TrueBlocks/3423-slurp-articulate
Browse files Browse the repository at this point in the history
3423 slurp articulate
  • Loading branch information
tjayrush authored Dec 6, 2023
2 parents d3b6674 + 8725f45 commit c495c3a
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/content/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,14 @@ paths:
explode: true
schema:
type: boolean
- name: articulate
description: articulate the retrieved data if ABIs can be found
required: false
style: form
in: query
explode: true
schema:
type: boolean
- name: perPage
description: the number of records to request on each page
required: false
Expand Down
1 change: 1 addition & 0 deletions docs/content/chifra/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions docs/readmes/other-slurp.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions sdk/python/src/_slurp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
slurpOpts = {
"types": {"hotkey": "-t", "type": "flag"},
"appearances": {"hotkey": "-p", "type": "switch"},
"articulate": {"hotkey": "-a", "type": "switch"},
"perPage": {"hotkey": "-P", "type": "flag"},
"sleep": {"hotkey": "-s", "type": "flag"},
"raw": {"hotkey": "-w", "type": "switch"},
Expand Down
1 change: 1 addition & 0 deletions sdk/typescript/src/paths/slurp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function getSlurp(
blocks?: blknum[],
types?: string[],
appearances?: boolean,
articulate?: boolean,
perPage?: uint64,
sleep?: double,
chain: string,
Expand Down
1 change: 1 addition & 0 deletions src/apps/chifra/cmd/slurp.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func init() {
slurpCmd.Flags().StringSliceVarP(&slurpPkg.GetOptions().Types, "types", "t", nil, `which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]`)
slurpCmd.Flags().BoolVarP(&slurpPkg.GetOptions().Appearances, "appearances", "p", false, "show only the blocknumber.tx_id appearances of the exported transactions")
slurpCmd.Flags().BoolVarP(&slurpPkg.GetOptions().Articulate, "articulate", "a", false, "articulate the retrieved data if ABIs can be found")
slurpCmd.Flags().Uint64VarP(&slurpPkg.GetOptions().PerPage, "per_page", "P", 5000, "the number of records to request on each page")
slurpCmd.Flags().Float64VarP(&slurpPkg.GetOptions().Sleep, "sleep", "s", .25, "seconds to sleep between requests")
globals.InitGlobals("slurp", slurpCmd, &slurpPkg.GetOptions().Globals, capabilities)
Expand Down
1 change: 1 addition & 0 deletions src/apps/chifra/internal/slurp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
16 changes: 14 additions & 2 deletions src/apps/chifra/internal/slurp/handle_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func (opts *SlurpOptions) HandleShow() error {
paginator.PerPage = 100
}

// TODO: Turn this back on
// abiCache := articulate.NewAbiCache(opts.Conn, opts.Articulate)

ctx := context.Background()
fetchData := func(modelChan chan types.Modeler[types.RawSlurp], errorChan chan error) {
totalFetched := 0
Expand Down Expand Up @@ -49,8 +52,13 @@ func (opts *SlurpOptions) HandleShow() error {
if !opts.isInRange(uint(tx.BlockNumber), errorChan) {
continue
}
bar.Tick()
// if opts.Articulate {
// if err = abiCache.ArticulateSlurp(&tx); err != nil {
// errorChan <- err // continue even with an error
// }
// }
modelChan <- &tx
bar.Tick()
totalFiltered++
}

Expand All @@ -72,7 +80,11 @@ func (opts *SlurpOptions) HandleShow() error {
}
}

return output.StreamMany(ctx, fetchData, opts.Globals.OutputOpts())
extra := map[string]interface{}{
// "articulate": opts.Articulate,
}

return output.StreamMany(ctx, fetchData, opts.Globals.OutputOptsWithExtra(extra))
}

func (opts *SlurpOptions) isInRange(bn uint, errorChan chan error) bool {
Expand Down
4 changes: 4 additions & 0 deletions src/apps/chifra/internal/slurp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type SlurpOptions struct {
BlockIds []identifiers.Identifier `json:"blockIds,omitempty"` // Block identifiers
Types []string `json:"types,omitempty"` // Which types of transactions to request
Appearances bool `json:"appearances,omitempty"` // Show only the blocknumber.tx_id appearances of the exported transactions
Articulate bool `json:"articulate,omitempty"` // Articulate the retrieved data if ABIs can be found
PerPage uint64 `json:"perPage,omitempty"` // The number of records to request on each page
Sleep float64 `json:"sleep,omitempty"` // Seconds to sleep between requests
Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options
Expand All @@ -47,6 +48,7 @@ func (opts *SlurpOptions) testLog() {
logger.TestLog(len(opts.Blocks) > 0, "Blocks: ", opts.Blocks)
logger.TestLog(len(opts.Types) > 0, "Types: ", opts.Types)
logger.TestLog(opts.Appearances, "Appearances: ", opts.Appearances)
logger.TestLog(opts.Articulate, "Articulate: ", opts.Articulate)
logger.TestLog(opts.PerPage != 5000, "PerPage: ", opts.PerPage)
logger.TestLog(opts.Sleep != float64(.25), "Sleep: ", opts.Sleep)
opts.Conn.TestLog(opts.getCaches())
Expand Down Expand Up @@ -84,6 +86,8 @@ func slurpFinishParseApi(w http.ResponseWriter, r *http.Request) *SlurpOptions {
}
case "appearances":
opts.Appearances = true
case "articulate":
opts.Articulate = true
case "perPage":
opts.PerPage = globals.ToUint64(value[0])
case "sleep":
Expand Down
19 changes: 19 additions & 0 deletions src/apps/chifra/pkg/articulate/slurp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package articulate

import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
)

func (abiCache *AbiCache) ArticulateSlurp(slurp *types.SimpleSlurp) error {
tx := types.SimpleTransaction{
To: slurp.To,
}

if err := abiCache.ArticulateTransaction(&tx); err != nil {
return err
}

slurp.ArticulatedTx = tx.ArticulatedTx
// TODO: We could add `message` here, but we'd have to modify the `types.SimpleSlurp` struct
return nil
}
47 changes: 47 additions & 0 deletions src/apps/chifra/pkg/types/types_slurp.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,30 @@ func (s *SimpleSlurp) Model(chain, format string, verbose bool, extraOptions map
}
model["transactionIndex"] = s.TransactionIndex

// TODO: Turn this back on
// var articulatedTx map[string]interface{}
// isArticulated := extraOptions["articulate"] == true && s.ArticulatedTx != nil
// if isArticulated && format != "json" {
// order = append(order, "compressedTx")
// }
// if isArticulated {
// articulatedTx = map[string]interface{}{
// "name": s.ArticulatedTx.Name,
// }
// inputModels := parametersToMap(s.ArticulatedTx.Inputs)
// if inputModels != nil {
// articulatedTx["inputs"] = inputModels
// }
// outputModels := parametersToMap(s.ArticulatedTx.Outputs)
// if outputModels != nil {
// articulatedTx["outputs"] = outputModels
// }
// sm := s.ArticulatedTx.StateMutability
// if sm != "" && sm != "nonpayable" && sm != "view" {
// articulatedTx["stateMutability"] = sm
// }
// }

if format == "json" {
a := s.ContractAddress.Hex()
if strings.HasPrefix(a, "0x") && len(a) == 42 {
Expand All @@ -184,6 +208,15 @@ func (s *SimpleSlurp) Model(chain, format string, verbose bool, extraOptions map
if len(s.Input) > 2 && s.Input != "deprecated" {
model["input"] = s.Input
}

// if isArticulated {
// model["articulatedTx"] = articulatedTx
// } else {
// if s.Message != "" {
// model["message"] = s.Message
// }
// }

} else {
model["hasToken"] = s.HasToken
model["isError"] = s.IsError
Expand All @@ -192,6 +225,20 @@ func (s *SimpleSlurp) Model(chain, format string, verbose bool, extraOptions map
s.Input = "0x"
}
model["input"] = s.Input

// model["compressedTx"] = ""
// enc := s.Input
// if len(s.Input) >= 10 {
// enc = s.Input[:10]
// }
// model["encoding"] = enc

// if isArticulated {
// model["compressedTx"] = makeCompressed(articulatedTx)
// } else if s.Message != "" {
// model["encoding"] = ""
// model["compressedTx"] = s.Message
// }
}

// EXISTING_CODE
Expand Down
1 change: 1 addition & 0 deletions src/cmd-line-options.csv
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ num,group,tags,api_route,tool,longName,hotKey,def_val,is_required,is_customizabl
12140,tools,Other,slurp,ethslurp,blocks,,,false,false,true,true,gocmd,positional,list<blknum>,an optional range of blocks to slurp
12160,tools,Other,slurp,ethslurp,types,t,,false,false,true,true,gocmd,flag,list<enum[ext*|int|token|nfts|1155|miner|uncles|withdrawals|all]>,which types of transactions to request
12180,tools,Other,slurp,ethslurp,appearances,p,,false,false,true,true,gocmd,switch,<boolean>,show only the blocknumber.tx_id appearances of the exported transactions
12185,tools,Other,slurp,ethslurp,articulate,a,,false,false,true,true,gocmd,switch,<boolean>,articulate the retrieved data if ABIs can be found
12200,tools,Other,slurp,ethslurp,per_page,P,5000,false,false,true,true,gocmd,flag,<uint64>,the number of records to request on each page
12210,tools,Other,slurp,ethslurp,sleep,s,.25,false,false,true,true,gocmd,flag,<double>,seconds to sleep between requests
12220,tools,Other,slurp,ethslurp,,,,false,false,true,true,--,description,,Fetch data from Etherscan for any address.
Expand Down
3 changes: 3 additions & 0 deletions src/dev_tools/makeClass/results/report.csv
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ scrape,touch,typescript
slurp,appearances,api
slurp,appearances,python
slurp,appearances,typescript
slurp,articulate,api
slurp,articulate,python
slurp,articulate,typescript
slurp,cache,api
slurp,cache,python
slurp,perPage,api
Expand Down
1 change: 1 addition & 0 deletions test/gold/apps/chifra/chifra_help_slurp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions test/gold/tools/ethslurp/ethslurp_cache_and_decache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions test/gold/tools/ethslurp/ethslurp_caps_allowed.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions test/gold/tools/ethslurp/ethslurp_caps_disallowed_1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions test/gold/tools/ethslurp/ethslurp_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions test/gold/tools/ethslurp/ethslurp_help_long.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions test/gold/tools/ethslurp/ethslurp_invalid_address.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions test/gold/tools/ethslurp/ethslurp_invalid_param.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions test/gold/tools/ethslurp/ethslurp_invalid_type_1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions test/gold/tools/ethslurp/ethslurp_invalid_type_2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down
1 change: 1 addition & 0 deletions test/gold/tools/ethslurp/ethslurp_no_params.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | all ]
-p, --appearances show only the blocknumber.tx_id appearances of the exported transactions
-a, --articulate articulate the retrieved data if ABIs can be found
-P, --per_page uint the number of records to request on each page (default 5000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
Expand Down

0 comments on commit c495c3a

Please sign in to comment.