Documentation ¶
Overview ¶
Package aeternity is the SDK user-facing code, e.g. convenience functions, helpers and utilities that one might want to use when creating/broadcasting transactions.
Index ¶
- func GetAccountsByName(n GetAnythingByNameFunc, name string) (addresses []string, err error)
- func GetChannelsByName(n GetAnythingByNameFunc, name string) (channels []string, err error)
- func GetContractsByName(n GetAnythingByNameFunc, name string) (contracts []string, err error)
- func GetOraclesByName(n GetAnythingByNameFunc, name string) (oracleIDs []string, err error)
- func Namehash(name string) []byte
- func SignBroadcastTransaction(tx rlp.Encoder, signingAccount *account.Account, n *naet.Node, ...) (signedTxStr, hash, signature string, err error)
- func SignBroadcastWaitTransaction(tx rlp.Encoder, signingAccount *account.Account, n *naet.Node, ...) (signedTxStr, hash, signature string, blockHeight uint64, blockHash string, ...)
- func WaitForTransactionForXBlocks(c getTransactionByHashHeighter, txHash string, x uint64) (blockHeight uint64, blockHash string, err error)
- type Context
- func (c *Context) ContractCallTx(ContractID, CallData string, AbiVersion uint16, ...) (tx *transactions.ContractCallTx, err error)
- func (c *Context) ContractCreateTx(Code string, CallData string, VMVersion, AbiVersion uint16, ...) (tx *transactions.ContractCreateTx, err error)
- func (c *Context) NameClaimTx(name string, nameSalt, fee *big.Int) (tx *transactions.NameClaimTx, err error)
- func (c *Context) NamePreclaimTx(name string, fee *big.Int) (tx *transactions.NamePreclaimTx, nameSalt *big.Int, err error)
- func (c *Context) NameRevokeTx(name string) (tx *transactions.NameRevokeTx, err error)
- func (c *Context) NameTransferTx(name string, recipientAddress string) (tx *transactions.NameTransferTx, err error)
- func (c *Context) NameUpdateTx(name string, targetAddress string) (tx *transactions.NameUpdateTx, err error)
- func (c *Context) OracleExtendTx(oracleID string, ttlType, ttlValue uint64) (tx *transactions.OracleExtendTx, err error)
- func (c *Context) OracleQueryTx(OracleID, Query string, QueryFee *big.Int, ...) (tx *transactions.OracleQueryTx, err error)
- func (c *Context) OracleRegisterTx(querySpec, responseSpec string, queryFee *big.Int, ...) (tx *transactions.OracleRegisterTx, err error)
- func (c *Context) OracleRespondTx(OracleID string, QueryID string, Response string, TTLType uint64, ...) (tx *transactions.OracleRespondTx, err error)
- func (c *Context) SpendTx(senderID string, recipientID string, amount, fee *big.Int, payload []byte) (tx *transactions.SpendTx, err error)
- type GetAnythingByNameFunc
- type GetNextNonceFunc
- type GetTTLFunc
- type GetTTLNonceFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAccountsByName ¶
func GetAccountsByName(n GetAnythingByNameFunc, name string) (addresses []string, err error)
GetAccountsByName returns any account_pubkey entries that it finds in a name's Pointers.
func GetChannelsByName ¶
func GetChannelsByName(n GetAnythingByNameFunc, name string) (channels []string, err error)
GetChannelsByName returns any channel entries that it finds in a name's Pointers.
func GetContractsByName ¶
func GetContractsByName(n GetAnythingByNameFunc, name string) (contracts []string, err error)
GetContractsByName returns any contract_pubkey entries that it finds in a name's Pointers.
func GetOraclesByName ¶
func GetOraclesByName(n GetAnythingByNameFunc, name string) (oracleIDs []string, err error)
GetOraclesByName returns any oracle_pubkey entries that it finds in a name's Pointers.
func Namehash ¶
Namehash calculate the Namehash of a string. Names within aeternity are generally referred to only by their namehashes.
The implementation is the same as ENS EIP-137 https://github.com/ethereum/EIPs/blob/master/EIPS/eip-137.md#namehash-algorithm but using Blake2b.
func SignBroadcastTransaction ¶
func SignBroadcastTransaction(tx rlp.Encoder, signingAccount *account.Account, n *naet.Node, networkID string) (signedTxStr, hash, signature string, err error)
SignBroadcastTransaction signs a transaction and broadcasts it to a node.
func SignBroadcastWaitTransaction ¶
func SignBroadcastWaitTransaction(tx rlp.Encoder, signingAccount *account.Account, n *naet.Node, networkID string, x uint64) (signedTxStr, hash, signature string, blockHeight uint64, blockHash string, err error)
SignBroadcastWaitTransaction is a convenience function that combines SignBroadcastTransaction and WaitForTransactionForXBlocks.
func WaitForTransactionForXBlocks ¶
func WaitForTransactionForXBlocks(c getTransactionByHashHeighter, txHash string, x uint64) (blockHeight uint64, blockHash string, err error)
WaitForTransactionForXBlocks blocks until a transaction has been mined or X blocks have gone by, after which it returns an error. The node polling interval can be config.Configured with config.Tuning.ChainPollInterval.
Types ¶
type Context ¶
type Context struct { GetTTL GetTTLFunc GetNonce GetNextNonceFunc GetTTLNonce GetTTLNonceFunc Address string }
Context is a struct that eases transaction creation. Specifically, the role of Context is to automate/hide the tedious details of transaction creation, such as filling in an unused account nonce and an appropriate TTL, so that the transaction creator only has to worry about the details relevant to the task at hand.
Example ¶
// Set the Network ID. For this example, setting the config.Node.NetworkID // is actually not needed - but if you have other code that also needs to // access NetworkID somehow, do it this way. config.Node.NetworkID = config.NetworkIDTestnet alice, err := account.FromHexString("deadbeef") if err != nil { fmt.Println("Could not create alice's Account:", err) } bobAddress := "ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v" // create a Context for the node you will use and address you're going to // sign the transaction with ctx, node := NewContextFromURL("http://localhost:3013", alice.Address, false) // create the SpendTransaction amount := big.NewInt(1e9) fee := big.NewInt(1e6) msg := "Reason For Payment" tx, err := ctx.SpendTx(alice.Address, bobAddress, amount, fee, []byte(msg)) if err != nil { fmt.Println("Could not create the SpendTx:", err) } // Optional: minimize the fee to save money! err = transactions.CalculateFee(tx) if err != nil { fmt.Println("Could not calculate the transaction fee", err) } _, _, _, _, _, err = SignBroadcastWaitTransaction(tx, alice, node, config.Node.NetworkID, 10) if err != nil { fmt.Println("SignBroadcastTransaction failed with:", err) } // check the recipient's balance time.Sleep(2 * time.Second) bobState, err := node.GetAccount(bobAddress) if err != nil { fmt.Println("Couldn't get Bob's account data:", err) } fmt.Println(bobState.Balance)
Output:
func NewContextFromNode ¶
NewContextFromNode is a convenience function that creates a Context and its TTL/Nonce closures from a Node instance
func NewContextFromURL ¶
NewContextFromURL is a convenience function that creates a Context and its TTL/Nonce closures from a URL
func (*Context) ContractCallTx ¶
func (c *Context) ContractCallTx(ContractID, CallData string, AbiVersion uint16, Amount, GasLimit, GasPrice, Fee *big.Int) (tx *transactions.ContractCallTx, err error)
ContractCallTx creates a contract call transaction,, filling in the account nonce and transaction TTL automatically.
func (*Context) ContractCreateTx ¶
func (c *Context) ContractCreateTx(Code string, CallData string, VMVersion, AbiVersion uint16, Deposit, Amount, GasLimit, Fee *big.Int) (tx *transactions.ContractCreateTx, err error)
ContractCreateTx creates a contract create transaction, filling in the account nonce and transaction TTL automatically.
func (*Context) NameClaimTx ¶
func (c *Context) NameClaimTx(name string, nameSalt, fee *big.Int) (tx *transactions.NameClaimTx, err error)
NameClaimTx creates a claim transaction, filling in the account nonce and transaction TTL automatically.
func (*Context) NamePreclaimTx ¶
func (c *Context) NamePreclaimTx(name string, fee *big.Int) (tx *transactions.NamePreclaimTx, nameSalt *big.Int, err error)
NamePreclaimTx creates a name preclaim transaction, filling in the account nonce and transaction TTL automatically. It also generates a commitment ID and salt, later used to claim the name.
func (*Context) NameRevokeTx ¶
func (c *Context) NameRevokeTx(name string) (tx *transactions.NameRevokeTx, err error)
NameRevokeTx creates a name revoke transaction, filling in the account nonce and transaction TTL automatically.
func (*Context) NameTransferTx ¶
func (c *Context) NameTransferTx(name string, recipientAddress string) (tx *transactions.NameTransferTx, err error)
NameTransferTx creates a name transfer transaction, filling in the account nonce and transaction TTL automatically.
func (*Context) NameUpdateTx ¶
func (c *Context) NameUpdateTx(name string, targetAddress string) (tx *transactions.NameUpdateTx, err error)
NameUpdateTx creates a name update transaction, filling in the account nonce and transaction TTL automatically.
func (*Context) OracleExtendTx ¶
func (c *Context) OracleExtendTx(oracleID string, ttlType, ttlValue uint64) (tx *transactions.OracleExtendTx, err error)
OracleExtendTx creates an oracle extend transaction, filling in the account nonce and transaction TTL automatically.
func (*Context) OracleQueryTx ¶
func (c *Context) OracleQueryTx(OracleID, Query string, QueryFee *big.Int, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue uint64) (tx *transactions.OracleQueryTx, err error)
OracleQueryTx creates an oracle query transaction, filling in the account nonce and transaction TTL automatically.
func (*Context) OracleRegisterTx ¶
func (c *Context) OracleRegisterTx(querySpec, responseSpec string, queryFee *big.Int, oracleTTLType, oracleTTLValue uint64, VMVersion uint16) (tx *transactions.OracleRegisterTx, err error)
OracleRegisterTx creates an oracle register transaction, filling in the account nonce and transaction TTL automatically.
func (*Context) OracleRespondTx ¶
func (c *Context) OracleRespondTx(OracleID string, QueryID string, Response string, TTLType uint64, TTLValue uint64) (tx *transactions.OracleRespondTx, err error)
OracleRespondTx creates an oracle response transaction, filling in the account nonce and transaction TTL automatically.
type GetAnythingByNameFunc ¶
GetAnythingByNameFunc describes a function that returns lookup results for a AENS name
func GenerateGetAnythingByName ¶
func GenerateGetAnythingByName(n naet.GetNameEntryByNamer) GetAnythingByNameFunc
GenerateGetAnythingByName is the underlying implementation of Get*ByName
type GetNextNonceFunc ¶
GetNextNonceFunc defines a function that will return an unused account nonce for making a transaction.
func GenerateGetNextNonce ¶
func GenerateGetNextNonce(n naet.GetAccounter) GetNextNonceFunc
GenerateGetNextNonce retrieves the current accountNonce and adds 1 to it for use in transaction building
type GetTTLFunc ¶
GetTTLFunc defines a function that will return an appropriate TTL for a transaction.
func GenerateGetTTL ¶
func GenerateGetTTL(n naet.GetHeighter) GetTTLFunc
GenerateGetTTL returns the chain height + offset
type GetTTLNonceFunc ¶
GetTTLNonceFunc describes a function that combines the roles of GetTTLFunc and GetNextNonceFunc
func GenerateGetTTLNonce ¶
func GenerateGetTTLNonce(ttlFunc GetTTLFunc, nonceFunc GetNextNonceFunc) GetTTLNonceFunc
GenerateGetTTLNonce combines the commonly used together functions of GetTTL and GetNextNonce