Repository navigation
feat: add contract decoding submissions API #31
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
bh2smith
merged 2 commits into
main
from
bh2smith/df-1107-contract-decoding-submissions
Sep 11, 2026
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package dune | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| "github.com/duneanalytics/duneapi-client-go/models" | ||
| ) | ||
|
|
||
| // SubmitContracts submits up to 100 contracts for decoding in one request. | ||
| // Each item is validated and queued independently; the response carries one result | ||
| // per item, matched by index, so one bad ABI does not fail the batch. Submissions are | ||
| // attributed to the user who created the API key. | ||
| // https://docs.dune.com/api-reference/contracts/endpoint/decode | ||
| func (c *duneClient) SubmitContracts(req models.SubmitContractsRequest) (*models.SubmitContractsResponse, error) { | ||
| submitURL := fmt.Sprintf(submitContractsURLTemplate, c.env.Host) | ||
|
|
||
| jsonData, err := json.Marshal(req) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| httpReq, err := http.NewRequest("POST", submitURL, bytes.NewBuffer(jsonData)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| httpReq.Header.Set("Content-Type", "application/json") | ||
|
|
||
| resp, err := httpRequest(c.env, httpReq) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var submitResp models.SubmitContractsResponse | ||
| if err := decodeBody(resp, &submitResp); err != nil { | ||
| return nil, err | ||
| } | ||
| if err := submitResp.HasError(); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &submitResp, nil | ||
| } | ||
|
|
||
| // ListContractSubmissions lists the contract decoding submissions made by the user | ||
| // who created the API key, newest first. Pass NextCursor from a response back as | ||
| // Cursor to fetch the next page. | ||
| // https://docs.dune.com/api-reference/contracts/endpoint/list | ||
| func (c *duneClient) ListContractSubmissions( | ||
| opts models.ListContractSubmissionsOptions, | ||
| ) (*models.ListContractSubmissionsResponse, error) { | ||
| listURL := fmt.Sprintf(listContractSubmissionsURLTemplate, c.env.Host) | ||
| if query := opts.ToURLValues().Encode(); query != "" { | ||
| listURL += "?" + query | ||
| } | ||
|
|
||
| req, err := http.NewRequest("GET", listURL, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| resp, err := httpRequest(c.env, req) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var listResp models.ListContractSubmissionsResponse | ||
| if err := decodeBody(resp, &listResp); err != nil { | ||
| return nil, err | ||
| } | ||
| if err := listResp.HasError(); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &listResp, 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| package dune | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "io" | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/duneanalytics/duneapi-client-go/models" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestSubmitContracts(t *testing.T) { | ||
| var gotMethod, gotPath string | ||
| var gotBody map[string]any | ||
|
|
||
| client := newTestClient(t, func(w http.ResponseWriter, r *http.Request) { | ||
| gotMethod = r.Method | ||
| gotPath = r.URL.Path | ||
| body, _ := io.ReadAll(r.Body) | ||
| json.Unmarshal(body, &gotBody) | ||
|
|
||
| w.WriteHeader(http.StatusOK) | ||
| io.WriteString(w, `{"results":[ | ||
| {"index":0,"submission_id":"sub_1","status":"pending"}, | ||
| {"index":1,"submission_id":"sub_0","status":"pending","replayed":true}, | ||
| {"index":2,"error":"abi must be valid JSON"} | ||
| ]}`) | ||
| }) | ||
|
|
||
| upgrade := "upgrade" | ||
| reason := "new implementation" | ||
| key := "k/0" | ||
| resp, err := client.SubmitContracts(models.SubmitContractsRequest{ | ||
| Submissions: []models.ContractSubmissionInput{ | ||
| { | ||
| BlockchainName: "ethereum", | ||
| Address: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", | ||
| ProjectName: "uniswap", | ||
| ContractName: "UniswapToken", | ||
| ABI: json.RawMessage(`[{"type":"event","name":"Transfer","inputs":[]}]`), | ||
| IsProxy: true, | ||
| IdempotencyKey: &key, | ||
| }, | ||
| { | ||
| BlockchainName: "ethereum", | ||
| Address: "0x1", | ||
| ProjectName: "uniswap", | ||
| ContractName: "Old", | ||
| ABI: json.RawMessage(`"[]"`), | ||
| SubmissionType: &upgrade, | ||
| ResubmissionReason: &reason, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| require.NoError(t, err) | ||
| require.Equal(t, "POST", gotMethod) | ||
| require.Equal(t, "/api/v1/contracts/decode", gotPath) | ||
|
|
||
| submissions := gotBody["submissions"].([]any) | ||
| require.Len(t, submissions, 2) | ||
| first := submissions[0].(map[string]any) | ||
| require.Equal(t, []any{map[string]any{"type": "event", "name": "Transfer", "inputs": []any{}}}, first["abi"]) | ||
| require.Equal(t, true, first["is_proxy"]) | ||
| require.Equal(t, false, first["has_multiple_instances"]) | ||
| require.Equal(t, "k/0", first["idempotency_key"]) | ||
| require.NotContains(t, first, "submission_type") | ||
| second := submissions[1].(map[string]any) | ||
| require.Equal(t, "[]", second["abi"]) | ||
| require.Equal(t, "upgrade", second["submission_type"]) | ||
| require.NotContains(t, second, "idempotency_key") | ||
|
|
||
| require.Len(t, resp.Results, 3) | ||
| require.Equal(t, "sub_1", *resp.Results[0].SubmissionID) | ||
| require.Equal(t, "pending", *resp.Results[0].Status) | ||
| require.False(t, resp.Results[0].Replayed) | ||
| require.Nil(t, resp.Results[0].Error) | ||
| require.True(t, resp.Results[1].Replayed) | ||
| require.Equal(t, 2, resp.Results[2].Index) | ||
| require.Nil(t, resp.Results[2].SubmissionID) | ||
| require.Equal(t, "abi must be valid JSON", *resp.Results[2].Error) | ||
| } | ||
|
|
||
| func TestSubmitContractsReturnsAPIError(t *testing.T) { | ||
| client := newTestClient(t, func(w http.ResponseWriter, r *http.Request) { | ||
| w.WriteHeader(http.StatusForbidden) | ||
| io.WriteString(w, `{"error":"Resubmissions and multi-chain batches require a paid team plan."}`) | ||
| }) | ||
|
|
||
| _, err := client.SubmitContracts(models.SubmitContractsRequest{ | ||
| Submissions: []models.ContractSubmissionInput{{BlockchainName: "base"}}, | ||
| }) | ||
|
|
||
| require.ErrorIs(t, err, ErrorReqUnsuccessful) | ||
| require.ErrorContains(t, err, "[403]") | ||
| require.ErrorContains(t, err, "paid team plan") | ||
| } | ||
|
|
||
| func TestListContractSubmissions(t *testing.T) { | ||
| var gotPath, gotQuery string | ||
|
|
||
| client := newTestClient(t, func(w http.ResponseWriter, r *http.Request) { | ||
| gotPath = r.URL.Path | ||
| gotQuery = r.URL.RawQuery | ||
| w.WriteHeader(http.StatusOK) | ||
| io.WriteString(w, `{"submissions":[{ | ||
| "id":"sub_1","blockchain_name":"ethereum","address":"0x1", | ||
| "project_name":"p","contract_name":"c","status":"rejected","submission_type":"new", | ||
| "comment":"There is already a decoded contract at this address.", | ||
| "created_at":"2026-09-10T11:04:18.724658Z","updated_at":"2026-09-10T11:05:18Z", | ||
| "idempotency_key":"k/1" | ||
| }],"total":7,"next_cursor":"abc"}`) | ||
| }) | ||
|
|
||
| resp, err := client.ListContractSubmissions(models.ListContractSubmissionsOptions{ | ||
| Limit: 1, | ||
| Cursor: "prev", | ||
| BlockchainName: "ethereum", | ||
| Status: "rejected", | ||
| }) | ||
|
|
||
| require.NoError(t, err) | ||
| require.Equal(t, "/api/v1/contracts/submissions", gotPath) | ||
| require.Equal(t, "blockchain_name=ethereum&cursor=prev&limit=1&status=rejected", gotQuery) | ||
| require.Equal(t, 7, resp.Total) | ||
| require.Equal(t, "abc", *resp.NextCursor) | ||
| require.Len(t, resp.Submissions, 1) | ||
| require.Equal(t, "rejected", resp.Submissions[0].Status) | ||
| require.Equal(t, "There is already a decoded contract at this address.", *resp.Submissions[0].Comment) | ||
| require.Equal(t, "k/1", *resp.Submissions[0].IdempotencyKey) | ||
| require.Equal(t, 2026, resp.Submissions[0].CreatedAt.Year()) | ||
| } | ||
|
|
||
| func TestListContractSubmissionsOmitsUnsetOptions(t *testing.T) { | ||
| var gotQuery string | ||
|
|
||
| client := newTestClient(t, func(w http.ResponseWriter, r *http.Request) { | ||
| gotQuery = r.URL.RawQuery | ||
| w.WriteHeader(http.StatusOK) | ||
| io.WriteString(w, `{"submissions":[],"total":0}`) | ||
| }) | ||
|
|
||
| resp, err := client.ListContractSubmissions(models.ListContractSubmissionsOptions{}) | ||
|
|
||
| require.NoError(t, err) | ||
| require.Equal(t, "", gotQuery) | ||
| require.Nil(t, resp.NextCursor) | ||
| require.Empty(t, resp.Submissions) | ||
| } |
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,49 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/duneanalytics/duneapi-client-go/models" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // Submitting is not exercised here: every SubmitContracts call creates a real | ||
| // decoding submission for the key's owner. | ||
| func TestListContractSubmissions(t *testing.T) { | ||
| if testing.Short() { | ||
| t.Skip("Skipping E2E test in short mode") | ||
| } | ||
|
|
||
| client := setupClient(t) | ||
|
|
||
| result, err := client.ListContractSubmissions(models.ListContractSubmissionsOptions{Limit: 5}) | ||
| require.NoError(t, err) | ||
| assert.NotNil(t, result.Submissions) | ||
| assert.GreaterOrEqual(t, result.Total, 0) | ||
| assert.LessOrEqual(t, len(result.Submissions), 5) | ||
|
|
||
| for _, submission := range result.Submissions { | ||
| assert.NotEmpty(t, submission.ID) | ||
| assert.NotEmpty(t, submission.BlockchainName) | ||
| assert.NotEmpty(t, submission.Status) | ||
| } | ||
| } | ||
|
|
||
| func TestListContractSubmissionsWithStatusFilter(t *testing.T) { | ||
| if testing.Short() { | ||
| t.Skip("Skipping E2E test in short mode") | ||
| } | ||
|
|
||
| client := setupClient(t) | ||
|
|
||
| result, err := client.ListContractSubmissions(models.ListContractSubmissionsOptions{ | ||
| Limit: 5, | ||
| Status: "rejected", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| for _, submission := range result.Submissions { | ||
| assert.Equal(t, "rejected", submission.Status) | ||
| } | ||
| } |
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.