aeternity

package
v9.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2021 License: ISC Imports: 11 Imported by: 0

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.

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_wJ3iKZcqvgdnQ6YVz8pY2xPjtVTNNEL61qF4AYQdksZfXZLks"

// create a connection to a node, represented by *Node
node := naet.NewNode("http://localhost:3013", false)

// create the closures that autofill the correct account nonce and transaction TTL
ttlnoncer := transactions.NewTTLNoncer(node)

// create the SpendTransaction
msg := "Reason For Payment"
tx, err := transactions.NewSpendTx(alice.Address, bobAddress, big.NewInt(1e9), []byte(msg), ttlnoncer)
if err != nil {
	fmt.Println("Could not create the SpendTx:", err)
}

spendTxReceipt, err := SignBroadcast(tx, alice, node, config.Node.NetworkID)
if err != nil {
	fmt.Println("could not send transaction:", err)
}
err = WaitSynchronous(spendTxReceipt, 10, node)
if err != nil {
	fmt.Println("transaction was not accepted by the blockchain:", err)
}
fmt.Printf("%#v\n", spendTxReceipt)

// 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:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultCallResultListener

func DefaultCallResultListener(node callResultListener, txHash string, callResultChan chan *models.ContractCallObject, errChan chan error, listenInterval time.Duration)

DefaultCallResultListener polls the node for the result of a particular transaction until /transaction/txhash/info is filled out with the pertinent data (only for ContractCallTxs). Then it will push the CallInfo to a channel. This function is intended to be run as a goroutine.

func DefaultOracleListener

func DefaultOracleListener(node oracleInfoer, oracleID string, queryChan chan *models.OracleQuery, errChan chan error, listenInterval time.Duration)

DefaultOracleListener uses a oracleInfoer to get all OracleQueries for a given oracleID, but keeps track of how many it read last time to that it only pushes new OracleQueries into the queryChan channel.

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 WaitSynchronous

func WaitSynchronous(txReceipt *TxReceipt, waitBlocks uint64, n transactionWaiter) (err error)

WaitSynchronous blocks until TxReceipt.Watch() reports that a transaction was mined/not mined. It is intended as a convenience function since it makes an asynchronous operation synchronous.

Types

type AENS

type AENS struct {
	// contains filtered or unexported fields
}

AENS is a higher level interface to AENS functionalities.

func NewAENS

func NewAENS(ctx ContextInterface) *AENS

NewAENS creates a new AENS higher level interface object

func (*AENS) RegisterName

func (aens *AENS) RegisterName(name string, nameFee *big.Int) (txReceipt *TxReceipt, err error)

RegisterName allows one to easily register a name on AENS. It does the preclaim, transaction sending, confirmation and claim for you.

type CompileEncoder

type CompileEncoder interface {
	naet.CompileContracter
	naet.EncodeCalldataer
}

CompileEncoder represents the basic capabilities required of a Compiler to be used by ContextInterface. Basically, a Compiler should be able to Compile and Encode Calldata.

type Context

type Context struct {
	SigningAccount *account.Account
	// contains filtered or unexported fields
}

Context holds information and node capabilities needed to create, sign and send transactions to a node. The node connection in Context does not need to be capable of other feature specific Swagger API endpoints.

func NewContext

func NewContext(signingAccount *account.Account, node transactionSender) (b *Context)

NewContext creates a new Context, but does not force one to provide a compiler (which can be set via SetCompiler)

func (*Context) Compiler

func (c *Context) Compiler() CompileEncoder

Compiler returns the compiler interface

func (*Context) NodeInfo

func (c *Context) NodeInfo() (networkID string, version string, err error)

NodeInfo returns the networkID and version of the currently connected node, needed for contract Tx creation

func (*Context) SenderAccount

func (c *Context) SenderAccount() string

SenderAccount returns the address of the signing account, which should also be the sender address (for many transaction types)

func (*Context) SetCompiler

func (c *Context) SetCompiler(compiler CompileEncoder)

SetCompiler changes the Context's compiler instance.

func (*Context) SignBroadcast

func (c *Context) SignBroadcast(tx transactions.Transaction, blocks uint64) (txReceipt *TxReceipt, err error)

SignBroadcast signs, sends and returns immediately, just like aeternity.SignBroadcast. The difference is that the account used to sign the transaction and broadcasting node and network ID don't have to be provided every time.

func (*Context) SignBroadcastWait

func (c *Context) SignBroadcastWait(tx transactions.Transaction, blocks uint64) (txReceipt *TxReceipt, err error)

SignBroadcastWait is just like SignBroadcast but integrates aeternity.WaitSynchronous afterwards, to block until the transaction is mined.

func (*Context) TTLNoncer

func (c *Context) TTLNoncer() transactions.TTLNoncer

TTLNoncer returns the TTLNoncer of Context.SigningAccount

type ContextInterface

type ContextInterface interface {
	SenderAccount() string
	TTLNoncer() transactions.TTLNoncer
	Compiler() CompileEncoder
	NodeInfo() (networkID string, version string, err error)
	SignBroadcastWait(tx transactions.Transaction, blocks uint64) (r *TxReceipt, err error)
	SetCompiler(c CompileEncoder)
}

ContextInterface describes the capabilities of Context, which provide information solely related to transaction creation/broadcasting. It allows for Context to be mocked out.

type Contract

type Contract struct {
	// contains filtered or unexported fields
}

Contract is a higher level interface to smart contract functionalities.

func NewContract

func NewContract(ctx ContextInterface) *Contract

NewContract creates a new Contract higher level interface object

func (*Contract) Call

func (c *Contract) Call(ctID, source, function string, args []string) (txReceipt *TxReceipt, err error)

Call calls a smart contract's function, automatically calling the compiler to transform the arguments into bytecode.

func (*Contract) Deploy

func (c *Contract) Deploy(source, function string, args []string) (ctID string, createTxReceipt *TxReceipt, err error)

Deploy lets one deploy a contract with minimum fuss.

type GetAnythingByNameFunc

type GetAnythingByNameFunc func(name, key string) (results []string, err error)

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 Oracle

type Oracle struct {
	ID                 string
	QuerySpec          string
	ResponseSpec       string
	Handler            oracleHandler
	Listener           oracleListener
	ListenPollInterval time.Duration
	// contains filtered or unexported fields
}

Oracle is a higher level interface to oracle functionalities.

func NewOracle

func NewOracle(h oracleHandler, node oracleInfoer, ctx ContextInterface, QuerySpec, ResponseSpec string, pollInterval time.Duration) *Oracle

NewOracle creates a new Oracle higher level interface object

func (*Oracle) Listen

func (o *Oracle) Listen() error

Listen starts polling for OracleQueries in a goroutine, passes new queries to Handler, and sends out a OracleResponseTx that contains Handler's return value.

func (*Oracle) RegisterIfNotExists

func (o *Oracle) RegisterIfNotExists() error

RegisterIfNotExists checks if an oracle is already registered, using Context.SenderAccount() to figure out the oracleID. If not, it sends a OracleRegisterTx with default TTL values from config.

type TxReceipt

type TxReceipt struct {
	Tx          transactions.Transaction
	SignedTx    string
	Hash        string
	Signature   string
	BlockHeight uint64
	BlockHash   string
	Mined       bool
	Error       error
}

TxReceipt represents the status of a sent transaction

func NewTxReceipt

func NewTxReceipt(tx transactions.Transaction, signedTx, hash, signature string) (txReceipt *TxReceipt)

NewTxReceipt ensures that the essential fields of a TxReceipt are filled upon creation

func SignBroadcast

func SignBroadcast(tx transactions.Transaction, signingAccount *account.Account, n naet.PostTransactioner, networkID string) (txReceipt *TxReceipt, err error)

SignBroadcast signs a transaction and broadcasts it to a node.

func (*TxReceipt) String

func (t *TxReceipt) String() string

func (*TxReceipt) Watch

func (t *TxReceipt) Watch(mined chan bool, waitBlocks uint64, node transactionWaiter)

Watch polls until a transaction has been mined or X blocks have gone by, after which it errors out via TxReceiptWatchResult. The node polling interval can be configured with config.Tuning.ChainPollInterval, which accepts a time.Duration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL