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

FOR REVIEW ONLY - go-algorand-sdk v1.16.0 #328

Merged
merged 21 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
19 changes: 19 additions & 0 deletions .github/workflows/codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "SDK Code Generation"
on:
schedule:
- cron: '20 23 * * *'
permissions:
contents: write
pull-requests: write
jobs:
generate_and_pr:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Generate and PR
uses: algorand/generator/.github/actions/sdk-codegen/@master
with:
args: "-k GO"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# 1.16.0

## Important Note
This release includes an upgrade to golang 1.17.

## What's Changed
* Adding `Foreign*` args to AddMethodCallParams by @barnjamin in https://github.com/algorand/go-algorand-sdk/pull/318
* build: Bump golang to 1.17 by @Eric-Warehime in https://github.com/algorand/go-algorand-sdk/pull/314
* Update generated files by @Eric-Warehime in https://github.com/algorand/go-algorand-sdk/pull/321
* Copy foreign arrays before modifying by @algoidurovic in https://github.com/algorand/go-algorand-sdk/pull/323
* Build: Sdk code generation automation by @Eric-Warehime in https://github.com/algorand/go-algorand-sdk/pull/324
* Update codegen.yml by @Eric-Warehime in https://github.com/algorand/go-algorand-sdk/pull/325
* Generate updated API client code by @algoidurovic in https://github.com/algorand/go-algorand-sdk/pull/316

## New Contributors
* @Eric-Warehime made their first contribution in https://github.com/algorand/go-algorand-sdk/pull/314

# 1.15.0
* adding foreign app addr to dryrun creator ([#312](https://github.com/algorand/go-algorand-sdk/pull/312))
* adding dryrun stack printer ([#289](https://github.com/algorand/go-algorand-sdk/pull/289))
Expand Down
4 changes: 4 additions & 0 deletions client/v2/algod/algod.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func (c *Client) TealCompile(source []byte) *TealCompile {
return &TealCompile{c: c, source: source}
}

func (c *Client) TealDisassemble(source []byte) *TealDisassemble {
return &TealDisassemble{c: c, source: source}
}

func (c *Client) TealDryrun(request models.DryrunRequest) *TealDryrun {
return &TealDryrun{c: c, request: request}
}
Expand Down
13 changes: 13 additions & 0 deletions client/v2/algod/getProof.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ type GetProofParams struct {

// Format configures whether the response object is JSON or MessagePack encoded.
Format string `url:"format,omitempty"`

// Hashtype the type of hash function used to create the proof, must be one of:
// * sha512_256
// * sha256
Hashtype string `url:"hashtype,omitempty"`
}

// GetProof get a Merkle proof for a transaction in a block.
Expand All @@ -25,6 +30,14 @@ type GetProof struct {
p GetProofParams
}

// Hashtype the type of hash function used to create the proof, must be one of:
// * sha512_256
// * sha256
func (s *GetProof) Hashtype(Hashtype string) *GetProof {
s.p.Hashtype = Hashtype
return s
}

// Do performs the HTTP request
func (s *GetProof) Do(ctx context.Context, headers ...*common.Header) (response models.ProofResponse, err error) {
err = s.c.get(ctx, &response, fmt.Sprintf("/v2/blocks/%v/transactions/%v/proof", s.round, s.txid), s.p, headers)
Expand Down
19 changes: 18 additions & 1 deletion client/v2/algod/tealCompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,31 @@ import (
"github.com/algorand/go-algorand-sdk/client/v2/common/models"
)

// TealCompileParams contains all of the query parameters for url serialization.
type TealCompileParams struct {

// Sourcemap when set to `true`, returns the source map of the program as a JSON.
// Defaults to `false`.
Sourcemap bool `url:"sourcemap,omitempty"`
}

// TealCompile given TEAL source code in plain text, return base64 encoded program
// bytes and base32 SHA512_256 hash of program bytes (Address style). This endpoint
// is only enabled when a node's configureation file sets EnableDeveloperAPI to
// is only enabled when a node's configuration file sets EnableDeveloperAPI to
// true.
type TealCompile struct {
c *Client

source []byte

p TealCompileParams
}

// Sourcemap when set to `true`, returns the source map of the program as a JSON.
// Defaults to `false`.
func (s *TealCompile) Sourcemap(Sourcemap bool) *TealCompile {
s.p.Sourcemap = Sourcemap
return s
}

// Do performs the HTTP request
Expand Down
23 changes: 23 additions & 0 deletions client/v2/algod/tealDisassemble.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package algod

import (
"context"

"github.com/algorand/go-algorand-sdk/client/v2/common"
"github.com/algorand/go-algorand-sdk/client/v2/common/models"
)

// TealDisassemble given the program bytes, return the TEAL source code in plain
// text. This endpoint is only enabled when a node's configuration file sets
// EnableDeveloperAPI to true.
type TealDisassemble struct {
c *Client

source []byte
}

// Do performs the HTTP request
func (s *TealDisassemble) Do(ctx context.Context, headers ...*common.Header) (response models.DisassembleResponse, err error) {
err = s.c.get(ctx, &response, "/v2/teal/disassemble", nil, headers)
return
}
2 changes: 1 addition & 1 deletion client/v2/algod/tealDryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// TealDryrun executes TEAL program(s) in context and returns debugging information
// about the execution. This endpoint is only enabled when a node's configureation
// about the execution. This endpoint is only enabled when a node's configuration
// file sets EnableDeveloperAPI to true.
type TealDryrun struct {
c *Client
Expand Down
3 changes: 3 additions & 0 deletions client/v2/common/models/compile_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ type CompileResponse struct {

// Result base64 encoded program bytes
Result string `json:"result"`

// Sourcemap jSON of the source map
Sourcemap *map[string]interface{} `json:"sourcemap,omitempty"`
}
7 changes: 7 additions & 0 deletions client/v2/common/models/disassemble_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package models

// DisassembleResponse teal disassembly Result
type DisassembleResponse struct {
// Result disassembled Teal code
Result string `json:"result"`
}
9 changes: 8 additions & 1 deletion client/v2/common/models/dryrun_txn_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ type DryrunTxnResult struct {
// AppCallTrace
AppCallTrace []DryrunState `json:"app-call-trace,omitempty"`

// Cost execution cost of app call transaction
// BudgetAdded budget added during execution of app call transaction.
BudgetAdded uint64 `json:"budget-added,omitempty"`

// BudgetConsumed budget consumed during execution of app call transaction.
BudgetConsumed uint64 `json:"budget-consumed,omitempty"`

// Cost net cost of app execution. Field is DEPRECATED and is subject for removal.
// Instead, use `budget-added` and `budget-consumed.
Cost uint64 `json:"cost,omitempty"`

// Disassembly disassembled program line by line.
Expand Down
2 changes: 1 addition & 1 deletion client/v2/common/models/proof_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package models
// ProofResponse proof of transaction in a block.
type ProofResponse struct {
// Hashtype the type of hash function used to create the proof, must be one of:
// * sumhash
// * sha512_256
// * sha256
Hashtype string `json:"hashtype,omitempty"`

// Idx index of the transaction in the block's payset.
Expand Down
3 changes: 2 additions & 1 deletion client/v2/indexer/lookupAccountTransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ type LookupAccountTransactionsParams struct {
TXID string `url:"txid,omitempty"`
}

// LookupAccountTransactions lookup account transactions.
// LookupAccountTransactions lookup account transactions. Transactions are returned
// newest to oldest.
type LookupAccountTransactions struct {
c *Client

Expand Down
3 changes: 2 additions & 1 deletion client/v2/indexer/lookupAssetTransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ type LookupAssetTransactionsParams struct {
TXID string `url:"txid,omitempty"`
}

// LookupAssetTransactions lookup transactions for an asset.
// LookupAssetTransactions lookup transactions for an asset. Transactions are
// returned oldest to newest.
type LookupAssetTransactions struct {
c *Client

Expand Down
4 changes: 3 additions & 1 deletion client/v2/indexer/searchForTransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ type SearchForTransactionsParams struct {
TXID string `url:"txid,omitempty"`
}

// SearchForTransactions search for transactions.
// SearchForTransactions search for transactions. Transactions are returned oldest
// to newest unless the address parameter is used, in which case results are
// returned newest to oldest.
type SearchForTransactions struct {
c *Client

Expand Down
30 changes: 26 additions & 4 deletions future/atomicTransactionComposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ type AddMethodCallParams struct {
RekeyTo types.Address
// A transaction Signer that can authorize this application call from sender
Signer TransactionSigner
// Any foreign apps to be passed that aren't part of the method signature.
// If apps are provided here, the apps specified in the method args will appear after these
ForeignApps []uint64
// Any foreign assets to be passed that aren't part of the method signature
// If assets are provided here, the assets specified in the method args will appear after these
ForeignAssets []uint64
// Any foreign accounts to be passed that aren't part of the method signature
// If accounts are provided here, the accounts specified in the method args will appear after these
ForeignAccounts []string
}

// ExecuteResult contains the results of successfully calling the Execute method on an
Expand Down Expand Up @@ -305,10 +314,23 @@ func (atc *AtomicTransactionComposer) AddMethodCall(params AddMethodCallParams)
}
}

var foreignAccounts []string
var foreignApps []uint64
var foreignAssets []uint64
refArgsResolved, err := populateMethodCallReferenceArgs(params.Sender.String(), params.AppID, refArgTypes, refArgValues, &foreignAccounts, &foreignApps, &foreignAssets)
// copy foreign arrays before modifying in populateMethodCallReferenceArgs
foreignAccounts := make([]string, len(params.ForeignAccounts))
copy(foreignAccounts, params.ForeignAccounts)
foreignApps := make([]uint64, len(params.ForeignApps))
copy(foreignApps, params.ForeignApps)
foreignAssets := make([]uint64, len(params.ForeignAssets))
copy(foreignAssets, params.ForeignAssets)

refArgsResolved, err := populateMethodCallReferenceArgs(
params.Sender.String(),
params.AppID,
refArgTypes,
refArgValues,
&foreignAccounts,
&foreignApps,
&foreignAssets,
)
if err != nil {
return err
}
Expand Down
46 changes: 46 additions & 0 deletions future/atomicTransactionComposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,52 @@ func TestAddMethodCall(t *testing.T) {
require.Equal(t, atc.Count(), 1)
}

func TestAddMethodCallWithManualForeignArgs(t *testing.T) {
var atc AtomicTransactionComposer
account := crypto.GenerateAccount()
txSigner := BasicAccountTransactionSigner{Account: account}
methodSig := "add(application)uint32"

method, err := abi.MethodFromSignature(methodSig)
require.NoError(t, err)

addr, err := types.DecodeAddress("DN7MBMCL5JQ3PFUQS7TMX5AH4EEKOBJVDUF4TCV6WERATKFLQF4MQUPZTA")
require.NoError(t, err)

arg_addr_str := "E4VCHISDQPLIZWMALIGNPK2B2TERPDMR64MZJXE3UL75MUDXZMADX5OWXM"
arg_addr, err := types.DecodeAddress(arg_addr_str)
require.NoError(t, err)

params := AddMethodCallParams{
AppID: 4,
Method: method,
Sender: addr,
Signer: txSigner,
MethodArgs: []interface{}{2},
ForeignApps: []uint64{1},
ForeignAssets: []uint64{5},
ForeignAccounts: []string{arg_addr_str},
}
err = atc.AddMethodCall(params)
require.NoError(t, err)
require.Equal(t, atc.GetStatus(), BUILDING)
require.Equal(t, atc.Count(), 1)
txns, err := atc.BuildGroup()
require.NoError(t, err)

require.Equal(t, len(txns[0].Txn.ForeignApps), 2)
require.Equal(t, txns[0].Txn.ForeignApps[0], types.AppIndex(1))
require.Equal(t, txns[0].Txn.ForeignApps[1], types.AppIndex(2))
// verify original params object hasn't changed.
require.Equal(t, params.ForeignApps, []uint64{1})

require.Equal(t, len(txns[0].Txn.ForeignAssets), 1)
require.Equal(t, txns[0].Txn.ForeignAssets[0], types.AssetIndex(5))

require.Equal(t, len(txns[0].Txn.Accounts), 1)
require.Equal(t, txns[0].Txn.Accounts[0], arg_addr)
}

func TestGatherSignatures(t *testing.T) {
var atc AtomicTransactionComposer
account := crypto.GenerateAccount()
Expand Down
11 changes: 8 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
module github.com/algorand/go-algorand-sdk

go 1.16
go 1.17

require (
github.com/algorand/go-algorand v0.0.0-20220323144801-17c0feef002f
github.com/algorand/go-codec/codec v1.1.8
github.com/cucumber/godog v0.8.1
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-querystring v1.0.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.7.1
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
Loading