Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dune/dune.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ type DuneClient interface {

// SearchDatasetsByContractAddress finds decoded datasets associated with a smart contract address
SearchDatasetsByContractAddress(req models.SearchDatasetsByContractAddressRequest) (*models.SearchDatasetsResponse, error)

// WhoAmI returns the identity associated with the current API key
WhoAmI() (*models.WhoAmIResponse, error)
}

type duneClient struct {
Expand Down Expand Up @@ -165,6 +168,7 @@ var (
archiveQueryURLTemplate = "%s/api/v1/query/%d/archive"
searchDatasetsURLTemplate = "%s/api/v1/datasets/search"
searchDatasetsByContractAddressURLTemplate = "%s/api/v1/datasets/search-by-contract"
whoamiURLTemplate = "%s/api/whoami"
)

var ErrorRetriesExhausted = errors.New("retries have been exhausted")
Expand Down
28 changes: 28 additions & 0 deletions dune/whoami.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dune

import (
"fmt"
"net/http"

"github.com/duneanalytics/duneapi-client-go/models"
)

func (c *duneClient) WhoAmI() (*models.WhoAmIResponse, error) {
reqURL := fmt.Sprintf(whoamiURLTemplate, c.env.Host)
req, err := http.NewRequest("GET", reqURL, nil)
if err != nil {
return nil, err
}

resp, err := httpRequest(c.env.APIKey, req)
if err != nil {
return nil, err
}

var whoamiResp models.WhoAmIResponse
if err := decodeBody(resp, &whoamiResp); err != nil {
return nil, err
}

return &whoamiResp, nil
}
10 changes: 10 additions & 0 deletions models/whoami.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package models

// WhoAmIResponse represents the response from the /api/whoami endpoint.
// It identifies the user or team associated with the current API key.
type WhoAmIResponse struct {
CustomerID string `json:"customer_id"` // e.g. "user_123" or "team_456"
CreatedBy int `json:"created_by"` // integer user ID of the key creator
APIKeyID string `json:"api_key_id"` // ULID of the API key
Handle string `json:"handle"` // username or team handle
}