-
Notifications
You must be signed in to change notification settings - Fork 6
Add search by contract functionality #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package dataset | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/duneanalytics/cli/cmdutil" | ||
| "github.com/duneanalytics/cli/output" | ||
| "github.com/duneanalytics/duneapi-client-go/models" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func newSearchByContractCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "search-by-contract", | ||
| Short: "Search for decoded tables associated with a specific contract address", | ||
| Long: `Search for decoded tables (events and calls) associated with a specific contract address. | ||
|
|
||
| This command finds all available decoded tables for a given smart contract address. | ||
| Decoded tables contain blockchain data that has been parsed according to a contract's ABI, | ||
| providing a structured view of contract interactions. | ||
|
|
||
| Table types returned: | ||
| - Event tables: contain parsed event logs emitted by smart contracts | ||
| - Call tables: contain parsed function calls made to smart contracts | ||
|
|
||
| When to use this command: | ||
| - You have a specific contract address (EVM or Tron) and want to find its decoded tables | ||
| - You want to analyze on-chain activity for a particular smart contract | ||
| - You need to find event or call tables for a known contract | ||
|
|
||
| For broader table discovery by keyword or project name, use 'dune dataset search' instead. | ||
|
|
||
| Examples: | ||
| dune dataset search-by-contract --contract-address 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984 | ||
| dune dataset search-by-contract --contract-address 0x1f98... --blockchains ethereum --blockchains arbitrum | ||
| dune dataset search-by-contract --contract-address 0x1f98... --include-schema | ||
| dune dataset search-by-contract --contract-address 0x1f98... --limit 50 --offset 20`, | ||
| RunE: runSearchByContract, | ||
| } | ||
|
|
||
| cmd.Flags().String("contract-address", "", | ||
| "The contract address to search for. Accepts EVM addresses (starting with 0x) or Tron addresses. "+ | ||
| "Example: '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984'.") | ||
| _ = cmd.MarkFlagRequired("contract-address") | ||
| cmd.Flags().StringArray("blockchains", nil, | ||
| "Filter results to specific blockchains (e.g. ethereum, arbitrum). "+ | ||
| "Can be specified multiple times. If not provided, searches across all blockchains where the contract exists.") | ||
| cmd.Flags().Bool("include-schema", false, | ||
| "If set, include the column-level schema (name, type, nullable) for every result. "+ | ||
| "Enable when preparing SQL generation.") | ||
| cmd.Flags().Int32("limit", 20, | ||
| "Maximum number of results to return. "+ | ||
| "Use smaller values (5-10) for quick checks, larger values (50-100) for comprehensive discovery.") | ||
| cmd.Flags().Int32("offset", 0, | ||
| "Number of results to skip for pagination. Use for paginating through large result sets.") | ||
| output.AddFormatFlag(cmd, "text") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runSearchByContract(cmd *cobra.Command, _ []string) error { | ||
| client := cmdutil.ClientFromCmd(cmd) | ||
|
|
||
| contractAddress, _ := cmd.Flags().GetString("contract-address") | ||
|
|
||
| req := models.SearchDatasetsByContractAddressRequest{ | ||
| ContractAddress: contractAddress, | ||
| } | ||
|
|
||
| if cmd.Flags().Changed("blockchains") { | ||
| v, _ := cmd.Flags().GetStringArray("blockchains") | ||
| req.Blockchains = v | ||
| } | ||
| if cmd.Flags().Changed("include-schema") { | ||
| v, _ := cmd.Flags().GetBool("include-schema") | ||
| req.IncludeSchema = &v | ||
| } | ||
| if cmd.Flags().Changed("limit") { | ||
| v, _ := cmd.Flags().GetInt32("limit") | ||
| req.Limit = &v | ||
| } | ||
| if cmd.Flags().Changed("offset") { | ||
| v, _ := cmd.Flags().GetInt32("offset") | ||
| req.Offset = &v | ||
| } | ||
|
|
||
| resp, err := client.SearchDatasetsByContractAddress(req) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| w := cmd.OutOrStdout() | ||
| switch output.FormatFromCmd(cmd) { | ||
| case output.FormatJSON: | ||
| return output.PrintJSON(w, resp) | ||
| default: | ||
| columns := []string{"FULL_NAME", "CATEGORY", "DATASET_TYPE", "BLOCKCHAINS"} | ||
| rows := make([][]string, len(resp.Results)) | ||
| for i, r := range resp.Results { | ||
| dt := "" | ||
| if r.DatasetType != nil { | ||
| dt = *r.DatasetType | ||
| } | ||
| rows[i] = []string{ | ||
| r.FullName, | ||
| r.Category, | ||
| dt, | ||
| strings.Join(r.Blockchains, ", "), | ||
| } | ||
| } | ||
| output.PrintTable(w, columns, rows) | ||
| fmt.Fprintf(w, "\n%d of %d results\n", len(resp.Results), resp.Total) | ||
| return nil | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.