Skip to content

Commit

Permalink
Fixing chifra slurp (#3732)
Browse files Browse the repository at this point in the history
* Fixes tests for chifra slurp

* Deprecates --types in favor or --parts to be consistant with other tools. Other changes
  • Loading branch information
tjayrush authored May 31, 2024
1 parent 7c76975 commit 531b51d
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 152 deletions.
28 changes: 27 additions & 1 deletion docs/content/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2910,7 +2910,7 @@ paths:
items:
type: string
format: blknum
- name: types
- name: parts
description: which types of transactions to request
required: false
style: form
Expand Down Expand Up @@ -2968,6 +2968,32 @@ paths:
explode: true
schema:
type: boolean
- name: page
description: the page to retrieve (page number)
required: false
style: form
in: query
explode: true
schema:
type: number
format: uint64
- name: pageId
description: the page to retrieve (page ID)
required: false
style: form
in: query
explode: true
schema:
type: string
- name: perPage
description: the number of records to request on each page
required: false
style: form
in: query
explode: true
schema:
type: number
format: uint64
- name: sleep
description: seconds to sleep between requests
required: false
Expand Down
34 changes: 19 additions & 15 deletions docs/content/chifra/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,31 @@ Arguments:
blocks - an optional range of blocks to slurp
Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | some | 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
-S, --source string the source of the slurped data
One of [ etherscan | key | covalent | alchemy ] (default "etherscan")
-U, --count for --appearances mode only, display only the count of records
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
-o, --cache force the results of the query into the cache
-D, --decache removes related items from the cache
-x, --fmt string export format, one of [none|json*|txt|csv]
-v, --verbose enable verbose output
-h, --help display this help screen
-r, --parts strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | some | 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
-S, --source string the source of the slurped data
One of [ etherscan | key | covalent | alchemy ] (default "etherscan")
-U, --count for --appearances mode only, display only the count of records
-g, --page uint the page to retrieve (page number)
--page_id string the page to retrieve (page ID)
-P, --per_page uint the number of records to request on each page (default 1000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
-o, --cache force the results of the query into the cache
-D, --decache removes related items from the cache
-x, --fmt string export format, one of [none|json*|txt|csv]
-v, --verbose enable verbose output
-h, --help display this help screen
Notes:
- An address must be either an ENS name or start with '0x' and be forty-two characters long.
- Portions of this software are Powered by Etherscan.io, Covalent, Alchemy, TrueBlocks Key APIs.
- See slurp/README on how to configure keys for API providers
- The withdrawals option is only available on certain chains. It is ignored otherwise.
- If the value of --source is key, --types is ignored.
- If the value of --source is key, --parts is ignored.
- The --types option is deprecated, use --parts instead.
```

Data models produced by this tool:
Expand Down
82 changes: 41 additions & 41 deletions sdk/slurp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
type SlurpOptions struct {
Addrs []string `json:"addrs,omitempty"`
BlockIds []string `json:"blocks,omitempty"`
Types SlurpTypes `json:"types,omitempty"`
Parts SlurpParts `json:"parts,omitempty"`
Articulate bool `json:"articulate,omitempty"`
Source SlurpSource `json:"source,omitempty"`
Page uint64 `json:"page,omitempty"`
Expand Down Expand Up @@ -57,45 +57,45 @@ func (opts *SlurpOptions) SlurpCount() ([]types.Monitor, *types.MetaData, error)
return querySlurp[types.Monitor](in)
}

type SlurpTypes int
type SlurpParts int

const (
NoST SlurpTypes = 0
STExt = 1 << iota
STInt
STToken
STNfts
ST1155
STMiner
STUncles
STWithdrawals
STSome = STExt | STInt | STToken | STNfts
STAll = STExt | STInt | STToken | STNfts | ST1155 | STMiner | STUncles | STWithdrawals
NoSLP SlurpParts = 0
SPExt = 1 << iota
SPInt
SPToken
SPNfts
SP1155
SPMiner
SPUncles
SPWithdrawals
SLPSome = SPExt | SPInt | SPToken | SPNfts
SLPAll = SPExt | SPInt | SPToken | SPNfts | SP1155 | SPMiner | SPUncles | SPWithdrawals
)

func (v SlurpTypes) String() string {
func (v SlurpParts) String() string {
switch v {
case NoST:
case NoSLP:
return "none"
case STSome:
case SLPSome:
return "some"
case STAll:
case SLPAll:
return "all"
}

var m = map[SlurpTypes]string{
STExt: "ext",
STInt: "int",
STToken: "token",
STNfts: "nfts",
ST1155: "1155",
STMiner: "miner",
STUncles: "uncles",
STWithdrawals: "withdrawals",
var m = map[SlurpParts]string{
SPExt: "ext",
SPInt: "int",
SPToken: "token",
SPNfts: "nfts",
SP1155: "1155",
SPMiner: "miner",
SPUncles: "uncles",
SPWithdrawals: "withdrawals",
}

var ret []string
for _, val := range []SlurpTypes{STExt, STInt, STToken, STNfts, ST1155, STMiner, STUncles, STWithdrawals} {
for _, val := range []SlurpParts{SPExt, SPInt, SPToken, SPNfts, SP1155, SPMiner, SPUncles, SPWithdrawals} {
if v&val != 0 {
ret = append(ret, m[val])
}
Expand All @@ -104,38 +104,38 @@ func (v SlurpTypes) String() string {
return strings.Join(ret, ",")
}

func enumFromSlurpTypes(values []string) (SlurpTypes, error) {
func enumFromSlurpParts(values []string) (SlurpParts, error) {
if len(values) == 0 {
return NoST, fmt.Errorf("no value provided for types option")
return NoSLP, fmt.Errorf("no value provided for parts option")
}

if len(values) == 1 && values[0] == "all" {
return STAll, nil
return SLPAll, nil
} else if len(values) == 1 && values[0] == "some" {
return STSome, nil
return SLPSome, nil
}

var result SlurpTypes
var result SlurpParts
for _, val := range values {
switch val {
case "ext":
result |= STExt
result |= SPExt
case "int":
result |= STInt
result |= SPInt
case "token":
result |= STToken
result |= SPToken
case "nfts":
result |= STNfts
result |= SPNfts
case "1155":
result |= ST1155
result |= SP1155
case "miner":
result |= STMiner
result |= SPMiner
case "uncles":
result |= STUncles
result |= SPUncles
case "withdrawals":
result |= STWithdrawals
result |= SPWithdrawals
default:
return NoST, fmt.Errorf("unknown types: %s", val)
return NoSLP, fmt.Errorf("unknown parts: %s", val)
}
}

Expand Down
8 changes: 4 additions & 4 deletions sdk/slurp_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
type slurpOptionsInternal struct {
Addrs []string `json:"addrs,omitempty"`
BlockIds []string `json:"blocks,omitempty"`
Types SlurpTypes `json:"types,omitempty"`
Parts SlurpParts `json:"parts,omitempty"`
Appearances bool `json:"appearances,omitempty"`
Articulate bool `json:"articulate,omitempty"`
Source SlurpSource `json:"source,omitempty"`
Expand Down Expand Up @@ -60,10 +60,10 @@ func slurpParseFunc(target any, key, value string) (bool, error) {
return false, fmt.Errorf("parseFunc(slurp): target is not of correct type")
}

if key == "types" {
if key == "parts" {
var err error
values := strings.Split(value, ",")
if opts.Types, err = enumFromSlurpTypes(values); err != nil {
if opts.Parts, err = enumFromSlurpParts(values); err != nil {
return false, err
} else {
found = true
Expand Down Expand Up @@ -130,7 +130,7 @@ func (opts *SlurpOptions) toInternal() *slurpOptionsInternal {
return &slurpOptionsInternal{
Addrs: opts.Addrs,
BlockIds: opts.BlockIds,
Types: opts.Types,
Parts: opts.Parts,
Articulate: opts.Articulate,
Source: opts.Source,
Page: opts.Page,
Expand Down
7 changes: 5 additions & 2 deletions sdk/typescript/src/paths/slurp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
*/

import * as ApiCallers from '../lib/api_callers';
import { address, Appearance, blknum, float64, Monitor, Slurp } from '../types';
import { address, Appearance, blknum, float64, Monitor, Slurp, uint64 } from '../types';

export function getSlurp(
parameters?: {
addrs: address[],
blocks?: blknum[],
types?: string[],
parts?: string[],
appearances?: boolean,
articulate?: boolean,
source?: 'etherscan' | 'key' | 'covalent' | 'alchemy',
count?: boolean,
page?: uint64,
pageId?: string,
perPage?: uint64,
sleep?: float64,
fmt?: string,
chain: string,
Expand Down
17 changes: 9 additions & 8 deletions src/apps/chifra/cmd/slurp.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Notes:
- Portions of this software are Powered by Etherscan.io, Covalent, Alchemy, TrueBlocks Key APIs.
- See slurp/README on how to configure keys for API providers
- The withdrawals option is only available on certain chains. It is ignored otherwise.
- If the value of --source is key, --types is ignored.`
- If the value of --source is key, --parts is ignored.
- The --types option is deprecated, use --parts instead.`

func init() {
var capabilities caps.Capability // capabilities for chifra slurp
Expand All @@ -61,22 +62,22 @@ func init() {

slurpCmd.Flags().SortFlags = false

slurpCmd.Flags().StringSliceVarP(&slurpPkg.GetOptions().Types, "types", "t", nil, `which types of transactions to request
slurpCmd.Flags().StringSliceVarP(&slurpPkg.GetOptions().Parts, "parts", "r", nil, `which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | some | 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().StringVarP(&slurpPkg.GetOptions().Source, "source", "S", "etherscan", `the source of the slurped data
One of [ etherscan | key | covalent | alchemy ]`)
slurpCmd.Flags().BoolVarP(&slurpPkg.GetOptions().Count, "count", "U", false, `for --appearances mode only, display only the count of records`)
slurpCmd.Flags().Uint64VarP(&slurpPkg.GetOptions().Page, "page", "g", 0, `the page to retrieve (page number) (hidden)`)
slurpCmd.Flags().StringVarP(&slurpPkg.GetOptions().PageId, "page_id", "", "", `the page to retrieve (page ID) (hidden)`)
slurpCmd.Flags().Uint64VarP(&slurpPkg.GetOptions().PerPage, "per_page", "P", 1000, `the number of records to request on each page (hidden)`)
slurpCmd.Flags().Uint64VarP(&slurpPkg.GetOptions().Page, "page", "g", 0, `the page to retrieve (page number)`)
slurpCmd.Flags().StringVarP(&slurpPkg.GetOptions().PageId, "page_id", "", "", `the page to retrieve (page ID)`)
slurpCmd.Flags().Uint64VarP(&slurpPkg.GetOptions().PerPage, "per_page", "P", 1000, `the number of records to request on each page`)
slurpCmd.Flags().Float64VarP(&slurpPkg.GetOptions().Sleep, "sleep", "s", .25, `seconds to sleep between requests`)
slurpCmd.Flags().StringSliceVarP(&slurpPkg.GetOptions().Types, "types", "t", nil, `deprecated, use --parts instead (hidden)`)
if os.Getenv("TEST_MODE") != "true" {
_ = slurpCmd.Flags().MarkHidden("page")
_ = slurpCmd.Flags().MarkHidden("page_id")
_ = slurpCmd.Flags().MarkHidden("per_page")
_ = slurpCmd.Flags().MarkHidden("types")
}
_ = slurpCmd.Flags().MarkDeprecated("types", "The --types option has been deprecated.")
globals.InitGlobals("slurp", slurpCmd, &slurpPkg.GetOptions().Globals, capabilities)

slurpCmd.SetUsageTemplate(UsageWithNotes(notesSlurp))
Expand Down
3 changes: 2 additions & 1 deletion src/apps/chifra/internal/daemon/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (opts *DaemonOptions) testLog() {
logger.TestLog(opts.Monitor, "Monitor: ", opts.Monitor)
logger.TestLog(opts.Grpc, "Grpc: ", opts.Grpc)
logger.TestLog(opts.Silent, "Silent: ", opts.Silent)
logger.TestLog(len(opts.Port) > 0 && opts.Port != ":8080", "Port: ", opts.Port)
opts.Conn.TestLog(opts.getCaches())
opts.Globals.TestLog()
}
Expand Down Expand Up @@ -111,6 +110,7 @@ func DaemonFinishParseInternal(w io.Writer, values url.Values) *DaemonOptions {
if opts.Port != ":8080" && opts.Url == "localhost:8080" {
logger.Warn("The --port flag is deprecated. Please use --url instead.")
opts.Url = opts.Port
opts.Port = ""
}

// EXISTING_CODE
Expand Down Expand Up @@ -142,6 +142,7 @@ func daemonFinishParse(args []string) *DaemonOptions {
if opts.Port != ":8080" && opts.Url == "localhost:8080" {
logger.Warn("The --port flag is deprecated. Please use --url instead.")
opts.Url = opts.Port
opts.Port = ""
}

// EXISTING_CODE
Expand Down
34 changes: 19 additions & 15 deletions src/apps/chifra/internal/slurp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,31 @@ Arguments:
blocks - an optional range of blocks to slurp
Flags:
-t, --types strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | some | 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
-S, --source string the source of the slurped data
One of [ etherscan | key | covalent | alchemy ] (default "etherscan")
-U, --count for --appearances mode only, display only the count of records
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
-o, --cache force the results of the query into the cache
-D, --decache removes related items from the cache
-x, --fmt string export format, one of [none|json*|txt|csv]
-v, --verbose enable verbose output
-h, --help display this help screen
-r, --parts strings which types of transactions to request
One or more of [ ext | int | token | nfts | 1155 | miner | uncles | withdrawals | some | 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
-S, --source string the source of the slurped data
One of [ etherscan | key | covalent | alchemy ] (default "etherscan")
-U, --count for --appearances mode only, display only the count of records
-g, --page uint the page to retrieve (page number)
--page_id string the page to retrieve (page ID)
-P, --per_page uint the number of records to request on each page (default 1000)
-s, --sleep float seconds to sleep between requests (default 0.25)
-H, --ether specify value in ether
-o, --cache force the results of the query into the cache
-D, --decache removes related items from the cache
-x, --fmt string export format, one of [none|json*|txt|csv]
-v, --verbose enable verbose output
-h, --help display this help screen
Notes:
- An address must be either an ENS name or start with '0x' and be forty-two characters long.
- Portions of this software are Powered by Etherscan.io, Covalent, Alchemy, TrueBlocks Key APIs.
- See slurp/README on how to configure keys for API providers
- The withdrawals option is only available on certain chains. It is ignored otherwise.
- If the value of --source is key, --types is ignored.
- If the value of --source is key, --parts is ignored.
- The --types option is deprecated, use --parts instead.
```

Data models produced by this tool:
Expand Down
Loading

0 comments on commit 531b51d

Please sign in to comment.