transactions

package
v6.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: ISC Imports: 10 Imported by: 0

Documentation

Overview

Package transactions contains Go-native Tx structs and related code around Transactions.

Index

Examples

Constants

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

Address-like bytearrays are converted in to an ID (uint8 bytearray) for RLP serialization. ID Tags differentiate between them. https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type

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
	ObjectTagGeneralizedAccountAttachTransaction uint = 80
	ObjectTagGeneralizedAccountMetaTransaction   uint = 81
	ObjectTagMicroBody                           uint = 101
	ObjectTagLightMicroBlock                     uint = 102
)

Object tags are used to differentiate between different types of bytearrays in RLP serialization. see https://github.com/aeternity/protocol/blob/master/serializations.md#binary-serialization

Variables

This section is empty.

Functions

func CalculateFee

func CalculateFee(tx TransactionFeeCalculable) (err error)

CalculateFee calculates the required transaction fee, and increases the fee further in case the newer fee ends up increasing the transaction size.

func Hash

func Hash(tx *SignedTx) (txhash string, err error)

Hash calculates the hash of a SignedTx. It is intended to be used after SignedTx.Signatures has been filled out.

func SerializeTx

func SerializeTx(tx rlp.Encoder) (string, error)

SerializeTx takes a Tx, runs its RLP() method, and base encodes the result.

Example
tx := &SpendTx{
	SenderID:    "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi",
	RecipientID: "ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v",
	Amount:      &big.Int{},
	Fee:         &big.Int{},
	Payload:     nil,
	TTL:         3627,
	Nonce:       3,
}
txStr, err := SerializeTx(tx)
if err != nil {
	return
}

fmt.Println(txStr)
Output:

tx_+E0MAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vOhAR8To7CL8AFABmKmi2nYdfeAPOxMCGR/btXYTHiXvVCjAACCDisDgLzTETQ=

func TransactionTypes

func TransactionTypes() map[uint]Transaction

TransactionTypes is a map between the ObjectTags defined above and the corresponding Tx struct. It is wrapped by a function to guarantee you cannot modify this map, because Golang does not have const maps.

func VerifySignedTx

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

VerifySignedTx verifies the signature of a signed transaction, in its RLP serialized, base64 encoded tx_ form.

The network ID is also used when calculating the signature, so the network ID that the transaction was intended for should be provided too.

Example
valid, err := VerifySignedTx("ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi", "tx_+JcLAfhCuEB42YQL7o806SO319qTPOiHRPKPPwJpcMbPry9PrAMLVmAZWdoEQNY1Ly5Bo5A2br1MaDrss6zkeR6sotxbf/kCuE/4TQwBoQHOp63kcMn5nZ1OQAiAqG8dSbtES2LxGp67ZLvP63P+86EBHxOjsIvwAUAGYqaLadh194A87EwIZH9u1dhMeJe9UKMAAIIOKwOA4+Wjcw==", "ae_testnet")
if err != nil {
	return
}
fmt.Println(valid)
Output:

true

Types

type ContractCallTx

type ContractCallTx struct {
	CallerID     string
	AccountNonce uint64
	ContractID   string
	Amount       *big.Int
	GasLimit     *big.Int
	GasPrice     *big.Int
	AbiVersion   uint16
	CallData     string
	Fee          *big.Int
	TTL          uint64
}

ContractCallTx represents calling an existing smart contract

func NewContractCallTx

func NewContractCallTx(CallerID string, AccountNonce uint64, ContractID string, Amount, GasLimit, GasPrice *big.Int, AbiVersion uint16, CallData string, Fee *big.Int, TTL uint64) *ContractCallTx

NewContractCallTx is a constructor for a ContractCallTx struct

func (*ContractCallTx) DecodeRLP

func (tx *ContractCallTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*ContractCallTx) EncodeRLP

func (tx *ContractCallTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*ContractCallTx) GetFee

func (tx *ContractCallTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*ContractCallTx) GetGasLimit

func (tx *ContractCallTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*ContractCallTx) JSON

func (tx *ContractCallTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoint

func (*ContractCallTx) SetFee

func (tx *ContractCallTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type ContractCreateTx

type ContractCreateTx struct {
	OwnerID      string
	AccountNonce uint64
	Code         string
	VMVersion    uint16
	AbiVersion   uint16
	Deposit      *big.Int
	Amount       *big.Int
	GasLimit     *big.Int
	GasPrice     *big.Int
	Fee          *big.Int
	TTL          uint64
	CallData     string
}

ContractCreateTx represents a transaction that creates a smart contract

func NewContractCreateTx

func NewContractCreateTx(OwnerID string, AccountNonce uint64, Code string, VMVersion, AbiVersion uint16, Deposit, Amount, GasLimit, GasPrice, Fee *big.Int, TTL uint64, CallData string) *ContractCreateTx

NewContractCreateTx is a constructor for a ContractCreateTx struct

func (*ContractCreateTx) ContractID

func (tx *ContractCreateTx) ContractID() (string, error)

ContractID returns the ct_ ID that this transaction would produce, which depends on the OwnerID and AccountNonce.

func (*ContractCreateTx) DecodeRLP

func (tx *ContractCreateTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*ContractCreateTx) EncodeRLP

func (tx *ContractCreateTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*ContractCreateTx) GetFee

func (tx *ContractCreateTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*ContractCreateTx) GetGasLimit

func (tx *ContractCreateTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*ContractCreateTx) JSON

func (tx *ContractCreateTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoint

func (*ContractCreateTx) SetFee

func (tx *ContractCreateTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type GAAttachTx

type GAAttachTx struct {
	OwnerID      string
	AccountNonce uint64
	Code         string
	AuthFunc     []byte
	VMVersion    uint16
	AbiVersion   uint16
	GasLimit     *big.Int
	GasPrice     *big.Int
	Fee          *big.Int
	TTL          uint64
	CallData     string
}

GAAttachTx is a transaction that converts a plain old account (POA) into a Generalized Account. The function in the contract that should be used for authenticating transactions from that account is denoted by the parameter AuthFunc.

func NewGAAttachTx

func NewGAAttachTx(OwnerID string, AccountNonce uint64, Code string, AuthFunc []byte, VMVersion uint16, AbiVersion uint16, GasLimit *big.Int, GasPrice *big.Int, Fee *big.Int, TTL uint64, CallData string) *GAAttachTx

NewGAAttachTx creates a GAAttachTx

func (*GAAttachTx) DecodeRLP

func (tx *GAAttachTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*GAAttachTx) EncodeRLP

func (tx *GAAttachTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*GAAttachTx) GetFee

func (tx *GAAttachTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*GAAttachTx) GetGasLimit

func (tx *GAAttachTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*GAAttachTx) SetFee

func (tx *GAAttachTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type GAMetaTx

type GAMetaTx struct {
	AccountID  string
	AuthData   string
	AbiVersion uint16
	GasLimit   *big.Int
	GasPrice   *big.Int
	Fee        *big.Int
	TTL        uint64
	Tx         *SignedTx
}

GAMetaTx wraps a normal Tx (that is not a GAAttachTx) that will only be executed if the contract located at GaID returns true

func NewGAMetaTx

func NewGAMetaTx(AccountID string, AuthData string, AbiVersion uint16, GasLimit *big.Int, GasPrice *big.Int, Fee *big.Int, TTL uint64, Tx rlp.Encoder) *GAMetaTx

NewGAMetaTx creates a GAMetaTx

func (*GAMetaTx) DecodeRLP

func (tx *GAMetaTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*GAMetaTx) EncodeRLP

func (tx *GAMetaTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*GAMetaTx) GetFee

func (tx *GAMetaTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*GAMetaTx) GetGasLimit

func (tx *GAMetaTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*GAMetaTx) SetFee

func (tx *GAMetaTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type NameClaimTx

type NameClaimTx struct {
	AccountID    string
	Name         string
	NameSalt     *big.Int
	Fee          *big.Int
	TTL          uint64
	AccountNonce uint64
}

NameClaimTx represents a transaction where one claims a previously reserved name on AENS The revealed name is simply sent in plaintext in RLP, while in JSON representation it is base58 encoded.

func NewNameClaimTx

func NewNameClaimTx(accountID, name string, nameSalt, fee *big.Int, ttl, accountNonce uint64) *NameClaimTx

NewNameClaimTx is a constructor for a NameClaimTx struct

func (*NameClaimTx) DecodeRLP

func (tx *NameClaimTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*NameClaimTx) EncodeRLP

func (tx *NameClaimTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*NameClaimTx) GetFee

func (tx *NameClaimTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*NameClaimTx) GetGasLimit

func (tx *NameClaimTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*NameClaimTx) JSON

func (tx *NameClaimTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoints

func (*NameClaimTx) SetFee

func (tx *NameClaimTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type NamePointer

type NamePointer struct {
	Key string
	ID  string
}

NamePointer is a go-native representation of swagger generated models.NamePointer.

func NewNamePointer

func NewNamePointer(key string, id string) *NamePointer

NewNamePointer is a constructor for NamePointer struct.

func (*NamePointer) DecodeRLP

func (np *NamePointer) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder interface.

func (*NamePointer) EncodeRLP

func (np *NamePointer) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder interface.

func (*NamePointer) Swagger

func (np *NamePointer) Swagger() *models.NamePointer

Swagger generates the go-swagger representation of this model

type NamePreclaimTx

type NamePreclaimTx struct {
	AccountID    string
	CommitmentID string
	Fee          *big.Int
	TTL          uint64
	AccountNonce uint64
}

NamePreclaimTx represents a transaction where one reserves a name on AENS without revealing it yet

func NewNamePreclaimTx

func NewNamePreclaimTx(accountID, commitmentID string, fee *big.Int, ttl, accountNonce uint64) *NamePreclaimTx

NewNamePreclaimTx is a constructor for a NamePreclaimTx struct

func (*NamePreclaimTx) DecodeRLP

func (tx *NamePreclaimTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*NamePreclaimTx) EncodeRLP

func (tx *NamePreclaimTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*NamePreclaimTx) GetFee

func (tx *NamePreclaimTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*NamePreclaimTx) GetGasLimit

func (tx *NamePreclaimTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*NamePreclaimTx) JSON

func (tx *NamePreclaimTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoint

func (*NamePreclaimTx) SetFee

func (tx *NamePreclaimTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type NameRevokeTx

type NameRevokeTx struct {
	AccountID    string
	NameID       string
	Fee          *big.Int
	TTL          uint64
	AccountNonce uint64
}

NameRevokeTx represents a transaction that revokes the name, i.e. has the same effect as waiting for the Name's TTL to expire.

func NewNameRevokeTx

func NewNameRevokeTx(accountID, name string, fee *big.Int, ttl, accountNonce uint64) *NameRevokeTx

NewNameRevokeTx is a constructor for a NameRevokeTx struct

func (*NameRevokeTx) DecodeRLP

func (tx *NameRevokeTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder interface.

func (*NameRevokeTx) EncodeRLP

func (tx *NameRevokeTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*NameRevokeTx) GetFee

func (tx *NameRevokeTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*NameRevokeTx) GetGasLimit

func (tx *NameRevokeTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*NameRevokeTx) JSON

func (tx *NameRevokeTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoint

func (*NameRevokeTx) SetFee

func (tx *NameRevokeTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type NameTransferTx

type NameTransferTx struct {
	AccountID    string
	NameID       string
	RecipientID  string
	Fee          *big.Int
	TTL          uint64
	AccountNonce uint64
}

NameTransferTx represents a transaction that transfers ownership of one name to another account.

func NewNameTransferTx

func NewNameTransferTx(AccountID, NameID, RecipientID string, Fee *big.Int, TTL, AccountNonce uint64) *NameTransferTx

NewNameTransferTx is a constructor for a NameTransferTx struct

func (*NameTransferTx) DecodeRLP

func (tx *NameTransferTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder interface.

func (*NameTransferTx) EncodeRLP

func (tx *NameTransferTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*NameTransferTx) GetFee

func (tx *NameTransferTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*NameTransferTx) GetGasLimit

func (tx *NameTransferTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*NameTransferTx) JSON

func (tx *NameTransferTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoint

func (*NameTransferTx) SetFee

func (tx *NameTransferTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type NameUpdateTx

type NameUpdateTx struct {
	AccountID    string
	NameID       string
	Pointers     []*NamePointer
	NameTTL      uint64
	ClientTTL    uint64
	Fee          *big.Int
	TTL          uint64
	AccountNonce uint64
}

NameUpdateTx represents a transaction where one extends the lifetime of a reserved name on AENS

func NewNameUpdateTx

func NewNameUpdateTx(accountID, nameID string, pointers []string, nameTTL, clientTTL uint64, fee *big.Int, ttl, accountNonce uint64) *NameUpdateTx

NewNameUpdateTx is a constructor for a NameUpdateTx struct

func (*NameUpdateTx) DecodeRLP

func (tx *NameUpdateTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*NameUpdateTx) EncodeRLP

func (tx *NameUpdateTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*NameUpdateTx) GetFee

func (tx *NameUpdateTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*NameUpdateTx) GetGasLimit

func (tx *NameUpdateTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*NameUpdateTx) JSON

func (tx *NameUpdateTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoint

func (*NameUpdateTx) SetFee

func (tx *NameUpdateTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type OracleExtendTx

type OracleExtendTx struct {
	OracleID       string
	AccountNonce   uint64
	OracleTTLType  uint64
	OracleTTLValue uint64
	Fee            *big.Int
	TTL            uint64
}

OracleExtendTx represents a transaction that extends the lifetime of an oracle

func NewOracleExtendTx

func NewOracleExtendTx(oracleID string, accountNonce, oracleTTLType, oracleTTLValue uint64, Fee *big.Int, TTL uint64) *OracleExtendTx

NewOracleExtendTx is a constructor for a OracleExtendTx struct

func (*OracleExtendTx) DecodeRLP

func (tx *OracleExtendTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*OracleExtendTx) EncodeRLP

func (tx *OracleExtendTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*OracleExtendTx) GetFee

func (tx *OracleExtendTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*OracleExtendTx) GetGasLimit

func (tx *OracleExtendTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*OracleExtendTx) JSON

func (tx *OracleExtendTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoint

func (*OracleExtendTx) SetFee

func (tx *OracleExtendTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type OracleQueryTx

type OracleQueryTx struct {
	SenderID         string
	AccountNonce     uint64
	OracleID         string
	Query            string
	QueryFee         *big.Int
	QueryTTLType     uint64
	QueryTTLValue    uint64
	ResponseTTLType  uint64
	ResponseTTLValue uint64
	Fee              *big.Int
	TTL              uint64
}

OracleQueryTx represents a transaction that a program sends to query an oracle

func NewOracleQueryTx

func NewOracleQueryTx(SenderID string, AccountNonce uint64, OracleID, Query string, QueryFee *big.Int, QueryTTLType, QueryTTLValue, ResponseTTLType, ResponseTTLValue uint64, Fee *big.Int, TTL uint64) *OracleQueryTx

NewOracleQueryTx is a constructor for a OracleQueryTx struct

func (*OracleQueryTx) DecodeRLP

func (tx *OracleQueryTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*OracleQueryTx) EncodeRLP

func (tx *OracleQueryTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*OracleQueryTx) GetFee

func (tx *OracleQueryTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*OracleQueryTx) GetGasLimit

func (tx *OracleQueryTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*OracleQueryTx) JSON

func (tx *OracleQueryTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoint

func (*OracleQueryTx) SetFee

func (tx *OracleQueryTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type OracleRegisterTx

type OracleRegisterTx struct {
	AccountID      string
	AccountNonce   uint64
	QuerySpec      string
	ResponseSpec   string
	QueryFee       *big.Int
	OracleTTLType  uint64
	OracleTTLValue uint64
	AbiVersion     uint16
	Fee            *big.Int
	TTL            uint64
}

OracleRegisterTx represents a transaction that registers an oracle on the blockchain's state

func NewOracleRegisterTx

func NewOracleRegisterTx(accountID string, accountNonce uint64, querySpec, responseSpec string, queryFee *big.Int, oracleTTLType, oracleTTLValue uint64, abiVersion uint16, txFee *big.Int, txTTL uint64) *OracleRegisterTx

NewOracleRegisterTx is a constructor for a OracleRegisterTx struct

func (*OracleRegisterTx) DecodeRLP

func (tx *OracleRegisterTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*OracleRegisterTx) EncodeRLP

func (tx *OracleRegisterTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*OracleRegisterTx) GetFee

func (tx *OracleRegisterTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*OracleRegisterTx) GetGasLimit

func (tx *OracleRegisterTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*OracleRegisterTx) JSON

func (tx *OracleRegisterTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoint BUG: Account Nonce won't be represented in JSON output if nonce is 0, thanks to swagger.json

func (*OracleRegisterTx) SetFee

func (tx *OracleRegisterTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type OracleRespondTx

type OracleRespondTx struct {
	OracleID         string
	AccountNonce     uint64
	QueryID          string
	Response         string
	ResponseTTLType  uint64
	ResponseTTLValue uint64
	Fee              *big.Int
	TTL              uint64
}

OracleRespondTx represents a transaction that an oracle sends to respond to an incoming query

func NewOracleRespondTx

func NewOracleRespondTx(OracleID string, AccountNonce uint64, QueryID string, Response string, TTLType uint64, TTLValue uint64, Fee *big.Int, TTL uint64) *OracleRespondTx

NewOracleRespondTx is a constructor for a OracleRespondTx struct

func (*OracleRespondTx) DecodeRLP

func (tx *OracleRespondTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*OracleRespondTx) EncodeRLP

func (tx *OracleRespondTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*OracleRespondTx) GetFee

func (tx *OracleRespondTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*OracleRespondTx) GetGasLimit

func (tx *OracleRespondTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*OracleRespondTx) JSON

func (tx *OracleRespondTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoint

func (*OracleRespondTx) SetFee

func (tx *OracleRespondTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type SignedTx

type SignedTx struct {
	Signatures [][]byte
	Tx         rlp.Encoder
}

SignedTx wraps around other Tx structs to hold the signature.

func NewSignedTx

func NewSignedTx(Signatures [][]byte, tx rlp.Encoder) (s *SignedTx)

NewSignedTx ensures that all fields of SignedTx are filled out.

func SignHashTx

func SignHashTx(kp *account.Account, tx Transaction, networkID string) (signedTx *SignedTx, txhash, signature string, err error)

SignHashTx wraps a *Tx struct in a SignedTx, then returns its signature and hash.

Example
acc, err := account.New()
if err != nil {
	return
}

tx := &SpendTx{
	SenderID:    acc.Address, // If the SenderID differs from the signing account, the transaction will not validate.
	RecipientID: "ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v",
	Amount:      &big.Int{},
	Fee:         &big.Int{},
	Payload:     nil,
	TTL:         3627,
	Nonce:       3,
}

stx, txhash, sig, err := SignHashTx(acc, tx, "ae_testnet")
if err != nil {
	return
}

fmt.Println(stx, txhash, sig, err)
Output:

func (*SignedTx) DecodeRLP

func (tx *SignedTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*SignedTx) EncodeRLP

func (tx *SignedTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

type SpendTx

type SpendTx struct {
	SenderID    string
	RecipientID string
	Amount      *big.Int
	Fee         *big.Int
	Payload     []byte
	TTL         uint64
	Nonce       uint64
}

SpendTx represents a simple transaction where one party sends another AE

func NewSpendTx

func NewSpendTx(senderID, recipientID string, amount, fee *big.Int, payload []byte, ttl, nonce uint64) *SpendTx

NewSpendTx is a constructor for a SpendTx struct

func (*SpendTx) DecodeRLP

func (tx *SpendTx) DecodeRLP(s *rlp.Stream) (err error)

DecodeRLP implements rlp.Decoder

func (*SpendTx) EncodeRLP

func (tx *SpendTx) EncodeRLP(w io.Writer) (err error)

EncodeRLP implements rlp.Encoder

func (*SpendTx) GetFee

func (tx *SpendTx) GetFee() *big.Int

GetFee implements TransactionFeeCalculable

func (*SpendTx) GetGasLimit

func (tx *SpendTx) GetGasLimit() *big.Int

GetGasLimit implements TransactionFeeCalculable

func (*SpendTx) JSON

func (tx *SpendTx) JSON() (string, error)

JSON representation of a Tx is useful for querying the node's debug endpoint

func (*SpendTx) SetFee

func (tx *SpendTx) SetFee(f *big.Int)

SetFee implements TransactionFeeCalculable

type Transaction

type Transaction interface {
	rlp.Encoder
}

Transaction is used to indicate a transaction of any type.

func DeserializeTx

func DeserializeTx(rawRLP []byte) (Transaction, error)

DeserializeTx takes a RLP serialized transaction as a bytearray and returns the corresponding Tx struct

Example
txRLP, err := binary.Decode("tx_+E0MAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vOhAR8To7CL8AFABmKmi2nYdfeAPOxMCGR/btXYTHiXvVCjAACCDisDgLzTETQ=")
if err != nil {
	return
}
tx, err := DeserializeTx(txRLP)
fmt.Printf("%T %+v", tx, tx)
Output:

*transactions.SpendTx &{SenderID:ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi RecipientID:ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v Amount:+0 Fee:+0 Payload:[] TTL:3627 Nonce:3}

func DeserializeTxStr

func DeserializeTxStr(txRLP string) (Transaction, error)

DeserializeTxStr takes a tx_ string and returns the corresponding Tx struct

Example
tx, err := DeserializeTxStr("tx_+E0MAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vOhAR8To7CL8AFABmKmi2nYdfeAPOxMCGR/btXYTHiXvVCjAACCDisDgLzTETQ=")
if err != nil {
	return
}
fmt.Printf("%T, %+v", tx, tx)
Output:

*transactions.SpendTx, &{SenderID:ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi RecipientID:ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v Amount:+0 Fee:+0 Payload:[] TTL:3627 Nonce:3}

func GetTransactionType

func GetTransactionType(rawRLP []byte) (tx Transaction, err error)

GetTransactionType reads the RLP input and returns a blank Tx struct of the correct type

Example
txRLP, err := binary.Decode("tx_+E0MAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vOhAR8To7CL8AFABmKmi2nYdfeAPOxMCGR/btXYTHiXvVCjAACCDisDgLzTETQ=")
if err != nil {
	return
}
tx, err := GetTransactionType(txRLP)
fmt.Printf("%T, %+v", tx, tx)
Output:

*transactions.SpendTx, &{SenderID: RecipientID: Amount:<nil> Fee:<nil> Payload:[] TTL:0 Nonce:0}

type TransactionFeeCalculable

type TransactionFeeCalculable interface {
	Transaction
	SetFee(*big.Int)
	GetFee() *big.Int
	GetGasLimit() *big.Int
}

TransactionFeeCalculable is a set of methods that simplify calculating the tx fee. In particular, SetFee and GetFee let the code increase the fee further in case the newer, calculated fee ends up increasing the size of the transaction (and thus necessitates an even larger fee)

Jump to

Keyboard shortcuts

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