Skip to content

Commit

Permalink
Release 1.3.0 (#130)
Browse files Browse the repository at this point in the history
# Added
-  additional Algorand Smart Contracts (ASC)
    -  support for Dynamic Fee contract
    -  support for Limit Order contract
    -  support for Periodic Payment contract
- support for SuggestedParams
- support for RawBlock request
- Missing transaction types
  • Loading branch information
algorotem authored Mar 24, 2020
1 parent 32dccac commit 0e85660
Show file tree
Hide file tree
Showing 29 changed files with 4,305 additions and 177 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ coverage.html

# Mac
.DS_Store

# Testing files
*.feature
temp
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ install:
- chmod +x ~/sdkupdate.sh

script:
- make build
- ~/sdkupdate.sh --go
- set -e
- go test `go list ./... | grep -v test`
- test/docker/run_docker.sh
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 1.3.0
# Added
- additional Algorand Smart Contracts (ASC)
- support for Dynamic Fee contract
- support for Limit Order contract
- support for Periodic Payment contract
- support for SuggestedParams
- support for RawBlock request
- Missing transaction types
# 1.2.1
# Added
- Added asset decimals field.
Expand Down
206 changes: 138 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,13 @@ func main() {

// Get the suggested transaction parameters
txParams, err := algodClient.SuggestedParams()
if err != nil {
fmt.Printf("error getting suggested tx params: %s\n", err)
return
}
if err != nil {
fmt.Printf("error getting suggested tx params: %s\n", err)
return
}

// Make transaction
genID := txParams.GenesisID
genHash := txParams.GenesisHash
tx, err := transaction.MakePaymentTxn(fromAddr, toAddr, 1000, 200000, txParams.LastRound, (txParams.LastRound + 1000), nil, "", genID, genHash)
tx, err := future.MakePaymentTxn(fromAddr, toAddr, 1000, nil, "", txParams)
if err != nil {
fmt.Printf("Error creating transaction: %s\n", err)
return
Expand Down Expand Up @@ -453,6 +451,7 @@ import (
"github.com/algorand/go-algorand-sdk/crypto"
"github.com/algorand/go-algorand-sdk/mnemonic"
"github.com/algorand/go-algorand-sdk/transaction"
"github.com/algorand/go-algorand-sdk/types"
)

func main() {
Expand All @@ -470,9 +469,15 @@ func main() {
const amount = 20000
const firstRound = 642715
const lastRound = firstRound + 1000
tx, err := transaction.MakePaymentTxn(
params := types.SuggestedParams {
Fee: types.MicroAlgos(fee),
FirstRoundValid: firstRound,
LastRoundValid: lastRound,
GenesisHash: []byte("JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="),
}
tx, err := future.MakePaymentTxn(
account.Address.String(), "4MYUHDWHWXAKA5KA7U5PEN646VYUANBFXVJNONBK3TIMHEMWMD4UBOJBI4",
fee, amount, firstRound, lastRound, nil, "", "", []byte("JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="),
amount, nil, "", params
)
if err != nil {
fmt.Printf("Error creating transaction: %s\n", err)
Expand Down Expand Up @@ -560,17 +565,20 @@ if err != nil {
panic("invalid multisig parameters")
}
fromAddr, _ := ma.Address()
txn, err := transaction.MakePaymentTxn(
params := types.SuggestedParams {
Fee: types.MicroAlgos(fee), // fee per byte, unless FlatFee is true
FlatFee: false,
FirstRoundValid: types.Round(100000),
LastRoundValid: types.Round(101000),
GenesisHash: []byte, // cannot be empty in practice
}
txn, err := future.MakePaymentTxn(
fromAddr.String(),
"INSERTTOADDRESHERE",
10, // fee per byte
10000, // amount
100000, // first valid round
101000, // last valid round
nil, // note
"", // closeRemainderTo
"", // genesisID
[]byte, // genesisHash (Cannot be empty in practice)
nil, // note
"", // closeRemainderTo
params
)
txid, txBytes, err := crypto.SignMultisigTransaction(secretKey, ma, txn)
if err != nil {
Expand Down Expand Up @@ -651,24 +659,34 @@ func submitGroup() {
const fee = 1000
const amount1 = 2000
var note []byte
const genesisID = "XYZ" // replace me
const genesisID = "XYZ" // replace me
genesisHash := []byte("ABC") // replace me

const firstRound1 = 710399
tx1, err := transaction.MakePaymentTxnWithFlatFee(
address1, address2, fee, amount1, firstRound1, firstRound1+1000,
note, "", genesisID, genesisHash,
params := types.SuggestedParams {
Fee: types.MicroAlgos(fee),
FlatFee: true,
FirstRoundValid: types.Round(firstRound1),
LastRoundValid: types.Round(firstRound1+1000),
GenesisHash: genesisHash,
GenesisID: genesisID,
}
tx1, err := future.MakePaymentTxn(
address1, address2, amount1,
note, "", params
)
if err != nil {
fmt.Printf("Failed to create payment transaction: %v\n", err)
return
}

const firstRound2 = 710515
params.FirstRoundValid = types.Round(firstRound2)
params.LastRoundValid = types.Round(firstRound2 + 1000)
const amount2 = 1500
tx2, err := transaction.MakePaymentTxnWithFlatFee(
address2, address3, fee, amount2, firstRound2, firstRound2+1000,
note, "", genesisID, genesisHash,
tx2, err := future.MakePaymentTxn(
address2, address3, amount2,
note, "", params
)
if err != nil {
fmt.Printf("Failed to create payment transaction: %v\n", err)
Expand Down Expand Up @@ -757,13 +775,21 @@ func main() {
const fee = 1000
const amount = 2000
var note []byte
const genesisID = "XYZ" // replace me
const genesisID = "XYZ" // replace me
genesisHash := []byte("ABC") // replace me

const firstRound = 710399
tx, err := transaction.MakePaymentTxnWithFlatFee(
sender.String(), receiver, fee, amount, firstRound, firstRound+1000,
note, "", genesisID, genesisHash,
params := types.SuggestedParams {
Fee: types.MicroAlgos(fee),
FlatFee: true,
FirstRoundValid: types.Round(firstRound),
LastRoundValid: types.Round(firstRound+1000),
GenesisHash: genesisHash,
GenesisID: genesisID,
}
tx, err := future.MakePaymentTxn(
sender.String(), receiver, amount,
note, "", params
)

txid, stx, err := crypto.SignLogicsigTransaction(lsig, tx)
Expand All @@ -790,12 +816,12 @@ Asset creation: This allows a user to issue a new asset. The user can define the
whether there is an account that can revoke assets, whether there is an account that can freeze user accounts,
whether there is an account that can be considered the asset reserve, and whether there is an account that can change
the other accounts. The creating user can also do things like specify a name for the asset.
```golang
addr := "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4" // the account issuing the transaction; the asset creator
fee := uint64(10) // the number of microAlgos per byte to pay as a transaction fee
fee := types.MicroAlgos(10) // the number of microAlgos per byte to pay as a transaction fee
defaultFrozen := false // whether user accounts will need to be unfrozen before transacting
genesisHash := "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=" // hash of the genesis block of the network to be used
genesisHash, _ := base64.StdEncoding.DecodeString("SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=") // hash of the genesis block of the network to be used
totalIssuance := uint64(100) // total number of this asset in circulation
decimals := uint64(1) // hint to GUIs for interpreting base unit
reserve := addr // specified address is considered the asset reserve (it has no special privileges, this is only informational)
Expand All @@ -805,16 +831,24 @@ manager := addr // specified address can change reserve, freeze, clawback, and m
unitName := "tst" // used to display asset units to user
assetName := "testcoin" // "friendly name" of asset
genesisID := "" // like genesisHash this is used to specify network to be used
firstRound := uint64(322575) // first Algorand round on which this transaction is valid
lastRound := uint64(322575) // last Algorand round on which this transaction is valid
firstRound := types.Round(322575) // first Algorand round on which this transaction is valid
lastRound := types.Round(322575) // last Algorand round on which this transaction is valid
note := nil // arbitrary data to be stored in the transaction; here, none is stored
assetURL := "http://someurl" // optional string pointing to a URL relating to the asset
assetMetadataHash := "thisIsSomeLength32HashCommitment" // optional hash commitment of some sort relating to the asset. 32 character length.

params := types.SuggestedParams {
Fee: fee,
FirstRoundValid: firstRound,
LastRoundValid: lastRound,
GenesisHash: genesisHash,
GenesisID: genesisID,
}

// signing and sending "txn" allows "addr" to create an asset
txn, err = MakeAssetCreateTxn(addr, fee, firstRound, lastRound, note,
genesisID, genesisHash, totalIssuance, decimals, defaultFrozen, manager, reserve, freeze, clawback,
unitName, assetName, assetURL, assetMetadataHash)
txn, err = MakeAssetCreateTxn(addr, note, params,
totalIssuance, decimals, defaultFrozen, manager, reserve, freeze, clawback,
unitName, assetName, assetURL, assetMetadataHash)
```


Expand All @@ -824,27 +858,35 @@ Supplying an empty address is the same as turning the associated feature off for
is set to the empty address, it can never change again. For example, if an asset configuration transaction specifying
`clawback=""` were issued, the associated asset could never be revoked from asset holders, and `clawback=""` would be
true for all time. The `strictEmptyAddressChecking` argument can help guard against this, it causes
`MakeAssetConfigTxn` return error if any management address is set to empty.
`MakeAssetConfigTxn` return error if any management address is set to empty.

```golang
addr := "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
fee := uint64(10)
firstRound := uint64(322575)
lastRound := uint64(322575)
fee := types.MicroAlgos(10)
firstRound := types.Round(322575)
lastRound := types.Round(322575)
note := nil
genesisID := ""
genesisHash := "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
genesisHash, _ := base64.StdEncoding.DecodeString("SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=")
assetIndex := uint64(1234)
reserve := addr
freeze := addr
clawback := addr
manager := addr
strictEmptyAddressChecking := true

params := types.SuggestedParams {
Fee: fee,
FirstRoundValid: firstRound,
LastRoundValid: lastRound,
GenesisHash: genesisHash,
GenesisID: genesisID,
}

// signing and sending "txn" will allow the asset manager to change:
// asset manager, asset reserve, asset freeze manager, asset revocation manager
txn, err = MakeAssetConfigTxn(addr, fee, firstRound, lastRound, note,
genesisID, genesisHash, assetIndex, manager, reserve, freeze, clawback, strictEmptyAddressChecking)
txn, err = MakeAssetConfigTxn(addr, note, params,
assetIndex, manager, reserve, freeze, clawback, strictEmptyAddressChecking)
```


Expand All @@ -853,77 +895,105 @@ by the creator.

```golang
addr := "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
fee := uint64(10)
firstRound := uint64(322575)
lastRound := uint64(322575)
fee := types.MicroAlgos(10)
firstRound := types.Round(322575)
lastRound := types.Round(322575)
note := nil
genesisID := ""
genesisHash := "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
genesisHash, _ := base64.StdEncoding.DecodeString("SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=")
assetIndex := uint64(1234)

params := types.SuggestedParams {
Fee: fee,
FirstRoundValid: firstRound,
LastRoundValid: lastRound,
GenesisHash: genesisHash,
GenesisID: genesisID,
}
// if all outstanding assets are held by the asset creator,
// the asset creator can sign and issue "txn" to remove the asset from the ledger.
txn, err = MakeAssetDestroyTxn(addr, fee, firstRound, lastRound, note, genesisID, genesisHash, assetIndex)
txn, err = MakeAssetDestroyTxn(addr, note, params, assetIndex)
```

Begin accepting an asset: Before a user can begin transacting with an asset, the user must first issue an asset acceptance transaction.
This is a special case of the asset transfer transaction, where the user sends 0 assets to themself. After issuing this transaction,
the user can begin transacting with the asset. Each new accepted asset increases the user's minimum balance.
the user can begin transacting with the asset. Each new accepted asset increases the user's minimum balance.

```golang
addr := "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
fee := uint64(10)
firstRound := uint64(322575)
lastRound := uint64(322575)
fee := types.MicroAlgos(10)
firstRound := types.Round(322575)
lastRound := types.Round(322575)
note := nil
genesisID := ""
genesisHash := "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
genesisHash, _ := base64.StdEncoding.DecodeString("SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=")
assetIndex := uint64(1234)

params := types.SuggestedParams {
Fee: fee,
FirstRoundValid: firstRound,
LastRoundValid: lastRound,
GenesisHash: genesisHash,
GenesisID: genesisID,
}
// signing and sending "txn" allows sender to begin accepting asset specified by creator and index
txn, err = MakeAssetAcceptanceTxn(addr, fee, firstRound, lastRound, note, genesisID, genesisHash, assetIndex)
txn, err = MakeAssetAcceptanceTxn(addr, note, params, assetIndex)
```


Transfer an asset: This allows users to transact with assets, after they have issued asset acceptance transactions. The
optional `closeRemainderTo` argument can be used to stop transacting with a particular asset. Note: A frozen account can always close
out to the asset creator.
out to the asset creator.
```golang
addr := "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
sender := addr
recipient := "47YPQTIGQEO7T4Y4RWDYWEKV6RTR2UNBQXBABEEGM72ESWDQNCQ52OPASU"
closeRemainderTo := "" // supply an address to close remaining balance after transfer to supplied address
fee := uint64(10)
firstRound := uint64(322575)
lastRound := uint64(322575)
fee := types.MicroAlgos(10)
firstRound := types.Round(322575)
lastRound := types.Round(322575)
note := nil
genesisID := ""
genesisHash := "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
genesisHash, _ := base64.StdEncoding.DecodeString("SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=")
assetIndex := uint64(1234)
amount := uint64(10)

params := types.SuggestedParams {
Fee: fee,
FirstRoundValid: firstRound,
LastRoundValid: lastRound,
GenesisHash: genesisHash,
GenesisID: genesisID,
}

// signing and sending "txn" will send "amount" assets from "sender" to "recipient"
txn, err = MakeAssetTransferTxn(sender, recipient, closeRemainderTo, amount, fee, firstRound, lastRound, note,
genesisID, genesisHash, assetIndex);
txn, err = MakeAssetTransferTxn(sender, recipient, amount, note, params, closeRemainderTo, assetIndex);
```

Revoke an asset: This allows an asset's revocation manager to transfer assets on behalf of another user. It will only work when
issued by the asset's revocation manager.
```golang
revocationManager := "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4" // txn signed by this address
recipient := "47YPQTIGQEO7T4Y4RWDYWEKV6RTR2UNBQXBABEEGM72ESWDQNCQ52OPASU" // assets sent to this address
recipient := "47YPQTIGQEO7T4Y4RWDYWEKV6RTR2UNBQXBABEEGM72ESWDQNCQ52OPASU" // assets sent to this address
revocationTarget := "47YPQTIGQEO7T4Y4RWDYWEKV6RTR2UNBQXBABEEGM72ESWDQNCQ52OPASU" // assets come from this address
fee := uint64(10)
firstRound := uint64(322575)
lastRound := uint64(322575)
fee := types.MicroAlgos(10)
firstRound := types.Round(322575)
lastRound := types.Round(322575)
note := nil
genesisID := ""
genesisHash := "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
genesisHash, _ := base64.StdEncoding.DecodeString("SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=")
assetIndex := uint64(1234)
amount := uint64(10)

params := types.SuggestedParams {
Fee: fee,
FirstRoundValid: firstRound,
LastRoundValid: lastRound,
GenesisHash: genesisHash,
GenesisID: genesisID,
}

// 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, recipient, revocationTarget, amount, fee, firstRound, lastRound, note,
genesisID, genesisHash, assetIndex);
txn, err = MakeAssetRevocationTxn(revocationManager, revocationTarget, amount, recipient, note, params, assetIndex);
```
Loading

0 comments on commit 0e85660

Please sign in to comment.