Skip to content
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

API: Experimental full assets for account endpoint. #5948

Merged
merged 18 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6993d7f
Initial cut of support for a full assets for account endpoint. Suppor…
gmalouf Apr 30, 2024
e846d55
Patches for cleanly returning no results when next token is set above…
gmalouf Mar 6, 2024
d2d1b8e
Unit test of the AccountAssets endpoint. Updated pagination logic to …
gmalouf Apr 1, 2024
f6de85c
Update lookup limited resources sql query to conditionally/left join …
gmalouf Apr 4, 2024
55667f3
Set asset max on account assets pagination query to 1000.
gmalouf Apr 4, 2024
7bc9aa1
Add support for invoking the account assets information endpoint from…
gmalouf Apr 6, 2024
f694aba
Introduce new database target version, adding a ctype column to the r…
gmalouf Apr 9, 2024
6726399
Remove join from resources table ctype migration and add a check if d…
gmalouf Apr 10, 2024
6c3d282
OAS cleanup.
gmalouf Apr 10, 2024
7722f80
Update AccountsInitTest for latest migration.
gmalouf Apr 10, 2024
a810c49
Decrease migration runtime of ctype resources migration by 2.5x lever…
gmalouf Apr 22, 2024
5d87b80
Address test failures (k-v store version has to match sqlite, even wi…
gmalouf Apr 23, 2024
5ab49fd
Refactor resources ctype migration to use a default value, avoiding h…
gmalouf Apr 25, 2024
6bb6442
Test adjustments to properly simulate initializing a ledger from a ca…
gmalouf Apr 30, 2024
963027d
Code review tweaks.
gmalouf Apr 30, 2024
2db2669
Changes based on additional CR feedback.
gmalouf May 2, 2024
778cadf
Basic exercise of goal account assetdetails in goal-account-asset.sh
gmalouf May 2, 2024
737c178
Update test/scripts/e2e_subs/goal-account-asset.sh
gmalouf May 3, 2024
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
79 changes: 79 additions & 0 deletions cmd/goal/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
listAccountInfo bool
onlyShowAssetIds bool
partKeyIDToDelete string

next string
limit uint64
)

func init() {
Expand All @@ -79,6 +82,7 @@
accountCmd.AddCommand(listCmd)
accountCmd.AddCommand(renameCmd)
accountCmd.AddCommand(infoCmd)
accountCmd.AddCommand(assetDetailsCmd)
accountCmd.AddCommand(balanceCmd)
accountCmd.AddCommand(rewardsCmd)
accountCmd.AddCommand(changeOnlineCmd)
Expand Down Expand Up @@ -136,6 +140,12 @@
infoCmd.MarkFlagRequired("address")
infoCmd.Flags().BoolVar(&onlyShowAssetIds, "onlyShowAssetIds", false, "Only show ASA IDs and not pull asset metadata")

// Asset details flags
assetDetailsCmd.Flags().StringVarP(&accountAddress, "address", "a", "", "Account address to look up (required)")
assetDetailsCmd.MarkFlagRequired("address")
assetDetailsCmd.Flags().StringVarP(&next, "next", "n", "", "The next asset index to use for pagination")
assetDetailsCmd.Flags().Uint64VarP(&limit, "limit", "l", 0, "The maximum number of assets to return")

// Balance flags
balanceCmd.Flags().StringVarP(&accountAddress, "address", "a", "", "Account address to retrieve balance (required)")
balanceCmd.MarkFlagRequired("address")
Expand Down Expand Up @@ -539,6 +549,33 @@
},
}

var assetDetailsCmd = &cobra.Command{
jasonpaulos marked this conversation as resolved.
Show resolved Hide resolved
Use: "assetdetails",
Short: "Retrieve information about the assets belonging to the specified account inclusive of asset metadata",
Long: `Retrieve information about the assets the specified account has created or opted into, inclusive of asset metadata.`,
Args: validateNoPosArgsFn,
Run: func(cmd *cobra.Command, args []string) {
dataDir := datadir.EnsureSingleDataDir()
client := ensureAlgodClient(dataDir)

Check warning on line 559 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L557-L559

Added lines #L557 - L559 were not covered by tests

var nextPtr *string
var limitPtr *uint64
if next != "" {
nextPtr = &next

Check warning on line 564 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L561-L564

Added lines #L561 - L564 were not covered by tests
}
if limit != 0 {
limitPtr = &limit

Check warning on line 567 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L566-L567

Added lines #L566 - L567 were not covered by tests
}
response, err := client.AccountAssetsInformation(accountAddress, nextPtr, limitPtr)

Check warning on line 569 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L569

Added line #L569 was not covered by tests

if err != nil {
reportErrorf(errorRequestFail, err)

Check warning on line 572 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L571-L572

Added lines #L571 - L572 were not covered by tests
}

printAccountAssetsInformation(accountAddress, response)

Check warning on line 575 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L575

Added line #L575 was not covered by tests

},
}
var infoCmd = &cobra.Command{
Use: "info",
Short: "Retrieve information about the assets and applications belonging to the specified account",
Expand Down Expand Up @@ -731,6 +768,48 @@
return hasError
}

func printAccountAssetsInformation(address string, response model.AccountAssetsInformationResponse) {
fmt.Printf("Account: %s\n", address)
fmt.Printf("Round: %d\n", response.Round)
if response.NextToken != nil {
fmt.Printf("NextToken (to retrieve more account assets): %s\n", *response.NextToken)

Check warning on line 775 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L771-L775

Added lines #L771 - L775 were not covered by tests
}
fmt.Printf("Assets:\n")
for _, asset := range *response.AssetHoldings {
fmt.Printf(" Asset ID: %d\n", asset.AssetHolding.AssetID)

Check warning on line 779 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L777-L779

Added lines #L777 - L779 were not covered by tests

if asset.AssetParams != nil {
amount := assetDecimalsFmt(asset.AssetHolding.Amount, asset.AssetParams.Decimals)
fmt.Printf(" Amount: %s\n", amount)
fmt.Printf(" IsFrozen: %t\n", asset.AssetHolding.IsFrozen)
fmt.Printf(" Asset Params:\n")
fmt.Printf(" Creator: %s\n", asset.AssetParams.Creator)

Check warning on line 786 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L781-L786

Added lines #L781 - L786 were not covered by tests

name := "<unnamed>"
if asset.AssetParams.Name != nil {
_, name = unicodePrintable(*asset.AssetParams.Name)

Check warning on line 790 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L788-L790

Added lines #L788 - L790 were not covered by tests
}
fmt.Printf(" Name: %s\n", name)

Check warning on line 792 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L792

Added line #L792 was not covered by tests

units := "units"
if asset.AssetParams.UnitName != nil {
_, units = unicodePrintable(*asset.AssetParams.UnitName)

Check warning on line 796 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L794-L796

Added lines #L794 - L796 were not covered by tests
}
fmt.Printf(" Units: %s\n", units)
fmt.Printf(" Total: %d\n", asset.AssetParams.Total)
fmt.Printf(" Decimals: %d\n", asset.AssetParams.Decimals)
safeURL := ""
if asset.AssetParams.Url != nil {
_, safeURL = unicodePrintable(*asset.AssetParams.Url)

Check warning on line 803 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L798-L803

Added lines #L798 - L803 were not covered by tests
}
fmt.Printf(" URL: %s\n", safeURL)
} else {
fmt.Printf(" Amount (without formatting): %d\n", asset.AssetHolding.Amount)
fmt.Printf(" IsFrozen: %t\n", asset.AssetHolding.IsFrozen)

Check warning on line 808 in cmd/goal/account.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/account.go#L805-L808

Added lines #L805 - L808 were not covered by tests
}
}
}

var balanceCmd = &cobra.Command{
Use: "balance",
Short: "Retrieve the balances for the specified account",
Expand Down
109 changes: 109 additions & 0 deletions daemon/algod/api/algod.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,73 @@
}
]
},
"/v2/accounts/{address}/assets": {
"get": {
"description": "Lookup an account's asset holdings.",
"tags": [
"public",
"experimental"
],
"produces": [
"application/json"
],
"schemes": [
"http"
],
"summary": "Get a list of assets held by an account, inclusive of asset params.",
"operationId": "AccountAssetsInformation",
"parameters": [
{
"pattern": "[A-Z0-9]{58}",
"type": "string",
"description": "An account public key",
"name": "address",
"in": "path",
"required": true
},
{
"$ref": "#/parameters/limit"
},
{
"$ref": "#/parameters/next"
}
],
"responses": {
"200": {
"$ref": "#/responses/AccountAssetsInformationResponse"
},
"400": {
"description": "Malformed address",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"401": {
"description": "Invalid API Token",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"default": {
"description": "Unknown Error"
}
}
},
"parameters": [
{
"type": "string",
"name": "address",
"in": "path",
"required": true
}
]
},
"/v2/accounts/{address}/applications/{application-id}": {
"get": {
"description": "Given a specific account public key and application ID, this call returns the account's application local state and global state (AppLocalState and AppParams, if either exists). Global state will only be returned if the provided address is the application's creator.",
Expand Down Expand Up @@ -3087,6 +3154,23 @@
}
}
},
"AccountAssetHolding": {
"description": "AccountAssetHolding describes the account's asset holding and asset parameters (if either exist) for a specific asset ID.",
"type": "object",
"required": [
"asset-holding"
],
"properties": {
"asset-holding": {
"description": "\\[asset\\] Details about the asset held by this account.\n\nThe raw account uses `AssetHolding` for this type.",
"$ref": "#/definitions/AssetHolding"
},
"asset-params": {
"description": "\\[apar\\] parameters of the asset held by this account.\n\nThe raw account uses `AssetParams` for this type.",
"$ref": "#/definitions/AssetParams"
}
}
},
"AccountParticipation": {
"description": "AccountParticipation describes the parameters used by this account in consensus protocol.",
"type": "object",
Expand Down Expand Up @@ -4818,6 +4902,31 @@
}
}
},
"AccountAssetsInformationResponse": {
"description": "AccountAssetsInformationResponse contains a list of assets held by an account.",
"schema": {
"type": "object",
"required": [
"round"
],
"properties": {
"round": {
"description": "The round for which this information is relevant.",
"type": "integer"
},
"next-token": {
"description": "Used for pagination, when making another request provide this token with the next parameter.",
"type": "string"
},
"asset-holdings": {
"type": "array",
"items": {
"$ref": "#/definitions/AccountAssetHolding"
}
}
}
}
},
"AccountApplicationResponse": {
"description": "AccountApplicationResponse describes the account's application local state and global state (AppLocalState and AppParams, if either exists) for a specific application ID. Global state will only be returned if the provided address is the application's creator.",
"schema": {
Expand Down
Loading
Loading