Skip to content

Commit

Permalink
Merge pull request #158 from algorand/release/1.4.0
Browse files Browse the repository at this point in the history
Release/1.4.0
  • Loading branch information
algorotem authored Jun 1, 2020
2 parents 0e85660 + ebda991 commit c178ae5
Show file tree
Hide file tree
Showing 49 changed files with 4,905 additions and 1,064 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ language: go

go:
- "1.12"
- "1.13"
- "1.14"

install:
- go get -u golang.org/x/lint/golint
- curl https://raw.githubusercontent.com/algorand/algorand-sdk-testing/master/scripts/sdkupdate.sh -o ~/sdkupdate.sh
- chmod +x ~/sdkupdate.sh

script:
- set -e
- go test `go list ./... | grep -v test`
- test/docker/run_docker.sh
- make docker-test
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.4.0
# Added
- Clients for Indexer V2 and algod API V2
# 1.3.0
# Added
- additional Algorand Smart Contracts (ASC)
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SRCPATH := $(shell pwd)
TEST_SOURCES := $(shell cd $(SRCPATH) && go list ./...)
TEST_SOURCES_NO_CUCUMBER := $(shell cd $(SRCPATH) && go list ./... | grep -v test)

lint:
golint `go list ./... | grep -v /vendor/`
Expand All @@ -9,3 +10,14 @@ generate:

build: generate
cd $(SRCPATH) && go test -run xxx_phony_test $(TEST_SOURCES)

unit:
go test $(TEST_SOURCES_NO_CUCUMBER)
cd test && go test --godog.strict=true --godog.format=progress --godog.tags="@unit.offline,@unit.algod,@unit.indexer" --test.v .

integration:
go test $(TEST_SOURCES_NO_CUCUMBER)
cd test && go test --godog.strict=true --godog.format=progress --godog.tags="@algod,@assets,@auction,@kmd,@send,@template,@indexer" --test.v .

docker-test:
./test/docker/run_docker.sh
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ In `client/`, the `algod` and `kmd` packages provide HTTP clients for their corr

`mnemonic` contains support for turning 32-byte keys into checksummed, human-readable mnemonics (and going from mnemonics back to keys).

# SDK Development

Run tests with `make docker-test`

# Quick Start
To download the SDK, open a terminal and use the `go get` command.

Expand Down Expand Up @@ -996,4 +1000,4 @@ params := types.SuggestedParams {
// signing and sending "txn" will send "amount" assets from "revocationTarget" to "recipient",
// if and only if sender == clawback manager for this asset
txn, err = MakeAssetRevocationTxn(revocationManager, revocationTarget, amount, recipient, note, params, assetIndex);
```
```
9 changes: 3 additions & 6 deletions client/algod/algod.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,9 @@ func (client Client) submitFormRaw(path string, request interface{}, requestMeth
return nil, err
}

// If we add another endpoint that does not require auth, we should add a
// requiresAuth argument to submitForm rather than checking here
if path != healthCheckEndpoint {
req.Header.Set(authHeader, client.apiToken)
}
// Add the client headers.
// Normally this would not always be set, but due to https://github.com/algorand/go-algorand/issues/1009 it is always needed
req.Header.Set(authHeader, client.apiToken)

for _, header := range client.headers {
req.Header.Add(header.Key, header.Value)
}
Expand Down
14 changes: 13 additions & 1 deletion client/algod/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"errors"
"fmt"
"github.com/algorand/go-algorand-sdk/types"
"io"
"io/ioutil"
"net/http"
"strings"

"github.com/algorand/go-algorand-sdk/client/algod/models"
"github.com/algorand/go-algorand-sdk/types"
)

// Status retrieves the StatusResponse from the running node
Expand Down Expand Up @@ -159,6 +160,17 @@ func (client Client) BuildSuggestedParams(headers ...*Header) (response types.Su

// SendRawTransaction gets the bytes of a SignedTxn and broadcasts it to the network
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;
for _, header := range headers {
if strings.ToLower(header.Key) == "content-type" {
addContentType = false;
break;
}
}
if addContentType {
headers = append(headers, &Header{"Content-Type", "application/x-binary"});
}
err = client.post(&response, "/transactions", stx, headers)
return
}
Expand Down
18 changes: 18 additions & 0 deletions client/v2/algod/accountInformation.go
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
}
82 changes: 82 additions & 0 deletions client/v2/algod/algod.go
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}
}
34 changes: 34 additions & 0 deletions client/v2/algod/block.go
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
}
14 changes: 14 additions & 0 deletions client/v2/algod/healthCheck.go
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)
}
29 changes: 29 additions & 0 deletions client/v2/algod/pendingTransactionInformation.go
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
}
27 changes: 27 additions & 0 deletions client/v2/algod/pendingTransactions.go
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
}
29 changes: 29 additions & 0 deletions client/v2/algod/pendingTransactionsByAddress.go
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
}
34 changes: 34 additions & 0 deletions client/v2/algod/sendRawTransaction.go
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
}
Loading

0 comments on commit c178ae5

Please sign in to comment.