Skip to content

Commit

Permalink
Merge branch 'release/v1.21.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
egieseke committed Sep 19, 2022
2 parents b5ae6ab + 95be0ea commit ac817f7
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,11 @@
# 1.21.0
## What's Changed
### Enhancements
* Deprecation: Add deprecated tags to v1 `algod1` API ([#392](https://github.com/algorand/go-algorand-sdk/pull/392))
* Enhancement: update block model ([#401](https://github.com/algorand/go-algorand-sdk/pull/401))
### Bugfixes
* Bugfix: Fix dryrun parser ([#400](https://github.com/algorand/go-algorand-sdk/pull/400))

# 1.20.0
## What's Changed
### Bugfixes
Expand Down
15 changes: 15 additions & 0 deletions client/algod/algod.go
Expand Up @@ -20,30 +20,35 @@ const (
)

// unversionedPaths ais a set of paths that should not be prefixed by the API version
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
var unversionedPaths = map[string]bool{
"/versions": true,
"/health": true,
}

// rawRequestPaths is a set of paths where the body should not be urlencoded
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
var rawRequestPaths = map[string]bool{
"/transactions": true,
}

// Header is a struct for custom headers.
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
type Header struct {
Key string
Value string
}

// Client manages the REST interface for a calling user.
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
type Client struct {
serverURL url.URL
apiToken string
headers []*Header
}

// MakeClient is the factory for constructing a Client for a given endpoint.
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func MakeClient(address string, apiToken string) (c Client, err error) {
url, err := url.Parse(address)
if err != nil {
Expand All @@ -58,6 +63,7 @@ func MakeClient(address string, apiToken string) (c Client, err error) {
}

// MakeClientWithHeaders is the factory for constructing a Client for a given endpoint with additional user defined headers.
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func MakeClientWithHeaders(address string, apiToken string, headers []*Header) (c Client, err error) {
c, err = MakeClient(address, apiToken)
if err != nil {
Expand All @@ -72,6 +78,7 @@ func MakeClientWithHeaders(address string, apiToken string, headers []*Header) (
// extractError checks if the response signifies an error (for now, StatusCode != 200).
// If so, it returns the error.
// Otherwise, it returns nil.
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func extractError(resp *http.Response) error {
if resp.StatusCode == 200 {
return nil
Expand All @@ -82,6 +89,7 @@ func extractError(resp *http.Response) error {
}

// stripTransaction gets a transaction of the form "tx-XXXXXXXX" and truncates the "tx-" part, if it starts with "tx-"
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func stripTransaction(tx string) string {
if strings.HasPrefix(tx, "tx-") {
return strings.SplitAfter(tx, "-")[1]
Expand All @@ -90,6 +98,7 @@ func stripTransaction(tx string) string {
}

// mergeRawQueries merges two raw queries, appending an "&" if both are non-empty
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func mergeRawQueries(q1, q2 string) string {
if q1 == "" {
return q2
Expand All @@ -101,6 +110,7 @@ func mergeRawQueries(q1, q2 string) string {
}

// RawRequest submits the requests, and returns a map of the response fields
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) RawRequest(path string, request interface{}, requestMethod string, encodeJSON bool, headers []*Header) (
v map[string]interface{}, err error) {
response, err := client.submitFormRaw(path, request, requestMethod, encodeJSON, headers)
Expand All @@ -120,6 +130,7 @@ func (client Client) RawRequest(path string, request interface{}, requestMethod
}

// submitForm is a helper used for submitting (ex.) GETs and POSTs to the server
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) submitFormRaw(path string, request interface{}, requestMethod string, encodeJSON bool, headers []*Header) (resp *http.Response, err error) {
queryURL := client.serverURL

Expand Down Expand Up @@ -185,6 +196,7 @@ func (client Client) submitFormRaw(path string, request interface{}, requestMeth
return resp, nil
}

// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) submitForm(response interface{}, path string, request interface{}, requestMethod string, encodeJSON bool, headers []*Header) error {
resp, err := client.submitFormRaw(path, request, requestMethod, encodeJSON, headers)
if err != nil {
Expand All @@ -198,6 +210,7 @@ func (client Client) submitForm(response interface{}, path string, request inter
}

// get performs a GET request to the specific path against the server
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) get(response interface{}, path string, request interface{}, headers []*Header) error {
return client.submitForm(response, path, request, "GET", false /* encodeJSON */, headers)
}
Expand All @@ -210,11 +223,13 @@ func (client Client) post(response interface{}, path string, request interface{}
}

// as post, but with MethodPut
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) put(response interface{}, path string, request interface{}, headers []*Header) error {
return client.submitForm(response, path, request, "PUT", true /* encodeJSON */, headers)
}

// as post, but with MethodPatch
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) patch(response interface{}, path string, request interface{}, headers []*Header) error {
return client.submitForm(response, path, request, "PATCH", true /* encodeJSON */, headers)
}
24 changes: 24 additions & 0 deletions client/algod/wrappers.go
Expand Up @@ -15,48 +15,56 @@ import (

// Status retrieves the StatusResponse from the running node
// the StatusResponse includes data like the consensus version and current round
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) Status(headers ...*Header) (response models.NodeStatus, err error) {
err = client.get(&response, "/status", nil, headers)
return
}

// HealthCheck does a health check on the the potentially running node,
// returning an error if the API is down
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) HealthCheck(headers ...*Header) error {
return client.get(nil, "/health", nil, headers)
}

// StatusAfterBlock waits for a block to occur then returns the StatusResponse after that block
// blocks on the node end
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) StatusAfterBlock(blockNum uint64, headers ...*Header) (response models.NodeStatus, err error) {
err = client.get(&response, fmt.Sprintf("/status/wait-for-block-after/%d", blockNum), nil, headers)
return
}

// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
type pendingTransactionsParams struct {
Max uint64 `url:"max"`
}

// GetPendingTransactions asks algod for a snapshot of current pending txns on the node, bounded by maxTxns.
// If maxTxns = 0, fetches as many transactions as possible.
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) GetPendingTransactions(maxTxns uint64, headers ...*Header) (response models.PendingTransactions, err error) {
err = client.get(&response, fmt.Sprintf("/transactions/pending"), pendingTransactionsParams{maxTxns}, headers)
return
}

// Versions retrieves the VersionResponse from the running node
// the VersionResponse includes data like version number and genesis ID
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) Versions(headers ...*Header) (response models.Version, err error) {
err = client.get(&response, "/versions", nil, headers)
return
}

// LedgerSupply gets the supply details for the specified node's Ledger
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) LedgerSupply(headers ...*Header) (response models.Supply, err error) {
err = client.get(&response, "/ledger/supply", nil, headers)
return
}

// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
type transactionsByAddrParams struct {
FirstRound uint64 `url:"firstRound,omitempty"`
LastRound uint64 `url:"lastRound,omitempty"`
Expand All @@ -67,13 +75,15 @@ type transactionsByAddrParams struct {

// TransactionsByAddr returns all transactions for a PK [addr] in the [first,
// last] rounds range.
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) TransactionsByAddr(addr string, first, last uint64, headers ...*Header) (response models.TransactionList, err error) {
params := transactionsByAddrParams{FirstRound: first, LastRound: last}
err = client.get(&response, fmt.Sprintf("/account/%s/transactions", addr), params, headers)
return
}

// TransactionsByAddrLimit returns the last [limit] number of transaction for a PK [addr].
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) TransactionsByAddrLimit(addr string, limit uint64, headers ...*Header) (response models.TransactionList, err error) {
params := transactionsByAddrParams{Max: limit}
err = client.get(&response, fmt.Sprintf("/account/%s/transactions", addr), params, headers)
Expand All @@ -82,26 +92,30 @@ func (client Client) TransactionsByAddrLimit(addr string, limit uint64, headers

// TransactionsByAddrForDate returns all transactions for a PK [addr] in the [first,
// last] date range. Dates are of the form "2006-01-02".
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) TransactionsByAddrForDate(addr string, first, last string, headers ...*Header) (response models.TransactionList, err error) {
params := transactionsByAddrParams{FromDate: first, ToDate: last}
err = client.get(&response, fmt.Sprintf("/account/%s/transactions", addr), params, headers)
return
}

// AccountInformation also gets the AccountInformationResponse associated with the passed address
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) AccountInformation(address string, headers ...*Header) (response models.Account, err error) {
err = client.get(&response, fmt.Sprintf("/account/%s", address), nil, headers)
return
}

// AssetInformation also gets the AssetInformationResponse associated with the passed asset creator and index
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) AssetInformation(index uint64, headers ...*Header) (response models.AssetParams, err error) {
err = client.get(&response, fmt.Sprintf("/asset/%d", index), nil, headers)
return
}

// TransactionInformation gets information about a specific transaction involving a specific account
// it will only return information about transactions submitted to the node queried
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) TransactionInformation(accountAddress, transactionID string, headers ...*Header) (response models.Transaction, err error) {
transactionID = stripTransaction(transactionID)
err = client.get(&response, fmt.Sprintf("/account/%s/transaction/%s", accountAddress, transactionID), nil, headers)
Expand All @@ -117,6 +131,7 @@ func (client Client) TransactionInformation(accountAddress, transactionID string
//
// Or the transaction may have happened sufficiently long ago that the
// node no longer remembers it, and this will return an error.
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) PendingTransactionInformation(transactionID string, headers ...*Header) (response models.Transaction, err error) {
transactionID = stripTransaction(transactionID)
err = client.get(&response, fmt.Sprintf("/transactions/pending/%s", transactionID), nil, headers)
Expand All @@ -125,26 +140,30 @@ func (client Client) PendingTransactionInformation(transactionID string, headers

// TransactionByID gets a transaction by its ID. Works only if the indexer is enabled on the node
// being queried.
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) TransactionByID(transactionID string, headers ...*Header) (response models.Transaction, err error) {
transactionID = stripTransaction(transactionID)
err = client.get(&response, fmt.Sprintf("/transaction/%s", transactionID), nil, headers)
return
}

// SuggestedFee gets the recommended transaction fee from the node
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) SuggestedFee(headers ...*Header) (response models.TransactionFee, err error) {
err = client.get(&response, "/transactions/fee", nil, headers)
return
}

// SuggestedParams gets the suggested transaction parameters
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) SuggestedParams(headers ...*Header) (response models.TransactionParams, err error) {
err = client.get(&response, "/transactions/params", nil, headers)
return
}

// BuildSuggestedParams gets the suggested transaction parameters and
// builds a types.SuggestedParams to pass to transaction builders (see package future)
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) BuildSuggestedParams(headers ...*Header) (response types.SuggestedParams, err error) {
var httpResponse models.TransactionParams
err = client.get(&httpResponse, "/transactions/params", nil, headers)
Expand All @@ -159,6 +178,7 @@ func (client Client) BuildSuggestedParams(headers ...*Header) (response types.Su
}

// SendRawTransaction gets the bytes of a SignedTxn and broadcasts it to the network
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) SendRawTransaction(stx []byte, headers ...*Header) (response models.TransactionID, err error) {
// Set default Content-Type, if not the user didn't specify it.
addContentType := true
Expand All @@ -176,11 +196,13 @@ func (client Client) SendRawTransaction(stx []byte, headers ...*Header) (respons
}

// Block gets the block info for the given round
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) Block(round uint64, headers ...*Header) (response models.Block, err error) {
err = client.get(&response, fmt.Sprintf("/block/%d", round), nil, headers)
return
}

// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func responseReadAll(resp *http.Response, maxContentLength int64) (body []byte, err error) {
if resp.ContentLength > 0 {
// more efficient path if we know the ContentLength
Expand All @@ -196,6 +218,7 @@ func responseReadAll(resp *http.Response, maxContentLength int64) (body []byte,
}

// BlockRaw gets the raw block msgpack bytes for the given round
// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) BlockRaw(round uint64, headers ...*Header) (blockbytes []byte, err error) {
var resp *http.Response
request := struct {
Expand All @@ -210,6 +233,7 @@ func (client Client) BlockRaw(round uint64, headers ...*Header) (blockbytes []by
return responseReadAll(resp, 10000000)
}

// Deprecated: v1 algod client is deprecated, please use the v2 algod client.
func (client Client) doGetWithQuery(ctx context.Context, path string, queryArgs map[string]string) (result string, err error) {
queryURL := client.serverURL
queryURL.Path = path
Expand Down
4 changes: 4 additions & 0 deletions client/v2/common/models/block.go
Expand Up @@ -10,6 +10,10 @@ type Block struct {
// GenesisId (gen) ID to which this block belongs.
GenesisId string `json:"genesis-id"`

// ParticipationUpdates participation account data that needs to be checked/acted
// on by the network.
ParticipationUpdates ParticipationUpdates `json:"participation-updates,omitempty"`

// PreviousBlockHash (prev) Previous block hash.
PreviousBlockHash []byte `json:"previous-block-hash"`

Expand Down
9 changes: 9 additions & 0 deletions client/v2/common/models/participation_updates.go
@@ -0,0 +1,9 @@
package models

// ParticipationUpdates participation account data that needs to be checked/acted
// on by the network.
type ParticipationUpdates struct {
// ExpiredParticipationAccounts (partupdrmv) a list of online accounts that needs
// to be converted to offline since their participation key expired.
ExpiredParticipationAccounts []string `json:"expired-participation-accounts,omitempty"`
}
12 changes: 10 additions & 2 deletions client/v2/indexer/searchForAccounts.go
Expand Up @@ -48,7 +48,11 @@ type SearchAccountsParams struct {
NextToken string `url:"next,omitempty"`

// Round include results for the specified round. For performance reasons, this
// parameter may be disabled on some configurations.
// parameter may be disabled on some configurations. Using application-id or
// asset-id filters will return both creator and opt-in accounts. Filtering by
// include-all will return creator and opt-in accounts for deleted assets and
// accounts. Non-opt-in managers are not included in the results when asset-id is
// used.
Round uint64 `url:"round,omitempty"`
}

Expand Down Expand Up @@ -124,7 +128,11 @@ func (s *SearchAccounts) NextToken(NextToken string) *SearchAccounts {
}

// Round include results for the specified round. For performance reasons, this
// parameter may be disabled on some configurations.
// parameter may be disabled on some configurations. Using application-id or
// asset-id filters will return both creator and opt-in accounts. Filtering by
// include-all will return creator and opt-in accounts for deleted assets and
// accounts. Non-opt-in managers are not included in the results when asset-id is
// used.
func (s *SearchAccounts) Round(Round uint64) *SearchAccounts {
s.p.Round = Round
return s
Expand Down
10 changes: 4 additions & 6 deletions future/dryrun.go
Expand Up @@ -154,14 +154,12 @@ type DryrunResponse struct {
}

func NewDryrunResponse(d models.DryrunResponse) (DryrunResponse, error) {
// TODO: this is lazy but also works?
dr := DryrunResponse{}
b, err := json.Marshal(dr)
// Marshal and unmarshal to fix integer types.
b, err := json.Marshal(d)
if err != nil {
return dr, err
return DryrunResponse{}, err
}
err = json.Unmarshal(b, &dr)
return dr, err
return NewDryrunResponseFromJson(b)
}

func NewDryrunResponseFromJson(js []byte) (DryrunResponse, error) {
Expand Down
1 change: 1 addition & 0 deletions test/unit.tags
Expand Up @@ -19,6 +19,7 @@
@unit.responses.genesis
@unit.responses.messagepack
@unit.responses.messagepack.231
@unit.responses.participationupdates
@unit.responses.unlimited_assets
@unit.sourcemap
@unit.stateproof.paths
Expand Down

0 comments on commit ac817f7

Please sign in to comment.