Releases: onflow/flow-go-sdk
Version 0.7.0
Network Compatibility
Emulator v0.4.0 | Emulator v0.5.0 | Testnet | Mainnet |
---|---|---|---|
❌ | ✅ | ❌ | ❌ |
💥 Breaking Changes
Transaction arguments (#67)
Due to a bug that was causing transaction arguments to be encoded in an inconsistent manner (#66), the flow.Transaction#Arguments
field has been updated to be typed as [][]byte
rather than []cadence.Value
.
This in turn necessitated a change to the flow.Transaction#AddArgument
function:
AddArgument
function signature changed tofunc (tx *Transaction) AddArgument(arg cadence.Value) error
- This function performs JSON-CDC encoding of the provided argument, and therefore has the potential to produce an error.
AddRawArgument
function introduced:func (tx *Transaction) AddRawArgument(arg []byte) *Transaction
- This is a chainable function that can be used to add pre-encoded arguments.
Transaction templates (#78)
The helpers defined in the templates
package have changed to use parameterized transactions and arguments rather than naive string templates. This approach is more flexible and will allow templates to be easily shared between different SDK implementations.
This change breaks the old API by changing the return type of each template function to *flow.Transaction
.
For example, this is the signature for templates.CreateAccount
:
// CreateAccount generates a transaction that creates a new account.
//
// This template accepts a list of public keys and a code argument, both of which are optional.
//
// The final argument is the address of the account that will pay the account creation fee.
// This account is added as a transaction authorizer and therefore must sign the resulting transaction.
func CreateAccount(accountKeys []*flow.AccountKey, code []byte, payer flow.Address) *flow.Transaction
The partial transactions returned by these helpers functions can later be signed and sent to the Access API.
Cadence v0.5.0 (#77)
The Go SDK has been upgraded to use the latest Cadence release. Please view the Cadence release notes for an overview of the features and changes introduced in this release: https://github.com/onflow/cadence/releases/tag/v0.5.0
🐛 Bug Fixes
- See transaction arguments change above
⭐ Features
- Added
flow.SignUserMessage
function to support signing of user messages (#76). Example usage
Version 0.6.0
💥 Breaking Changes
RPC errors
This release introduces a dedicated client.RPCError
type for errors returned by the Access API. (#62)
client.RPCError
implements the interface defined in the status.FromError
function from the google.golang.org/grpc/status
package:
import "google.golang.org/grpc/status"
res, err := c.GetTransactionResult(...)
if err != nil {
s, ok := status.FromError(err)
...
}
client.RPCError
can also be unwrapped to produce the original gRPC error:
grpcErr := errors.Unwrap(rpcErr)
Removed crypto.KeyType
enum
The crypto.KeyType
enum was removed because it is no longer required by the rest of the SDK. (#58)
Version 0.5.0
💥 Breaking Changes
Script arguments
Added support for script arguments, which allows Cadence values to be passed as arguments to ExecuteScript
calls. This change affects the following functions on client.Client
:
ExecuteScriptAtLatestBlock
ExecuteScriptAtBlockID
ExecuteScriptAtBlockHeight
Each of these functions now takes an additional argument of type []cadence.Value
. For scripts that do not require any arguments, simply pass nil
:
result, _ := c.ExecuteScriptAtLatestBlock(ctx, myBlockID, myScript, nil)
Note: script arguments are not yet supported in the emulator.
🐛 Bug Fixes
- Added thread safety to the
flow.Transaction#ID
function. This fixes a previous race condition that would occur when generating transaction IDs from multiple routines.
⭐ Features
- Added
flow.TransactionStatusExpired
status to theflow.TransactionStatus
enum.- Note: transaction expiry is not yet supported by the emulator.
Version 0.4.1
🐛 Bug Fixes
- Patch the following Access API client methods to support versions of the Access API that do not include a
Timestamp
field inBlock
andBlockHeader
responses: (#47)GetLatestBlock
,GetBlockAtHeight
,GetBlockByID
GetLatestBlockHeader
,GetBlockHeaderAtHeight
,GetBlockHeaderByID
Version 0.4.0
💥 Breaking Changes
Cadence
- Cadence has been upgraded to
v0.4.0
: https://github.com/onflow/cadence/releases/tag/v0.4.0
The AuthAccount
constructor signature has changed from this:
AuthAccount(publicKeys: [[Int]], code: [Int])
to this:
let account = AuthAccount(payer: AuthAccount)
This allows for another account that isn't the transaction payer to pay for the creation of a new account.
The constructor also no longer takes publicKeys
and code
arguments -- these fields must be provided via the addPublicKey
and setCode
methods.
Example
This transaction:
transaction {
prepare() {
let acct = AuthAccount(keys: keys, code: code)
}
}
now becomes this:
transaction {
prepare(signer: AuthAccount) {
let acct = AuthAccount(payer: signer)
for key in keys {
acct.addPublicKey(key)
}
acct.setCode(code)
}
}
This also means that the account creation transaction requires an authorizer. For cases where you were previously signing with a single payer, you can make this change to use the same payer to pay the transaction fee and account creation fee.
// Old code
tx := flow.NewTransaction().
SetScript(createAccount).
SetPayer(payerAddress)
_, = tx.SignEnvelope(payerAddress, payerKey, payerSigner)
// New code
tx := flow.NewTransaction().
SetScript(createAccount).
SetPayer(payerAddress).
AddAuthorizer(payerAddress) // add payerAddress as an authorizer
_, = tx.SignEnvelope(payerAddress, payerKey, payerSigner)
Account Addresses
Changes introduced in #36 and #41.
- Address length has changed from 20 bytes to 8 bytes (64 bits).
- Address generation no longer follows a monotonic sequence; addresses are now generated in a deterministic but non-monotonic sequence.
- Each network (
Mainnet
,Testnet
andEmulator
) uses different parameters for address generation, meaning that addresses are not compatible across networks.
AddressGenerator
The flow.AddressGenerator
struct can be used to generate addresses for a specific network. Here's an example:
gen := flow.NewAddressGenerator(flow.Mainnet)
// get the current address
addressA := gen.Address()
// increment state
gen.Next()
// get the next address
addressB := gen.Address()
// skip to index 42
gen.SetIndex(42)
addressC := gen.Address()
// check if an address is valid for a network
if !addressC.IsValid(flow.Testnet) {
fmt.Println("Invalid testnet address!")
}
Other Breaking Changes
flow.ZeroAddress
was renamed toflow.EmptyAddress
flow.ZeroID
was renamed toflow.EmptyID
⭐ Features
- Transactions now support Cadence arguments, which can be used with parameterized scripts to create reusable transactions. (#43) Example
flow.AccountKey#SetPublicKey
now automatically sets theSigAlgo
field based on the provided public key. (#35)flow.BlockHeader
now includes aTimestamp
field. (#42)- The
flow.Mainnet
,flow.Testnet
andflow.Emulator
ChainID
constants were introduced to differentiate between different networks.
⚙️ Installing & Upgrading
go get github.com/onflow/[email protected]
Version 0.4.0 (Beta 1)
⚠️ Breaking Changes
Cadence
Upgrade to Cadence v0.4.0-beta1
: https://github.com/onflow/cadence/releases/tag/v0.4.0-beta1
The AuthAccount
constructor signature has changed from this:
AuthAccount(publicKeys: [[Int]], code: [Int])
to this:
let account = AuthAccount(payer: AuthAccount)
This allows for another account that isn't the transaction payer to pay for the creation of a new account.
The constructor also no longer takes publicKeys
and code
arguments -- these fields must be provided via the addPublicKey
and setCode
methods.
Example
This transaction:
transaction {
prepare() {
let acct = AuthAccount(keys: keys, code: code)
}
}
now becomes this:
transaction {
prepare(signer: AuthAccount) {
let acct = AuthAccount(payer: signer)
for key in keys {
acct.addPublicKey(key)
}
acct.setCode(code)
}
}
This also means that the account creation transaction requires an authorizer. For cases where you were previously signing with a single payer, you can make this change to use the same payer to pay the transaction fee and account creation fee.
// Old code
tx := flow.NewTransaction().
SetScript(createAccount).
SetPayer(payerAddress)
_, = tx.SignEnvelope(payerAddress, payerKey, payerSigner)
// New code
tx := flow.NewTransaction().
SetScript(createAccount).
SetPayer(payerAddress).
AddAuthorizer(payerAddress) // add payerAddress as an authorizer
_, = tx.SignEnvelope(payerAddress, payerKey, payerSigner)
Version 0.1.1
Compatible Emulator version: v0.1.1
🐛 Bug Fixes
- Fix
GetAccount
to returnAccountKey
values with correctID
field. Previously the ID for each key was set to zero.
⬆️ Upgrade
go get github.com/onflow/[email protected]
This update is compatible with the latest emulator release, which is included in the Flow CLI. To upgrade the CLI, follow these steps.
If you're running the emulator with Docker, simply bump your image version:
gcr.io/dl-flow/emulator:v0.1.1