aeternity

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2019 License: ISC Imports: 26 Imported by: 8

Documentation

Index

Constants

View Source
const (
	Base58c = ObjectEncoding("b58c")
	Base64c = ObjectEncoding("b64c")
)

Encoding strategies

View Source
const (
	// Prefix separator
	PrefixSeparator = "_"

	// Base58 prefixes
	PrefixAccountPubkey         = HashPrefix("ak_")
	PrefixBlockProofOfFraudHash = HashPrefix("bf_")
	PrefixBlockStateHash        = HashPrefix("bs_")
	PrefixBlockTransactionHash  = HashPrefix("bx_")
	PrefixChannel               = HashPrefix("ch_")
	PrefixCommitment            = HashPrefix("cm_")
	PrefixContractPubkey        = HashPrefix("ct_")
	PrefixKeyBlockHash          = HashPrefix("kh_")
	PrefixMicroBlockHash        = HashPrefix("mh_")
	PrefixName                  = HashPrefix("nm_")
	PrefixOraclePubkey          = HashPrefix("ok_")
	PrefixOracleQueryID         = HashPrefix("oq_")
	PrefixPeerPubkey            = HashPrefix("pp_")
	PrefixSignature             = HashPrefix("sg_")
	PrefixTransactionHash       = HashPrefix("th_")

	// Base 64 encoded transactions
	PrefixContractByteArray = HashPrefix("cb_")
	PrefixOracleResponse    = HashPrefix("or_")
	PrefixOracleQuery       = HashPrefix("ov_")
	PrefixProofOfInclusion  = HashPrefix("pi_")
	PrefixStateTrees        = HashPrefix("ss_")
	PrefixState             = HashPrefix("st_")
	PrefixTransaction       = HashPrefix("tx_")
)

Prefixes

View Source
const (
	IDTagAccount    uint8 = 1
	IDTagName       uint8 = 2
	IDTagCommitment uint8 = 3
	IDTagOracle     uint8 = 4
	IDTagContract   uint8 = 5
	IDTagChannel    uint8 = 6
)

Tag constant for ids (type uint8) see https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type <<Tag:1/unsigned-integer-unit:8, Hash:32/binary-unit:8>>

View Source
const (
	ObjectTagAccount                             uint = 10
	ObjectTagSignedTransaction                   uint = 11
	ObjectTagSpendTransaction                    uint = 12
	ObjectTagOracle                              uint = 20
	ObjectTagOracleQuery                         uint = 21
	ObjectTagOracleRegisterTransaction           uint = 22
	ObjectTagOracleQueryTransaction              uint = 23
	ObjectTagOracleResponseTransaction           uint = 24
	ObjectTagOracleExtendTransaction             uint = 25
	ObjectTagNameServiceName                     uint = 30
	ObjectTagNameServiceCommitment               uint = 31
	ObjectTagNameServiceClaimTransaction         uint = 32
	ObjectTagNameServicePreclaimTransaction      uint = 33
	ObjectTagNameServiceUpdateTransaction        uint = 34
	ObjectTagNameServiceRevokeTransaction        uint = 35
	ObjectTagNameServiceTransferTransaction      uint = 36
	ObjectTagContract                            uint = 40
	ObjectTagContractCall                        uint = 41
	ObjectTagContractCreateTransaction           uint = 42
	ObjectTagContractCallTransaction             uint = 43
	ObjectTagChannelCreateTransaction            uint = 50
	ObjectTagChannelDepositTransaction           uint = 51
	ObjectTagChannelWithdrawTransaction          uint = 52
	ObjectTagChannelForceProgressTransaction     uint = 521
	ObjectTagChannelCloseMutualTransaction       uint = 53
	ObjectTagChannelCloseSoloTransaction         uint = 54
	ObjectTagChannelSlashTransaction             uint = 55
	ObjectTagChannelSettleTransaction            uint = 56
	ObjectTagChannelOffChainTransaction          uint = 57
	ObjectTagChannelOffChainUpdateTransfer       uint = 570
	ObjectTagChannelOffChainUpdateDeposit        uint = 571
	ObjectTagChannelOffChainUpdateWithdrawal     uint = 572
	ObjectTagChannelOffChainUpdateCreateContract uint = 573
	ObjectTagChannelOffChainUpdateCallContract   uint = 574
	ObjectTagChannel                             uint = 58
	ObjectTagChannelSnapshotTransaction          uint = 59
	ObjectTagPoi                                 uint = 60
	ObjectTagMicroBody                           uint = 101
	ObjectTagLightMicroBlock                     uint = 102
)

Object tags see https://github.com/aeternity/protocol/blob/master/serializations.md#binary-serialization

View Source
const (
	// ConfigFilename default configuration file name
	ConfigFilename = "config"
)

Variables

View Source
var Config = ProfileConfig{
	Name: "Default Config",
	Node: NodeConfig{
		URL:         "https://sdk-mainnet.aepps.com",
		URLInternal: "https://sdk-mainnet.aepps.com",
		URLChannels: "https://sdk-mainnet.aepps.com",
		NetworkID:   "ae_mainnet",
	},
	Client: ClientConfig{
		TTL: 500,
		Fee: *utils.RequireBigIntFromString("200000000000000"),
		Names: AensConfig{
			NameTTL:   500,
			ClientTTL: 500,
		},
		Contracts: ContractConfig{
			Gas:       1e9,
			GasPrice:  1,
			Deposit:   0,
			VMVersion: 0,
		},
		Oracles: OracleConfig{
			QueryFee:  *utils.NewBigIntFromUint64(0),
			VMVersion: 0,
		},
		StateChannels: StateChannelConfig{
			LockPeriod:     0,
			ChannelReserve: 0,
		},
		NativeTransactions: false,
		Offline:            false,
	},
	Tuning: TuningConfig{
		ChainPollInteval:  100,
		ChainTimeout:      5000,
		CryptoKdfMemlimit: 1024 * 32,
		CryptoKdfOpslimit: 3,
		CryptoKdfThreads:  1,
		OutputFormatJSON:  false,
	},
}

Config sytem configuration

Functions

func Decode

func Decode(in string) (out []byte, err error)

Decode a string encoded with base58/base64 + checksum to a byte array

func Encode

func Encode(prefix HashPrefix, data []byte) string

Encode a byte array into base58/base64 with chacksum and a prefix

func GetWalletPath

func GetWalletPath(path string) (walletPath string, err error)

GetWalletPath try to locate a wallet

func KeystoreSeal

func KeystoreSeal(account *Account, password string) (j []byte, e error)

KeystoreSeal create an encrypted json keystore with the private key of the account

func NameClaimTx

func NameClaimTx(accountID, name string, nameSalt, fee uint64, ttl, nonce uint64) (rlpRawMsg []byte, err error)

NameClaimTx build a preclaim transaction

func NamePreclaimTx

func NamePreclaimTx(accountID, commitmentID string, fee uint64, ttl, nonce uint64) (rlpRawMsg []byte, err error)

NamePreclaimTx build a preclaim transaction

func NameUpdateTx

func NameUpdateTx(accountID, nameID string, pointers []string, nameTTL, clientTTL uint64, fee uint64, ttl, nonce uint64) (rlpRawMsg []byte, err error)

NameUpdateTx build an update name transaction

func OracleExtendTx

func OracleExtendTx(oracleID string, accountNonce, ttlType, ttlValue uint64, fee utils.BigInt, ttl uint64) (rlpRawMsg []byte, err error)

OracleExtendTx extend an oracle's lifetime

func OracleRegisterTx

func OracleRegisterTx(accountID string, accountNonce uint64, querySpec, responseSpec string, queryFee utils.BigInt, oracleTTLType, oracleTTLValue, abiVersion uint64, txFee utils.BigInt, txTTL uint64) (rlpRawMsg []byte, err error)

OracleRegisterTx register an oracle

func Pp

func Pp(data ...interface{})

Pp pretty print

func PpI

func PpI(indentSize int, data ...interface{})

PpI pretty print indent

func PpT

func PpT(indentSize int, title string)

PpT pretty print indent Title

func PrintError

func PrintError(code string, e *models.Error)

PrintError print error

func PrintObject

func PrintObject(title string, i interface{})

PrintObject pretty print an object obtained from the api with a title

func SignEncodeTx

func SignEncodeTx(kp *Account, txRaw []byte, networkID string) (signedEncodedTx, signedEncodedTxHash, signature string, err error)

SignEncodeTx sign and encode a transaction

func SignEncodeTxStr

func SignEncodeTxStr(kp *Account, tx string, networkID string) (signedEncodedTx, signedEncodedTxHash, signature string, err error)

SignEncodeTxStr sign and encode a transaction format as string (ex. tx_xyz)

func SpendTx

func SpendTx(senderID, recipientID string, amount, fee utils.BigInt, payload string, ttl, nonce uint64) (rlpRawMsg []byte, err error)

SpendTx create a spend transaction

func SpendTxStr

func SpendTxStr(sender, recipient string, amount, fee utils.BigInt, message string, txTTL, accountNonce uint64) (base64Tx string, err error)

SpendTxStr creates an unsigned SpendTx but returns the base64 representation instead of an RLP bytestring

func StoreAccountToKeyStoreFile

func StoreAccountToKeyStoreFile(account *Account, password, walletName string) (filePath string, err error)

StoreAccountToKeyStoreFile store an account to a json file

func Verify

func Verify(address string, message, signature []byte) (valid bool, err error)

Verify a message with a private key

func VerifySignedTx

func VerifySignedTx(accountID string, txSigned string, networkID string) (valid bool, err error)

VerifySignedTx verifies a tx_ with signature

Types

type Account

type Account struct {
	SigningKey ed25519.PrivateKey
	Address    string
}

Account holds the signing key and the aeternity account address

func AccountFromHexString

func AccountFromHexString(hexPrivateKey string) (account *Account, err error)

AccountFromHexString load an account from hex string

func KeystoreOpen

func KeystoreOpen(data []byte, password string) (account *Account, err error)

KeystoreOpen open and decrypt a keystore

func LoadAccountFromKeyStoreFile

func LoadAccountFromKeyStoreFile(keyFile, password string) (account *Account, err error)

LoadAccountFromKeyStoreFile load file from the keystore

func NewAccount

func NewAccount() (account *Account, err error)

NewAccount genereate a new keypair

func (*Account) Sign

func (account *Account) Sign(message []byte) (signature []byte)

Sign a message with a private key

func (*Account) SigningKeyToHexString

func (account *Account) SigningKeyToHexString() (signingKeyHex string)

SigningKeyToHexString return the SigningKey as an hex string

type Ae

type Ae struct {
	*apiclient.Node
	*Wallet
	*Aens
	*Contract
	*Oracle
}

Ae the aeternity client

func NewCli

func NewCli(nodeURL string, debug bool) *Ae

NewCli obtain a new nodeClient instance

func (*Ae) APIGetAccount

func (ae *Ae) APIGetAccount(accountID string) (account *models.Account, err error)

APIGetAccount return the account

func (*Ae) APIGetCurrentKeyBlock

func (ae *Ae) APIGetCurrentKeyBlock() (kb *models.KeyBlock, err error)

APIGetCurrentKeyBlock get current key block

func (*Ae) APIGetHeight

func (ae *Ae) APIGetHeight() (height uint64, err error)

APIGetHeight get the height of the chain

func (*Ae) APIGetKeyBlockByHash

func (ae *Ae) APIGetKeyBlockByHash(keyBlockID string) (txs *models.KeyBlock, err error)

APIGetKeyBlockByHash get a key block by its hash

func (*Ae) APIGetMicroBlockHeaderByHash

func (ae *Ae) APIGetMicroBlockHeaderByHash(microBlockID string) (txs *models.MicroBlockHeader, err error)

APIGetMicroBlockHeaderByHash get the header of a micro block

func (*Ae) APIGetMicroBlockTransactionsByHash

func (ae *Ae) APIGetMicroBlockTransactionsByHash(microBlockID string) (txs *models.GenericTxs, err error)

APIGetMicroBlockTransactionsByHash get the transactions of a microblock

func (*Ae) APIGetNameEntryByName

func (ae *Ae) APIGetNameEntryByName(name string) (nameEntry *models.NameEntry, err error)

APIGetNameEntryByName return the name entry

func (*Ae) APIGetOracleByPubkey

func (ae *Ae) APIGetOracleByPubkey(pubkey string) (oracle *models.RegisteredOracle, err error)

APIGetOracleByPubkey get an oracle by it's public key

func (*Ae) APIGetStatus

func (ae *Ae) APIGetStatus() (status *models.Status, err error)

APIGetStatus post transaction

func (*Ae) APIGetTopBlock

func (ae *Ae) APIGetTopBlock() (kb *models.KeyBlockOrMicroBlockHeader, err error)

APIGetTopBlock get the top block of the chain

func (*Ae) APIGetTransactionByHash

func (ae *Ae) APIGetTransactionByHash(txHash string) (tx *models.GenericSignedTx, err error)

APIGetTransactionByHash get a transaction by it's hash

func (*Ae) APIPostTransaction

func (ae *Ae) APIPostTransaction(signedEncodedTx, signedEncodedTxHash string) (err error)

APIPostTransaction post transaction

func (*Ae) BroadcastTransaction

func (ae *Ae) BroadcastTransaction(txSignedBase64 string) (err error)

BroadcastTransaction recalculates the transaction hash and sends the transaction to the node.

func (*Ae) GetNextNonce

func (ae *Ae) GetNextNonce(accountID string) (nextNonce uint64, err error)

GetNextNonce retrieves the current accountNonce for an account + 1

func (*Ae) GetTTL

func (ae *Ae) GetTTL(offset uint64) (height uint64, err error)

GetTTL returns the chain height + offset

func (*Ae) GetTTLNonce

func (ae *Ae) GetTTLNonce(accountID string, offset uint64) (txTTL, accountNonce uint64, err error)

GetTTLNonce is a convenience function that combines GetTTL() and GetNextNonce()

func (*Ae) PrintGenerationByHeight

func (ae *Ae) PrintGenerationByHeight(height uint64)

PrintGenerationByHeight utility function to print a generation by it's height

func (*Ae) WaitForTransactionUntilHeight

func (ae *Ae) WaitForTransactionUntilHeight(height uint64, txHash string) (blockHeight uint64, blockHash, microBlockHash string, tx *models.GenericSignedTx, err error)

WaitForTransactionUntilHeight waits for a transaction until heightLimit (inclusive) is reached

func (*Ae) WithAccount

func (ae *Ae) WithAccount(account *Account) *Ae

WithAccount associate a Account with the client

type Aens

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

Aens abstractions for aens operations

func (*Aens) NameClaimTxStr

func (n *Aens) NameClaimTxStr(name string, nameSalt, txTTL, accountNonce uint64) (tx string, err error)

NameClaimTxStr creates a claim transaction

func (*Aens) NamePreclaimTxStr

func (n *Aens) NamePreclaimTxStr(name string, txTTL, accountNonce uint64) (tx string, nameSalt uint64, err error)

NamePreclaimTxStr creates a name preclaim transaction and nameSalt (required for claiming)

func (*Aens) NameUpdateTxStr

func (n *Aens) NameUpdateTxStr(name string, targetAddress string, txTTL, accountNonce uint64) (tx string, err error)

NameUpdateTxStr perform a name update

type AensConfig

type AensConfig struct {
	NameTTL     uint64 `json:"name_ttl" yaml:"name_ttl" mapstructure:"name_ttl"`
	ClientTTL   uint64 `json:"client_ttl" yaml:"client_ttl" mapstructure:"client_ttl"`
	PreClaimFee uint64 `json:"preclaim_fee" yaml:"preclaim_fee" mapstructure:"preclaim_fee"`
	ClaimFee    uint64 `json:"claim_fee" yaml:"claim_fee" mapstructure:"claim_fee"`
	UpdateFee   uint64 `json:"update_fee" yaml:"update_fee" mapstructure:"update_fee"`
}

AensConfig configurations for Aens

type ClientConfig

type ClientConfig struct {
	TTL                uint64             `json:"ttl" yaml:"ttl" mapstructure:"ttl"`
	Fee                utils.BigInt       `json:"fee" yaml:"fee" mapstructure:"fee"`
	DefaultKey         string             `json:"default_key_name" yaml:"default_key_name" mapstructure:"default_key_name"`
	Names              AensConfig         `json:"names" yaml:"names" mapstructure:"names"`
	Contracts          ContractConfig     `json:"contracts" yaml:"contracts" mapstructure:"contracts"`
	Oracles            OracleConfig       `json:"oracles" yaml:"oracles" mapstructure:"oracles"`
	StateChannels      StateChannelConfig `json:"state_channels" yaml:"state_channels" mapstructure:"state_channels"`
	NativeTransactions bool               `yaml:"native_transactions" json:"native_transactions" mapstructure:"native_transactions"`
	Offline            bool               `yaml:"offline" json:"offline" mapstructure:"offline"`
}

ClientConfig client paramters configuration

type Contract

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

Contract abstractions for contracts

type ContractConfig

type ContractConfig struct {
	Gas       uint64 `json:"gas" yaml:"gas" mapstructure:"gas"`
	GasPrice  uint64 `json:"gas_price" yaml:"gas_price" mapstructure:"gas_price"`
	Deposit   uint64 `json:"deposit" yaml:"deposit" mapstructure:"deposit"`
	VMVersion uint64 `json:"vm_version" yaml:"vm_version" mapstructure:"vm_version"`
}

ContractConfig configurations for contracts

type HashPrefix

type HashPrefix string

HashPrefix a prefix for an aeternity object hash

func GetHashPrefix

func GetHashPrefix(hash string) (p HashPrefix)

GetHashPrefix get the prefix of an hash, panics if the hash is too short

type NodeConfig

type NodeConfig struct {
	URL         string `yaml:"url" json:"url" mapstructure:"url"`
	URLInternal string `yaml:"url_internal" json:"url_internal" mapstructure:"url_internal"`
	URLChannels string `yaml:"url_channels" json:"url_channels" mapstructure:"url_channels"`
	NetworkID   string `yaml:"network_id" json:"network_id" mapstructure:"network_id"`
}

NodeConfig configuration for the node node

type ObjectEncoding

type ObjectEncoding string

ObjectEncoding the encoding of an object

type Oracle

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

Oracle abstractions for oracles

func (*Oracle) OracleRegisterTxStr

func (o *Oracle) OracleRegisterTxStr(querySpec, responseSpec string, queryFee utils.BigInt, txTTLType, txTTLValue, abiVersion uint64, txFee utils.BigInt, txTTL, accountNonce uint64) (tx string, err error)

OracleRegisterTxStr register an oracle

type OracleConfig

type OracleConfig struct {
	QueryFee  utils.BigInt `json:"query_fee" yaml:"query_fee" mapstructure:"query_fee"`
	VMVersion uint64       `json:"vm_version" yaml:"vm_version" mapstructure:"vm_version"`
}

OracleConfig configurations for contracts

type ProfileConfig

type ProfileConfig struct {
	Name   string       `json:"name" yaml:"name" mapstructure:"name"`
	Node   NodeConfig   `json:"node" yaml:"node" mapstructure:"node"`
	Client ClientConfig `json:"client" yaml:"client" mapstructure:"client"`
	Tuning TuningConfig `json:"tuning" yaml:"tuning" mapstructure:"tuning"`
}

ProfileConfig a configuration profile

type StateChannelConfig

type StateChannelConfig struct {
	LockPeriod     uint64 `json:"lock_period" yaml:"lock_period" mapstructure:"lock_period"`
	ChannelReserve uint64 `json:"channel_reserve" yaml:"channel_reserve" mapstructure:"channel_reserve"`
}

StateChannelConfig configurations for contracts TODO: not complete

type TuningConfig

type TuningConfig struct {
	ChainPollInteval  int64  `json:"chain_poll_interval" yaml:"chain_poll_interval" mapstructure:"chain_poll_interval"`
	ChainTimeout      int64  `json:"chain_timeout" yaml:"chain_timeout" mapstructure:"chain_timeout"`
	CryptoKdfMemlimit uint32 `json:"crypto_kdf_memlimit" yaml:"crypto_kdf_memlimit" mapstructure:"crypto_kdf_memlimit"`
	CryptoKdfOpslimit uint32 `json:"crypto_kdf_opslimit" yaml:"crypto_kdf_opslimit" mapstructure:"crypto_kdf_opslimit"`
	CryptoKdfThreads  uint8  `json:"crypto_kdf_threads" yaml:"crypto_kdf_threads" mapstructure:"crypto_kdf_threads"`
	OutputFormatJSON  bool   `json:"-" yaml:"-" mapstructure:"-"`
}

TuningConfig fine tuning of parameters of the client

type Wallet

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

Wallet high level abstraction for operation on a wallet

Jump to

Keyboard shortcuts

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