-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from algorand/release/1.4.0
Release/1.4.0
- Loading branch information
Showing
49 changed files
with
4,905 additions
and
1,064 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,18 @@ | ||
package algod | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common/models" | ||
) | ||
|
||
type AccountInformation struct { | ||
c *Client | ||
account string | ||
} | ||
|
||
func (s *AccountInformation) Do(ctx context.Context, headers ...*common.Header) (result models.Account, err error) { | ||
err = s.c.get(ctx, &result, fmt.Sprintf("/v2/accounts/%s", s.account), nil, headers) | ||
return | ||
} |
This file contains 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,82 @@ | ||
package algod | ||
|
||
import ( | ||
"context" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common" | ||
) | ||
|
||
const algodAuthHeader = "X-Algo-API-Token" | ||
|
||
type Client common.Client | ||
|
||
// get performs a GET request to the specific path against the server, assumes JSON response | ||
func (c *Client) get(ctx context.Context, response interface{}, path string, request interface{}, headers []*common.Header) error { | ||
return (*common.Client)(c).Get(ctx, response, path, request, headers) | ||
} | ||
|
||
// getMsgpack performs a GET request to the specific path against the server, assumes msgpack response | ||
func (c *Client) getMsgpack(ctx context.Context, response interface{}, path string, request interface{}, headers []*common.Header) error { | ||
return (*common.Client)(c).GetRawMsgpack(ctx, response, path, request, headers) | ||
} | ||
|
||
// post sends a POST request to the given path with the given request object. | ||
// No query parameters will be sent if request is nil. | ||
// response must be a pointer to an object as post writes the response there. | ||
func (c *Client) post(ctx context.Context, response interface{}, path string, request interface{}, headers []*common.Header) error { | ||
return (*common.Client)(c).Post(ctx, response, path, request, headers) | ||
} | ||
|
||
// MakeClient is the factory for constructing a ClientV2 for a given endpoint. | ||
func MakeClient(address string, apiToken string) (c *Client, err error) { | ||
commonClient, err := common.MakeClient(address, algodAuthHeader, apiToken) | ||
c = (*Client)(commonClient) | ||
return | ||
} | ||
|
||
func (c *Client) AccountInformation(account string) *AccountInformation { | ||
return &AccountInformation{c: c, account: account} | ||
} | ||
|
||
func (c *Client) Block(round uint64) *Block { | ||
return &Block{c: c, round: round} | ||
} | ||
|
||
func (c *Client) HealthCheck() *HealthCheck { | ||
return &HealthCheck{c: c} | ||
} | ||
|
||
func (c *Client) PendingTransactionInformation(txid string) *PendingTransactionInformation { | ||
return &PendingTransactionInformation{c: c, txid: txid} | ||
} | ||
|
||
func (c *Client) PendingTransactionsByAddress(address string) *PendingTransactionInformationByAddress { | ||
return &PendingTransactionInformationByAddress{c: c, address: address} | ||
} | ||
|
||
func (c *Client) PendingTransactions() *PendingTransactions { | ||
return &PendingTransactions{c: c} | ||
} | ||
|
||
func (c *Client) SendRawTransaction(tx []byte) *SendRawTransaction { | ||
return &SendRawTransaction{c: c, stx: tx} | ||
} | ||
|
||
func (c *Client) StatusAfterBlock(round uint64) *StatusAfterBlock { | ||
return &StatusAfterBlock{c: c, round: round} | ||
} | ||
|
||
func (c *Client) Status() *Status { | ||
return &Status{c: c} | ||
} | ||
|
||
func (c *Client) SuggestedParams() *SuggestedParams { | ||
return &SuggestedParams{c: c} | ||
} | ||
|
||
func (c *Client) Supply() *Supply { | ||
return &Supply{c: c} | ||
} | ||
|
||
func (c *Client) Versions() *Versions { | ||
return &Versions{c: c} | ||
} |
This file contains 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,34 @@ | ||
package algod | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common/models" | ||
"github.com/algorand/go-algorand-sdk/types" | ||
) | ||
|
||
type Block struct { | ||
c *Client | ||
round uint64 | ||
p models.GetBlockParams | ||
} | ||
|
||
type generatedBlockResponse struct { | ||
// Block header data. | ||
Block types.Block `json:"block"` | ||
|
||
// Optional certificate object. This is only included when the format is set to message pack. | ||
Cert *map[string]interface{} `json:"cert,omitempty"` | ||
} | ||
|
||
func (s *Block) Do(ctx context.Context, headers ...*common.Header) (result types.Block, err error) { | ||
s.p.Format = "msgpack" | ||
var response generatedBlockResponse | ||
err = s.c.getMsgpack(ctx, &response, fmt.Sprintf("/v2/blocks/%d", s.round), s.p, headers) | ||
if err != nil { | ||
return | ||
} | ||
result = response.Block | ||
return | ||
} |
This file contains 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,14 @@ | ||
package algod | ||
|
||
import ( | ||
"context" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common" | ||
) | ||
|
||
type HealthCheck struct { | ||
c *Client | ||
} | ||
|
||
func (s *HealthCheck) Do(ctx context.Context, headers ...*common.Header) error { | ||
return s.c.get(ctx, nil, "/health", nil, headers) | ||
} |
This file contains 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,29 @@ | ||
package algod | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common/models" | ||
"github.com/algorand/go-algorand-sdk/types" | ||
) | ||
|
||
type PendingTransactionInformation struct { | ||
c *Client | ||
txid string | ||
p models.PendingTransactionInformationParams | ||
} | ||
|
||
func (s *PendingTransactionInformation) Max(max uint64) *PendingTransactionInformation { | ||
s.p.Max = max | ||
return s | ||
} | ||
|
||
// s.p.Format setter intentionally omitted: this SDK only uses msgpack. | ||
|
||
func (s *PendingTransactionInformation) Do(ctx context.Context, headers ...*common.Header) (response models.PendingTransactionInfoResponse, stxn types.SignedTxn, err error) { | ||
s.p.Format = "msgpack" | ||
err = s.c.getMsgpack(ctx, &response, fmt.Sprintf("/v2/transactions/pending/%s", s.txid), s.p, headers) | ||
stxn = response.Transaction | ||
return | ||
} |
This file contains 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,27 @@ | ||
package algod | ||
|
||
import ( | ||
"context" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common/models" | ||
"github.com/algorand/go-algorand-sdk/types" | ||
) | ||
|
||
type PendingTransactions struct { | ||
c *Client | ||
p models.PendingTransactionInformationParams | ||
} | ||
|
||
func (s *PendingTransactions) Max(max uint64) *PendingTransactions { | ||
s.p.Max = max | ||
return s | ||
} | ||
|
||
func (s *PendingTransactions) Do(ctx context.Context, headers ...*common.Header) (total uint64, topTransactions []types.SignedTxn, err error) { | ||
s.p.Format = "msgpack" | ||
response := models.PendingTransactionsResponse{} | ||
err = s.c.getMsgpack(ctx, &response, "/v2/transactions/pending", s.p, headers) | ||
total = response.TotalTransactions | ||
topTransactions = response.TopTransactions | ||
return | ||
} |
This file contains 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,29 @@ | ||
package algod | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common/models" | ||
"github.com/algorand/go-algorand-sdk/types" | ||
) | ||
|
||
type PendingTransactionInformationByAddress struct { | ||
c *Client | ||
address string | ||
p models.GetPendingTransactionsByAddressParams | ||
} | ||
|
||
func (s *PendingTransactionInformationByAddress) Max(max uint64) *PendingTransactionInformationByAddress { | ||
s.p.Max = max | ||
return s | ||
} | ||
|
||
func (s *PendingTransactionInformationByAddress) Do(ctx context.Context, headers ...*common.Header) (total uint64, topTransactions []types.SignedTxn, err error) { | ||
s.p.Format = "msgpack" | ||
response := models.PendingTransactionsResponse{} | ||
err = s.c.getMsgpack(ctx, &response, fmt.Sprintf("/v2/accounts/%s/transactions/pending", s.address), s.p, headers) | ||
total = response.TotalTransactions | ||
topTransactions = response.TopTransactions | ||
return | ||
} |
This file contains 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,34 @@ | ||
package algod | ||
|
||
import ( | ||
"context" | ||
"github.com/algorand/go-algorand-sdk/client/v2/common" | ||
"strings" | ||
) | ||
|
||
type SendRawTransaction struct { | ||
c *Client | ||
stx []byte | ||
} | ||
|
||
type txidresponse struct { | ||
TxID string `json:"txId"` | ||
} | ||
|
||
func (s *SendRawTransaction) Do(ctx context.Context, headers ...*common.Header) (txid string, err error) { | ||
var response txidresponse | ||
// Set default Content-Type, if the user didn't specify it. | ||
addContentType := true | ||
for _, header := range headers { | ||
if strings.ToLower(header.Key) == "content-type" { | ||
addContentType = false | ||
break | ||
} | ||
} | ||
if addContentType { | ||
headers = append(headers, &common.Header{"Content-Type", "application/x-binary"}) | ||
} | ||
err = s.c.post(ctx, &response, "/transactions", s.stx, headers) | ||
txid = response.TxID | ||
return | ||
} |
Oops, something went wrong.