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

REST API: split msgpack API type AccountResourceModel into two #3679

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
15 changes: 15 additions & 0 deletions cmd/goal/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ import (
"encoding/base64"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"net/http"
"os"
"strconv"
"strings"

"github.com/spf13/cobra"

"github.com/algorand/go-algorand/crypto"
apiclient "github.com/algorand/go-algorand/daemon/algod/api/client"
"github.com/algorand/go-algorand/data/abi"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/transactions"
Expand Down Expand Up @@ -955,6 +958,14 @@ var readStateAppCmd = &cobra.Command{
// Fetching local state. Get account information
ai, err := client.RawAccountApplicationInformation(account, appIdx)
if err != nil {
var httpError apiclient.HTTPError
if errors.As(err, &httpError) && httpError.StatusCode == http.StatusNotFound {
reportErrorf(errorAccountNotOptedInToApp, account, appIdx)
}
reportErrorf(errorRequestFail, err)
}

if ai.AppLocalState == nil {
reportErrorf(errorAccountNotOptedInToApp, account, appIdx)
}

Expand All @@ -981,6 +992,10 @@ var readStateAppCmd = &cobra.Command{
// Get creator information
ai, err := client.RawAccountApplicationInformation(app.Params.Creator, appIdx)
if err != nil {
reportErrorf(errorRequestFail, err)
}

if ai.AppParams == nil {
reportErrorf(errorAccountNotOptedInToApp, account, appIdx)
}

Expand Down
15 changes: 15 additions & 0 deletions cmd/goal/interact.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ import (
"encoding/base32"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
"strconv"
"strings"

"github.com/spf13/cobra"

"github.com/algorand/go-algorand/crypto"
apiclient "github.com/algorand/go-algorand/daemon/algod/api/client"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/transactions/logic"
Expand Down Expand Up @@ -673,6 +676,14 @@ var appQueryCmd = &cobra.Command{
// Fetching local state. Get account information
ai, err := client.RawAccountApplicationInformation(account, appIdx)
if err != nil {
var httpError apiclient.HTTPError
if errors.As(err, &httpError) && httpError.StatusCode == http.StatusNotFound {
reportErrorf(errorAccountNotOptedInToApp, account, appIdx)
}
reportErrorf(errorRequestFail, err)
}

if ai.AppLocalState == nil {
reportErrorf(errorAccountNotOptedInToApp, account, appIdx)
}

Expand All @@ -690,6 +701,10 @@ var appQueryCmd = &cobra.Command{
// Get creator information
ai, err := client.RawAccountApplicationInformation(app.Params.Creator, appIdx)
if err != nil {
reportErrorf(errorRequestFail, err)
}

if ai.AppParams == nil {
reportErrorf(errorAccountNotOptedInToApp, account, appIdx)
}

Expand Down
8 changes: 4 additions & 4 deletions daemon/algod/api/algod.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
},
"/v2/accounts/{address}/assets/{asset-id}": {
"get": {
"description": "Given a specific account public key, this call returns the account's asset holding and asset params (if they exist) about a given asset ID",
"description": "Given a specific account public key and asset ID, this call returns the account's asset holding and asset parameters (if either exist). Asset parameters will only be returned if the provided address is the asset's creator.",
"produces": [
"application/json",
"application/msgpack"
Expand Down Expand Up @@ -303,7 +303,7 @@
},
"/v2/accounts/{address}/applications/{application-id}": {
"get": {
"description": "Given a specific account public key, this call returns the account's application local state and application params (if they exist) about a given application ID",
"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.",
"produces": [
"application/json",
"application/msgpack"
Expand Down Expand Up @@ -2676,7 +2676,7 @@
}
},
"AccountAssetResponse": {
"description": "AccountAssetResponse describes the asset data for a specific account and asset ID.",
"description": "AccountAssetResponse describes the account's asset holding and asset parameters (if either exist) for a specific asset ID. Asset parameters will only be returned if the provided address is the asset's creator.",
"schema": {
"type": "object",
"required": [
Expand All @@ -2699,7 +2699,7 @@
}
},
"AccountApplicationResponse": {
"description": "AccountApplicationResponse describes the application data for a specific account and application ID.",
"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": {
"type": "object",
"required": [
Expand Down
12 changes: 6 additions & 6 deletions daemon/algod/api/algod.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
}
}
},
"description": "AccountApplicationResponse describes the application data for a specific account and application ID."
"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."
},
"AccountAssetResponse": {
"content": {
Expand All @@ -271,7 +271,7 @@
}
}
},
"description": "AccountAssetResponse describes the asset data for a specific account and asset ID."
"description": "AccountAssetResponse describes the account's asset holding and asset parameters (if either exist) for a specific asset ID. Asset parameters will only be returned if the provided address is the asset's creator."
},
"AccountResponse": {
"content": {
Expand Down Expand Up @@ -1870,7 +1870,7 @@
},
"/v2/accounts/{address}/applications/{application-id}": {
"get": {
"description": "Given a specific account public key, this call returns the account's application local state and application params (if they exist) about a given application ID",
"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.",
"operationId": "AccountApplicationInformation",
"parameters": [
{
Expand Down Expand Up @@ -1949,7 +1949,7 @@
}
}
},
"description": "AccountApplicationResponse describes the application data for a specific account and application ID."
"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."
},
"400": {
"content": {
Expand Down Expand Up @@ -2006,7 +2006,7 @@
},
"/v2/accounts/{address}/assets/{asset-id}": {
"get": {
"description": "Given a specific account public key, this call returns the account's asset holding and asset params (if they exist) about a given asset ID",
"description": "Given a specific account public key and asset ID, this call returns the account's asset holding and asset parameters (if either exist). Asset parameters will only be returned if the provided address is the asset's creator.",
jasonpaulos marked this conversation as resolved.
Show resolved Hide resolved
"operationId": "AccountAssetInformation",
"parameters": [
{
Expand Down Expand Up @@ -2085,7 +2085,7 @@
}
}
},
"description": "AccountAssetResponse describes the asset data for a specific account and asset ID."
"description": "AccountAssetResponse describes the account's asset holding and asset parameters (if either exist) for a specific asset ID. Asset parameters will only be returned if the provided address is the asset's creator."
},
"400": {
"content": {
Expand Down
14 changes: 13 additions & 1 deletion daemon/algod/api/client/restClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ func (e unauthorizedRequestError) Error() string {
return fmt.Sprintf("Unauthorized request to `%s` when using token `%s` : %s", e.url, e.apiToken, e.errorString)
}

// HTTPError is generated when we receive an unhandled error from the server. This error contains the error string.
type HTTPError struct {
StatusCode int
Status string
ErrorString string
}

// Error formats an error string.
func (e HTTPError) Error() string {
return fmt.Sprintf("HTTP %s: %s", e.Status, e.ErrorString)
}

// RestClient manages the REST interface for a calling user.
type RestClient struct {
serverURL url.URL
Expand Down Expand Up @@ -131,7 +143,7 @@ func extractError(resp *http.Response) error {
return unauthorizedRequestError{errorString, apiToken, resp.Request.URL.String()}
}

return fmt.Errorf("HTTP %s: %s", resp.Status, errorString)
return HTTPError{StatusCode: resp.StatusCode, Status: resp.Status, ErrorString: errorString}
}

// stripTransaction gets a transaction of the form "tx-XXXXXXXX" and truncates the "tx-" part, if it starts with "tx-"
Expand Down
Loading