-
Notifications
You must be signed in to change notification settings - Fork 3
Add evm transactions command and fix OpenAPI spec gaps across all EVM commands #33
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
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,168 @@ | ||
| package evm | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/url" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/duneanalytics/cli/output" | ||
| ) | ||
|
|
||
| // NewTransactionsCmd returns the `sim evm transactions` command. | ||
| func NewTransactionsCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "transactions <address>", | ||
| Short: "Get EVM transactions for a wallet address", | ||
| Long: "Return transaction history for the given wallet address across supported EVM chains.\n" + | ||
| "Use --decode with -o json to include decoded function calls and event logs.\n\n" + | ||
| "Examples:\n" + | ||
| " dune sim evm transactions 0xd8da6bf26964af9d7eed9e03e53415d37aa96045\n" + | ||
| " dune sim evm transactions 0xd8da... --chain-ids 1 --decode -o json\n" + | ||
| " dune sim evm transactions 0xd8da... --limit 50 -o json", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: runTransactions, | ||
| } | ||
|
|
||
| cmd.Flags().String("chain-ids", "", "Comma-separated chain IDs or tags (default: all default chains)") | ||
| cmd.Flags().Bool("decode", false, "Include decoded transaction data and logs (use with -o json)") | ||
| cmd.Flags().Int("limit", 0, "Max results (1-100)") | ||
| cmd.Flags().String("offset", "", "Pagination cursor from previous response") | ||
| output.AddFormatFlag(cmd, "text") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| type transactionsResponse struct { | ||
| WalletAddress string `json:"wallet_address"` | ||
| Transactions []transactionTx `json:"transactions"` | ||
| Errors *transactionErrors `json:"errors,omitempty"` | ||
| NextOffset string `json:"next_offset,omitempty"` | ||
| Warnings []warningEntry `json:"warnings,omitempty"` | ||
| RequestTime string `json:"request_time,omitempty"` | ||
| ResponseTime string `json:"response_time,omitempty"` | ||
| } | ||
|
|
||
| type transactionErrors struct { | ||
| ErrorMessage string `json:"error_message,omitempty"` | ||
| TransactionErrors []apiChainError `json:"transaction_errors,omitempty"` | ||
| } | ||
ivpusic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| type transactionTx struct { | ||
| Address string `json:"address"` | ||
| BlockHash string `json:"block_hash"` | ||
| BlockNumber json.Number `json:"block_number"` | ||
| BlockTime string `json:"block_time"` | ||
| BlockVersion int `json:"block_version,omitempty"` | ||
| Chain string `json:"chain"` | ||
| From string `json:"from"` | ||
| To string `json:"to"` | ||
| Data string `json:"data,omitempty"` | ||
| GasPrice string `json:"gas_price,omitempty"` | ||
| Hash string `json:"hash"` | ||
| Index json.Number `json:"index,omitempty"` | ||
| MaxFeePerGas string `json:"max_fee_per_gas,omitempty"` | ||
| MaxPriorityFeePerGas string `json:"max_priority_fee_per_gas,omitempty"` | ||
| Nonce string `json:"nonce,omitempty"` | ||
| TransactionType string `json:"transaction_type,omitempty"` | ||
| Value string `json:"value"` | ||
| Decoded *decodedCall `json:"decoded,omitempty"` | ||
| Logs []transactionLog `json:"logs,omitempty"` | ||
| } | ||
|
|
||
| type decodedCall struct { | ||
| Name string `json:"name,omitempty"` | ||
| Inputs []decodedInput `json:"inputs,omitempty"` | ||
| } | ||
|
|
||
| type decodedInput struct { | ||
| Name string `json:"name,omitempty"` | ||
| Type string `json:"type,omitempty"` | ||
| Value json.RawMessage `json:"value,omitempty"` | ||
| } | ||
|
|
||
| type transactionLog struct { | ||
| Address string `json:"address,omitempty"` | ||
| Data string `json:"data,omitempty"` | ||
| Topics []string `json:"topics,omitempty"` | ||
| Decoded *decodedCall `json:"decoded,omitempty"` | ||
| } | ||
|
|
||
| func runTransactions(cmd *cobra.Command, args []string) error { | ||
| client := SimClientFromCmd(cmd) | ||
| if client == nil { | ||
| return fmt.Errorf("sim client not initialized") | ||
| } | ||
|
|
||
| address := args[0] | ||
| params := url.Values{} | ||
|
|
||
| if v, _ := cmd.Flags().GetString("chain-ids"); v != "" { | ||
| params.Set("chain_ids", v) | ||
| } | ||
| if v, _ := cmd.Flags().GetBool("decode"); v { | ||
| params.Set("decode", "true") | ||
| } | ||
| if v, _ := cmd.Flags().GetInt("limit"); v > 0 { | ||
| params.Set("limit", fmt.Sprintf("%d", v)) | ||
| } | ||
| if v, _ := cmd.Flags().GetString("offset"); v != "" { | ||
| params.Set("offset", v) | ||
| } | ||
|
|
||
| data, err := client.Get(cmd.Context(), "/v1/evm/transactions/"+address, params) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| w := cmd.OutOrStdout() | ||
| switch output.FormatFromCmd(cmd) { | ||
| case output.FormatJSON: | ||
| var raw json.RawMessage = data | ||
| return output.PrintJSON(w, raw) | ||
| default: | ||
| var resp transactionsResponse | ||
| if err := json.Unmarshal(data, &resp); err != nil { | ||
| return fmt.Errorf("parsing response: %w", err) | ||
| } | ||
|
|
||
| // Warn if --decode is used in text mode since the table can't show decoded data. | ||
| if decode, _ := cmd.Flags().GetBool("decode"); decode { | ||
| fmt.Fprintln(cmd.ErrOrStderr(), "Note: --decode data is only visible in JSON output. Use -o json to see decoded fields.") | ||
| } | ||
|
|
||
| // Print errors to stderr. | ||
| printTransactionErrors(cmd, resp.Errors) | ||
|
|
||
| // Print warnings to stderr. | ||
| printWarnings(cmd, resp.Warnings) | ||
|
|
||
| columns := []string{"CHAIN", "HASH", "FROM", "TO", "VALUE", "BLOCK_TIME"} | ||
| rows := make([][]string, len(resp.Transactions)) | ||
| for i, tx := range resp.Transactions { | ||
| rows[i] = []string{ | ||
| tx.Chain, | ||
| truncateHash(tx.Hash), | ||
| truncateHash(tx.From), | ||
| truncateHash(tx.To), | ||
| tx.Value, | ||
| tx.BlockTime, | ||
| } | ||
| } | ||
| output.PrintTable(w, columns, rows) | ||
|
|
||
| if resp.NextOffset != "" { | ||
| fmt.Fprintf(w, "\nNext offset: %s\n", resp.NextOffset) | ||
| } | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| // printTransactionErrors writes transaction-level errors to stderr. | ||
| func printTransactionErrors(cmd *cobra.Command, errs *transactionErrors) { | ||
| if errs == nil { | ||
| return | ||
| } | ||
| printAPIChainErrors(cmd, errs.ErrorMessage, errs.TransactionErrors) | ||
| } | ||
Oops, something went wrong.
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.