txnbuild

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2025 License: MIT, Apache-2.0 Imports: 17 Imported by: 0

README

txnbuild

txnbuild is a Stellar SDK, implemented in Go. It provides a reference implementation of the complete set of operations that compose transactions for the Stellar distributed ledger.

This project is maintained by the Stellar Development Foundation.

    import (
        "log"
        
        "github.com/stellar/go/clients/horizonclient"
        "github.com/stellar/go/keypair"
        "github.com/stellar/go/network"
        "github.com/stellar/go/txnbuild"
    )
    
    // Make a keypair for a known account from a secret seed
    kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
    
    // Get the current state of the account from the network
    client := horizonclient.DefaultTestNetClient
    ar := horizonclient.AccountRequest{AccountID: kp.Address()}
    sourceAccount, err := client.AccountDetail(ar)
    if err != nil {
        log.Fatalln(err)
    }
    
    // Build an operation to create and fund a new account
    op := txnbuild.CreateAccount{
        Destination: "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z",
        Amount:      "10",
    }
    
    // Construct the transaction that holds the operations to execute on the network
    tx, err := txnbuild.NewTransaction(
        txnbuild.TransactionParams{
            SourceAccount:        &sourceAccount,
            IncrementSequenceNum: true,
            Operations:           []txnbuild.Operation{&op},
            BaseFee:              txnbuild.MinBaseFee,
            Timebounds:           txnbuild.NewTimeout(300),
        },
    )
    if err != nil {
        log.Fatalln(err)
    }
    
    // Sign the transaction
    tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
    if err != nil {
        log.Fatalln(err)
    }
    
    // Get the base 64 encoded transaction envelope
    txe, err := tx.Base64()
    if err != nil {
        log.Fatalln(err)
    }
    
    // Send the transaction to the network
    resp, err := client.SubmitTransactionXDR(txe)
    if err != nil {
        log.Fatalln(err)
    }

Getting Started

This library is aimed at developers building Go applications on top of the Stellar network. Transactions constructed by this library may be submitted to any Horizon instance for processing onto the ledger, using any Stellar SDK client. The recommended client for Go programmers is horizonclient. Together, these two libraries provide a complete Stellar SDK.

An easy-to-follow demonstration that exercises this SDK on the TestNet with actual accounts is also included! See the Demo section below.

Prerequisites
  • Go (this repository is officially supported on the last two releases of Go)
  • Modules to manage dependencies
Installing
  • go get github.com/stellar/go/txnbuild

Running the tests

Run the unit tests from the package directory: go test

Demo

To see the SDK in action, build and run the demo:

  • Enter the demo directory: cd $GOPATH/src/github.com/stellar/go/txnbuild/cmd/demo
  • Build the demo: go build
  • Run the demo: ./demo init

Contributing

Please read Code of Conduct to understand this project's communication rules.

To submit improvements and fixes to this library, please see CONTRIBUTING.

License

This project is licensed under the Apache License - see the LICENSE file for details.

Documentation

Overview

Package txnbuild implements transactions and operations on the Stellar network. This library provides an interface to the Stellar transaction model. It supports the building of Go applications on top of the Stellar network (https://www.stellar.org/). Transactions constructed by this library may be submitted to any Horizon instance for processing onto the ledger, using any Stellar SDK client. The recommended client for Go programmers is horizonclient (https://github.com/stellar/go/tree/master/clients/horizonclient). Together, these two libraries provide a complete Stellar SDK. For more information and further examples, see https://github.com/stellar/go/blob/master/docs/reference/readme.md

Index

Constants

View Source
const MemoTextMaxLength = 28

MemoTextMaxLength is the maximum number of bytes allowed for a text memo.

View Source
const MinBaseFee = 100

MinBaseFee is the minimum transaction fee for the Stellar network of 100 stroops (0.00001 XLM).

View Source
const TimeoutInfinite = int64(0)

TimeoutInfinite allows an indefinite upper bound to be set for Transaction.MaxTime. This is usually not what you want.

Variables

View Source
var MaxTrustlineLimit = amount.StringFromInt64(math.MaxInt64)

MaxTrustlineLimit represents the maximum value that can be set as a trustline limit.

Functions

func SetOpSourceAccount

func SetOpSourceAccount(op *xdr.Operation, sourceAccount string)

SetOpSourceAccount sets the source account ID on an Operation, allowing M-strkeys (as defined in SEP23).

Types

type Account

type Account interface {
	GetAccountID() string
	IncrementSequenceNumber() (int64, error)
	GetSequenceNumber() (int64, error)
}

Account represents the aspects of a Stellar account necessary to construct transactions. See https://developers.stellar.org/docs/glossary/accounts/

type AccountMerge

type AccountMerge struct {
	Destination   string
	SourceAccount string
}

AccountMerge represents the Stellar merge account operation. See https://developers.stellar.org/docs/start/list-of-operations/

func (*AccountMerge) BuildXDR

func (am *AccountMerge) BuildXDR() (xdr.Operation, error)

BuildXDR for AccountMerge returns a fully configured XDR Operation.

func (*AccountMerge) FromXDR

func (am *AccountMerge) FromXDR(xdrOp xdr.Operation) error

FromXDR for AccountMerge initialises the txnbuild struct from the corresponding xdr Operation.

func (*AccountMerge) GetSourceAccount

func (am *AccountMerge) GetSourceAccount() string

GetSourceAccount returns the source account of the operation, or the empty string if not set.

func (*AccountMerge) Validate

func (am *AccountMerge) Validate() error

Validate for AccountMerge validates the required struct fields. It returns an error if any of the fields are invalid. Otherwise, it returns nil.

type AllowTrust deprecated

type AllowTrust struct {
	Trustor                        string
	Type                           Asset
	Authorize                      bool
	AuthorizeToMaintainLiabilities bool
	ClawbackEnabled                bool
	SourceAccount                  string
}

Deprecated: use SetTrustLineFlags instead. AllowTrust represents the Stellar allow trust operation. See https://developers.stellar.org/docs/start/list-of-operations/

func (*AllowTrust) BuildXDR

func (at *AllowTrust) BuildXDR() (xdr.Operation, error)

BuildXDR for AllowTrust returns a fully configured XDR Operation.

func (*AllowTrust) FromXDR

func (at *AllowTrust) FromXDR(xdrOp xdr.Operation) error

FromXDR for AllowTrust initialises the txnbuild struct from the corresponding xdr Operation.

func (*AllowTrust) GetSourceAccount

func (at *AllowTrust) GetSourceAccount() string

GetSourceAccount returns the source account of the operation, or the empty string if not set.

func (*AllowTrust) Validate

func (at *AllowTrust) Validate() error

Validate for AllowTrust validates the required struct fields. It returns an error if any of the fields are invalid. Otherwise, it returns nil.

type Asset

type Asset interface {
	BasicAsset
	LessThan(other Asset) bool
	ToXDR() (xdr.Asset, error)
}

Asset represents a Stellar asset.

func MustAssetFromXDR

func MustAssetFromXDR(xAsset xdr.Asset) Asset

MustAssetFromXDR constructs an Asset from its xdr representation. If the given asset xdr is invalid, MustAssetFromXDR will panic.

func ParseAssetString

func ParseAssetString(canonical string) (Asset, error)

ParseAssetString parses an asset string in canonical form (SEP-11) into an Asset structure. https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md#asset

type AssetAmount

type AssetAmount struct {
	Asset  Asset
	Amount string
}

AssetAmount is a "tuple", pairing an asset with an amount. Used for LiquidityPoolDeposit and LiquidityPoolWithdraw operations.

type AssetType

type AssetType xdr.AssetType

AssetType represents the type of a Stellar asset.

AssetTypeNative, AssetTypeCreditAlphanum4, AssetTypeCreditAlphanum12 enumerate the different types of asset on the Stellar network.

type Assets

type Assets []Asset

Assets represents a list of Stellar assets. Importantly, it is sortable.

func (Assets) Len

func (s Assets) Len() int

func (Assets) Less

func (s Assets) Less(i, j int) bool

func (Assets) Swap

func (s Assets) Swap(i, j int)

type BasicAsset

type BasicAsset interface {
	GetType() (AssetType, error)
	IsNative() bool
	GetCode() string
	GetIssuer() string

	// Conversions to the 3 asset types
	ToAsset() (Asset, error)
	MustToAsset() Asset

	ToChangeTrustAsset() (ChangeTrustAsset, error)
	MustToChangeTrustAsset() ChangeTrustAsset

	ToTrustLineAsset() (TrustLineAsset, error)
	MustToTrustLineAsset() TrustLineAsset
}

Breaks out some stuff common to all assets

type BumpSequence

type BumpSequence struct {
	BumpTo        int64
	SourceAccount string
}

BumpSequence represents the Stellar bump sequence operation. See https://developers.stellar.org/docs/start/list-of-operations/

func (*BumpSequence) GetSourceAccount

func (bs *BumpSequence) GetSourceAccount() string

GetSourceAccount returns the source account of the operation, or the empty string if not set.

func (*BumpSequence) Validate

func (bs *BumpSequence) Validate() error

Validate for BumpSequence validates the required struct fields. It returns an error if any of the fields are invalid. Otherwise, it returns nil.

type ChangeTrust

type ChangeTrust struct {
	Line          ChangeTrustAsset
	Limit         string
	SourceAccount string
}

ChangeTrust represents the Stellar change trust operation. See https://developers.stellar.org/docs/start/list-of-operations/ If Limit is omitted, it defaults to txnbuild.MaxTrustlineLimit.

func RemoveTrustlineOp

func RemoveTrustlineOp(issuedAsset ChangeTrustAsset) ChangeTrust

RemoveTrustlineOp returns a ChangeTrust operation to remove the trustline of the described asset, by setting the limit to "0".

func (*ChangeTrust) BuildXDR

func (ct *ChangeTrust) BuildXDR() (xdr.Operation, error)

BuildXDR for ChangeTrust returns a fully configured XDR Operation.

func (*ChangeTrust) FromXDR

func (ct *ChangeTrust) FromXDR(xdrOp xdr.Operation) error

FromXDR for ChangeTrust initialises the txnbuild struct from the corresponding xdr Operation.

func (*ChangeTrust) GetSourceAccount

func (ct *ChangeTrust) GetSourceAccount() string

GetSourceAccount returns the source account of the operation, or the empty string if not set.

func (*ChangeTrust) Validate

func (ct *ChangeTrust) Validate() error

Validate for ChangeTrust validates the required struct fields. It returns an error if any of the fields are invalid. Otherwise, it returns nil.

type ChangeTrustAsset

type ChangeTrustAsset interface {
	BasicAsset
	ToXDR() (xdr.ChangeTrustAsset, error)
	ToChangeTrustAsset() (ChangeTrustAsset, error)
	ToTrustLineAsset() (TrustLineAsset, error)
}

ChangeTrustAsset represents a Stellar change trust asset.

type ChangeTrustAssetWrapper

type ChangeTrustAssetWrapper struct {
	Asset
}

ChangeTrustAssetWrapper wraps a native/credit Asset so it generates xdr to be used in a change trust operation.

func (ChangeTrustAssetWrapper) ToXDR

ToXDR for ChangeTrustAssetWrapper generates the xdr.TrustLineAsset.

type CreditAsset

type CreditAsset struct {
	Code   string
	Issuer string
}

CreditAsset represents non-XLM assets on the Stellar network.

func (CreditAsset) GetCode

func (ca CreditAsset) GetCode() string

GetCode for CreditAsset returns the asset code.

func (CreditAsset) GetIssuer

func (ca CreditAsset) GetIssuer() string

GetIssuer for CreditAsset returns the address of the issuing account.

func (CreditAsset) GetType

func (ca CreditAsset) GetType() (AssetType, error)

GetType for CreditAsset returns the enum type of the asset, based on its code length.

func (CreditAsset) IsNative

func (ca CreditAsset) IsNative() bool

IsNative for CreditAsset returns false (this is not an XLM asset).

func (CreditAsset) LessThan

func (ca CreditAsset) LessThan(other Asset) bool

LessThan returns true if this asset sorts before some other asset.

func (CreditAsset) MustToAsset

func (ca CreditAsset) MustToAsset() Asset

MustToAsset for CreditAsset returns itself unchanged.

func (CreditAsset) MustToChangeTrustAsset

func (ca CreditAsset) MustToChangeTrustAsset() ChangeTrustAsset

MustToChangeTrustAsset for CreditAsset produces a corresponding XDR asset.

func (CreditAsset) MustToTrustLineAsset

func (ca CreditAsset) MustToTrustLineAsset() TrustLineAsset

MustToTrustLineAsset for CreditAsset produces a corresponding XDR asset.

func (CreditAsset) ToAsset

func (ca CreditAsset) ToAsset() (Asset, error)

ToAsset for CreditAsset returns itself unchanged.

func (CreditAsset) ToChangeTrustAsset

func (ca CreditAsset) ToChangeTrustAsset() (ChangeTrustAsset, error)

ToChangeTrustAsset for CreditAsset produces a corresponding XDR asset.

func (CreditAsset) ToTrustLineAsset

func (ca CreditAsset) ToTrustLineAsset() (TrustLineAsset, error)

ToTrustLineAsset for CreditAsset produces a corresponding XDR asset.

func (CreditAsset) ToXDR

func (ca CreditAsset) ToXDR() (xdr.Asset, error)

ToXDR for CreditAsset produces a corresponding XDR asset.

type FeeBumpTransaction

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

FeeBumpTransaction represents a CAP 15 fee bump transaction. Fee bump transactions allow an arbitrary account to pay the fee for a transaction.

func NewFeeBumpTransaction

func NewFeeBumpTransaction(params FeeBumpTransactionParams) (*FeeBumpTransaction, error)

NewFeeBumpTransaction returns a new FeeBumpTransaction instance

func (*FeeBumpTransaction) AddSignatureBase64

func (t *FeeBumpTransaction) AddSignatureBase64(network, publicKey, signature string) (*FeeBumpTransaction, error)

AddSignatureBase64 returns a new FeeBumpTransaction instance which extends the current instance with an additional signature derived from the given base64-encoded signature.

func (*FeeBumpTransaction) AddSignatureDecorated

func (t *FeeBumpTransaction) AddSignatureDecorated(signature ...xdr.DecoratedSignature) (*FeeBumpTransaction, error)

AddSignatureDecorated returns a new FeeBumpTransaction instance which extends the current instance with an additional decorated signature(s).

func (*FeeBumpTransaction) Base64

func (t *FeeBumpTransaction) Base64() (string, error)

Base64 returns the base 64 XDR representation of the transaction envelope.

func (*FeeBumpTransaction) BaseFee

func (t *FeeBumpTransaction) BaseFee() int64

BaseFee returns the per operation fee for this transaction.

func (*FeeBumpTransaction) ClearSignatures

func (t *FeeBumpTransaction) ClearSignatures() (*FeeBumpTransaction, error)

ClearSignatures returns a new Transaction instance which extends the current instance with signatures removed.

func (*FeeBumpTransaction) FeeAccount

func (t *FeeBumpTransaction) FeeAccount() string

FeeAccount returns the address of the account which will be paying for the inner transaction.

func (*FeeBumpTransaction) Hash

func (t *FeeBumpTransaction) Hash(networkStr string) ([32]byte, error)

Hash returns the network specific hash of this transaction encoded as a byte array.

func (*FeeBumpTransaction) HashHex

func (t *FeeBumpTransaction) HashHex(network string) (string, error)

HashHex returns the network specific hash of this transaction encoded as a hexadecimal string.

func (*FeeBumpTransaction) InnerTransaction

func (t *FeeBumpTransaction) InnerTransaction() *Transaction

InnerTransaction returns the Transaction which is wrapped by this FeeBumpTransaction instance.

func (*FeeBumpTransaction) MarshalBinary

func (t *FeeBumpTransaction) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary XDR representation of the transaction envelope.

func (*FeeBumpTransaction) MarshalText

func (t *FeeBumpTransaction) MarshalText() ([]byte, error)

MarshalText returns the base64 XDR representation of the transaction envelope.

func (*FeeBumpTransaction) MaxFee

func (t *FeeBumpTransaction) MaxFee() int64

MaxFee returns the total fees which can be spent to submit this transaction.

func (*FeeBumpTransaction) Sign

func (t *FeeBumpTransaction) Sign(network string, kps ...*keypair.Full) (*FeeBumpTransaction, error)

Sign returns a new FeeBumpTransaction instance which extends the current instance with additional signatures derived from the given list of keypair instances.

func (*FeeBumpTransaction) SignHashX

func (t *FeeBumpTransaction) SignHashX(preimage []byte) (*FeeBumpTransaction, error)

SignHashX returns a new FeeBumpTransaction instance which extends the current instance with HashX signature type. See description here: https://developers.stellar.org/docs/glossary/multisig/#hashx

func (*FeeBumpTransaction) SignWithKeyString

func (t *FeeBumpTransaction) SignWithKeyString(network string, keys ...string) (*FeeBumpTransaction, error)

SignWithKeyString returns a new FeeBumpTransaction instance which extends the current instance with additional signatures derived from the given list of private key strings.

func (*FeeBumpTransaction) Signatures

func (t *FeeBumpTransaction) Signatures() []xdr.DecoratedSignature

Signatures returns the list of signatures attached to this transaction. The contents of the returned slice should not be modified.

func (*FeeBumpTransaction) ToGenericTransaction

func (t *FeeBumpTransaction) ToGenericTransaction() *GenericTransaction

ToGenericTransaction creates a GenericTransaction containing the FeeBumpTransaction.

func (*FeeBumpTransaction) ToXDR

ToXDR returns the a xdr.TransactionEnvelope which is equivalent to this transaction. The envelope should not be modified because any changes applied may affect the internals of the FeeBumpTransaction instance.

func (*FeeBumpTransaction) UnmarshalText

func (t *FeeBumpTransaction) UnmarshalText(b []byte) error

UnmarshalText consumes into the value the base64 XDR representation of the transaction envelope.

type FeeBumpTransactionParams

type FeeBumpTransactionParams struct {
	Inner      *Transaction
	FeeAccount string
	BaseFee    int64
}

FeeBumpTransactionParams is a container for parameters which are used to construct new FeeBumpTransaction instances

type GenericTransaction

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

GenericTransaction represents a parsed transaction envelope returned by TransactionFromXDR. A GenericTransaction can be either a Transaction or a FeeBumpTransaction.

func NewGenericTransactionWithFeeBumpTransaction

func NewGenericTransactionWithFeeBumpTransaction(feeBumpTx *FeeBumpTransaction) *GenericTransaction

NewGenericTransactionWithFeeBumpTransaction creates a GenericTransaction containing a FeeBumpTransaction.

func NewGenericTransactionWithTransaction

func NewGenericTransactionWithTransaction(tx *Transaction) *GenericTransaction

NewGenericTransactionWithTransaction creates a GenericTransaction containing a Transaction.

func TransactionFromXDR

func TransactionFromXDR(txeB64 string) (*GenericTransaction, error)

TransactionFromXDR parses the supplied transaction envelope in base64 XDR and returns a GenericTransaction instance.

func (GenericTransaction) FeeBump

func (t GenericTransaction) FeeBump() (*FeeBumpTransaction, bool)

FeeBump unpacks the GenericTransaction instance into a FeeBumpTransaction. The function also returns a boolean which is true if the GenericTransaction can be unpacked into a FeeBumpTransaction.

func (GenericTransaction) Hash

func (t GenericTransaction) Hash(networkStr string) ([32]byte, error)

Hash returns the network specific hash of this transaction encoded as a byte array.

func (GenericTransaction) HashHex

func (t GenericTransaction) HashHex(network string) (string, error)

HashHex returns the network specific hash of this transaction encoded as a hexadecimal string.

func (*GenericTransaction) MarshalBinary

func (t *GenericTransaction) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary XDR representation of the transaction envelope.

func (*GenericTransaction) MarshalText

func (t *GenericTransaction) MarshalText() ([]byte, error)

MarshalText returns the base64 XDR representation of the transaction envelope.

func (*GenericTransaction) ToXDR

ToXDR returns the a xdr.TransactionEnvelope which is equivalent to this transaction. The envelope should not be modified because any changes applied may affect the internals of the GenericTransaction.

func (GenericTransaction) Transaction

func (t GenericTransaction) Transaction() (*Transaction, bool)

Transaction unpacks the GenericTransaction instance into a Transaction. The function also returns a boolean which is true if the GenericTransaction can be unpacked into a Transaction.

func (*GenericTransaction) UnmarshalText

func (t *GenericTransaction) UnmarshalText(b []byte) error

UnmarshalText consumes into the value the base64 XDR representation of the transaction envelope.

type Inflation

type Inflation struct {
	SourceAccount string
}

Inflation represents the Stellar inflation operation. See https://developers.stellar.org/docs/start/list-of-operations/

func (*Inflation) BuildXDR

func (inf *Inflation) BuildXDR() (xdr.Operation, error)

BuildXDR for Inflation returns a fully configured XDR Operation.

func (*Inflation) FromXDR

func (inf *Inflation) FromXDR(xdrOp xdr.Operation) error

FromXDR for Inflation initialises the txnbuild struct from the corresponding xdr Operation.

func (*Inflation) GetSourceAccount

func (inf *Inflation) GetSourceAccount() string

GetSourceAccount returns the source account of the operation, or the empty string if not set.

func (*Inflation) Validate

func (inf *Inflation) Validate() error

Validate for Inflation is just a method that implements the Operation interface. No logic is actually performed because the inflation operation does not have any required field. Nil is always returned.

type LedgerBounds

type LedgerBounds struct {
	MinLedger uint32
	MaxLedger uint32
}

LedgerBounds represent a transaction precondition that controls the ledger range for which a transaction is valid. Setting MaxLedger = 0 indicates there is no maximum ledger.

func (*LedgerBounds) Validate

func (lb *LedgerBounds) Validate() error

type Memo

type Memo interface {
	ToXDR() (xdr.Memo, error)
}

Memo represents the superset of all memo types.

type MemoHash

type MemoHash [32]byte

MemoHash is a hash representing a reference to another transaction.

func (MemoHash) ToXDR

func (mh MemoHash) ToXDR() (xdr.Memo, error)

ToXDR for MemoHash returns an XDR object representation of a Memo of the same type.

type MemoID

type MemoID uint64

MemoID is an identifier representing the transaction originator.

func (MemoID) ToXDR

func (mid MemoID) ToXDR() (xdr.Memo, error)

ToXDR for MemoID returns an XDR object representation of a Memo of the same type.

type MemoReturn

type MemoReturn [32]byte

MemoReturn is a hash representing the hash of the transaction the sender is refunding.

func (MemoReturn) ToXDR

func (mr MemoReturn) ToXDR() (xdr.Memo, error)

ToXDR for MemoReturn returns an XDR object representation of a Memo of the same type.

type MemoText

type MemoText string

MemoText is used to send human messages of up to 28 bytes of ASCII/UTF-8.

func (MemoText) ToXDR

func (mt MemoText) ToXDR() (xdr.Memo, error)

ToXDR for MemoText returns an XDR object representation of a Memo of the same type.

type NativeAsset

type NativeAsset struct{}

NativeAsset represents the native XLM asset.

func (NativeAsset) GetCode

func (na NativeAsset) GetCode() string

GetCode for NativeAsset returns an empty string (XLM doesn't have a code).

func (NativeAsset) GetIssuer

func (na NativeAsset) GetIssuer() string

GetIssuer for NativeAsset returns an empty string (XLM doesn't have an issuer).

func (NativeAsset) GetType

func (na NativeAsset) GetType() (AssetType, error)

GetType for NativeAsset returns the enum type of the asset.

func (NativeAsset) IsNative

func (na NativeAsset) IsNative() bool

IsNative for NativeAsset returns true (this is an XLM asset).

func (NativeAsset) LessThan

func (na NativeAsset) LessThan(other Asset) bool

LessThan returns true if this asset sorts before some other asset.

func (NativeAsset) MustToAsset

func (na NativeAsset) MustToAsset() Asset

MustToAsset for NativeAsset returns itself unchanged.

func (NativeAsset) MustToChangeTrustAsset

func (na NativeAsset) MustToChangeTrustAsset() ChangeTrustAsset

MustToChangeTrustAsset for NativeAsset produces a corresponding ChangeTrustAsset.

func (NativeAsset) MustToTrustLineAsset

func (na NativeAsset) MustToTrustLineAsset() TrustLineAsset

MustToTrustLineAsset for NativeAsset produces a corresponding TrustLineAsset.

func (NativeAsset) ToAsset

func (na NativeAsset) ToAsset() (Asset, error)

ToAsset for NativeAsset returns itself unchanged.

func (NativeAsset) ToChangeTrustAsset

func (na NativeAsset) ToChangeTrustAsset() (ChangeTrustAsset, error)

ToChangeTrustAsset for NativeAsset produces a corresponding ChangeTrustAsset.

func (NativeAsset) ToTrustLineAsset

func (na NativeAsset) ToTrustLineAsset() (TrustLineAsset, error)

ToTrustLineAsset for NativeAsset produces a corresponding TrustLineAsset.

func (NativeAsset) ToXDR

func (na NativeAsset) ToXDR() (xdr.Asset, error)

ToXDR for NativeAsset produces a corresponding XDR asset.

type Operation

type Operation interface {
	BuildXDR() (xdr.Operation, error)
	FromXDR(xdrOp xdr.Operation) error
	Validate() error
	GetSourceAccount() string
}

Operation represents the operation types of the Stellar network.

type Payment

type Payment struct {
	Destination   string
	Amount        string
	Asset         Asset
	SourceAccount string
}

Payment represents the Stellar payment operation. See https://developers.stellar.org/docs/start/list-of-operations/

func (*Payment) BuildXDR

func (p *Payment) BuildXDR() (xdr.Operation, error)

func (*Payment) FromXDR

func (p *Payment) FromXDR(xdrOp xdr.Operation) error

FromXDR for Payment initialises the txnbuild struct from the corresponding xdr Operation.

func (*Payment) GetSourceAccount

func (p *Payment) GetSourceAccount() string

GetSourceAccount returns the source account of the operation, or the empty string if not set.

func (*Payment) Validate

func (p *Payment) Validate() error

Validate for Payment validates the required struct fields. It returns an error if any of the fields are invalid. Otherwise, it returns nil.

type Preconditions

type Preconditions struct {
	// Transaction is only valid during a certain time range (units are seconds).
	TimeBounds TimeBounds
	// Transaction is valid for ledger numbers n such that minLedger <= n <
	// maxLedger (if maxLedger == 0, then only minLedger is checked)
	LedgerBounds *LedgerBounds
	// If nil, the transaction is only valid when sourceAccount's sequence
	// number "N" is seqNum - 1. Otherwise, valid when N satisfies minSeqNum <=
	// N < tx.seqNum.
	MinSequenceNumber *int64
	// Transaction is valid if the current ledger time is at least
	// minSequenceNumberAge greater than the source account's seqTime (units are
	// seconds).
	MinSequenceNumberAge uint64
	// Transaction is valid if the current ledger number is at least
	// minSequenceNumberLedgerGap greater than the source account's seqLedger.
	MinSequenceNumberLedgerGap uint32
	// Transaction is valid if there is a signature corresponding to every
	// Signer in this array, even if the signature is not otherwise required by
	// the source account or operations.
	ExtraSigners []string
}

Preconditions is a container for all transaction preconditions.

func (*Preconditions) BuildXDR

func (cond *Preconditions) BuildXDR() (xdr.Preconditions, error)

BuildXDR will create a precondition structure that varies depending on whether or not there are additional preconditions besides timebounds (which are required).

func (*Preconditions) FromXDR

func (cond *Preconditions) FromXDR(precondXdr xdr.Preconditions) error

FromXDR fills in the precondition structure from an xdr.Precondition.

func (*Preconditions) Validate

func (cond *Preconditions) Validate() error

Validate ensures that all enabled preconditions are valid.

type SignerSummary

type SignerSummary map[string]int32

SignerSummary is a map of signers to their weights.

type SimpleAccount

type SimpleAccount struct {
	AccountID string
	Sequence  int64
}

SimpleAccount is a minimal implementation of an Account.

func NewSimpleAccount

func NewSimpleAccount(accountID string, sequence int64) SimpleAccount

NewSimpleAccount is a factory method that creates a SimpleAccount from "accountID" and "sequence".

func (*SimpleAccount) GetAccountID

func (sa *SimpleAccount) GetAccountID() string

GetAccountID returns the Account ID.

func (*SimpleAccount) GetSequenceNumber

func (sa *SimpleAccount) GetSequenceNumber() (int64, error)

GetSequenceNumber returns the sequence number of the account.

func (*SimpleAccount) IncrementSequenceNumber

func (sa *SimpleAccount) IncrementSequenceNumber() (int64, error)

IncrementSequenceNumber increments the internal record of the account's sequence number by 1.

type SorobanOperation

type SorobanOperation interface {
	BuildTransactionExt() (xdr.TransactionExt, error)
}

SorobanOperation represents a smart contract operation on the Stellar network.

type TimeBounds

type TimeBounds struct {
	MinTime int64
	MaxTime int64
	// contains filtered or unexported fields
}

TimeBounds represents the time window during which a Stellar transaction is considered valid.

MinTime and MaxTime represent Stellar timebounds - a window of time over which the Transaction will be considered valid. In general, almost all Transactions benefit from setting an upper timebound, because once submitted, the status of a pending Transaction may remain unresolved for a long time if the network is congested. With an upper timebound, the submitter has a guaranteed time at which the Transaction is known to have either succeeded or failed, and can then take appropriate action (e.g. to resubmit or mark as resolved).

Create a TimeBounds struct using one of NewTimebounds(), NewTimeout(), or NewInfiniteTimeout().

func NewInfiniteTimeout

func NewInfiniteTimeout() TimeBounds

NewInfiniteTimeout is a factory method that sets the MaxTime to a value representing an indefinite upper time bound. This is rarely needed, but is helpful for certain smart contracts, and for deterministic testing. A Transaction cannot be built unless a TimeBounds object is provided through a factory method.

func NewTimebounds

func NewTimebounds(minTime, maxTime int64) TimeBounds

NewTimebounds is a factory method that constructs a TimeBounds object from a min and max time. A Transaction cannot be built unless a TimeBounds object is provided through a factory method.

func NewTimeout

func NewTimeout(timeout int64) TimeBounds

NewTimeout is a factory method that sets the MaxTime to be the duration in seconds in the future specified by 'timeout'. A Transaction cannot be built unless a TimeBounds object is provided through a factory method. This method uses the provided system time - make sure it is accurate.

func (*TimeBounds) Validate

func (tb *TimeBounds) Validate() error

Validate for TimeBounds sanity-checks the configured Timebound limits, and confirms the object was built using a factory method. This is done to ensure that default Timebound structs (which have no limits) are not valid - you must explicitly specify the Timebound you require.

type Timebounds

type Timebounds = TimeBounds

type Transaction

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

Transaction represents a Stellar transaction. See https://developers.stellar.org/docs/glossary/transactions/ A Transaction may be wrapped by a FeeBumpTransaction in which case the account authorizing the FeeBumpTransaction will pay for the transaction fees instead of the Transaction's source account.

func NewTransaction

func NewTransaction(params TransactionParams) (*Transaction, error)

NewTransaction returns a new Transaction instance

func (*Transaction) AddSignatureBase64

func (t *Transaction) AddSignatureBase64(network, publicKey, signature string) (*Transaction, error)

AddSignatureBase64 returns a new Transaction instance which extends the current instance with an additional signature derived from the given base64-encoded signature.

func (*Transaction) AddSignatureDecorated

func (t *Transaction) AddSignatureDecorated(signature ...xdr.DecoratedSignature) (*Transaction, error)

AddSignatureDecorated returns a new Transaction instance which extends the current instance with an additional decorated signature(s).

func (*Transaction) Base64

func (t *Transaction) Base64() (string, error)

Base64 returns the base 64 XDR representation of the transaction envelope.

func (*Transaction) BaseFee

func (t *Transaction) BaseFee() int64

BaseFee returns the per operation fee for this transaction.

func (*Transaction) ClearSignatures

func (t *Transaction) ClearSignatures() (*Transaction, error)

ClearSignatures returns a new Transaction instance which extends the current instance with signatures removed.

func (*Transaction) Hash

func (t *Transaction) Hash(networkStr string) ([32]byte, error)

Hash returns the network specific hash of this transaction encoded as a byte array.

func (*Transaction) HashHex

func (t *Transaction) HashHex(network string) (string, error)

HashHex returns the network specific hash of this transaction encoded as a hexadecimal string.

func (*Transaction) MarshalBinary

func (t *Transaction) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary XDR representation of the transaction envelope.

func (*Transaction) MarshalText

func (t *Transaction) MarshalText() ([]byte, error)

MarshalText returns the base64 XDR representation of the transaction envelope.

func (*Transaction) MaxFee

func (t *Transaction) MaxFee() int64

MaxFee returns the total fees which can be spent to submit this transaction.

func (*Transaction) Memo

func (t *Transaction) Memo() Memo

Memo returns the memo configured for this transaction.

func (*Transaction) Operations

func (t *Transaction) Operations() []Operation

Operations returns the list of operations included in this transaction. The contents of the returned slice should not be modified.

func (*Transaction) SequenceNumber

func (t *Transaction) SequenceNumber() int64

SequenceNumber returns the sequence number of the transaction.

func (*Transaction) Sign

func (t *Transaction) Sign(network string, kps ...*keypair.Full) (*Transaction, error)

Sign returns a new Transaction instance which extends the current instance with additional signatures derived from the given list of keypair instances.

func (*Transaction) SignHashX

func (t *Transaction) SignHashX(preimage []byte) (*Transaction, error)

SignHashX returns a new Transaction instance which extends the current instance with HashX signature type. See description here: https://developers.stellar.org/docs/glossary/multisig/#hashx

func (*Transaction) SignWithKeyString

func (t *Transaction) SignWithKeyString(network string, keys ...string) (*Transaction, error)

SignWithKeyString returns a new Transaction instance which extends the current instance with additional signatures derived from the given list of private key strings.

func (*Transaction) Signatures

func (t *Transaction) Signatures() []xdr.DecoratedSignature

Signatures returns the list of signatures attached to this transaction. The contents of the returned slice should not be modified.

func (*Transaction) SourceAccount

func (t *Transaction) SourceAccount() SimpleAccount

SourceAccount returns the account which is originating this account.

func (*Transaction) Timebounds

func (t *Transaction) Timebounds() TimeBounds

Timebounds returns the Timebounds configured for this transaction.

func (*Transaction) ToGenericTransaction

func (t *Transaction) ToGenericTransaction() *GenericTransaction

ToGenericTransaction creates a GenericTransaction containing the Transaction.

func (*Transaction) ToXDR

func (t *Transaction) ToXDR() xdr.TransactionEnvelope

ToXDR returns the a xdr.TransactionEnvelope which is equivalent to this transaction. The envelope should not be modified because any changes applied may affect the internals of the Transaction instance.

func (*Transaction) UnmarshalText

func (t *Transaction) UnmarshalText(b []byte) error

UnmarshalText consumes into the value the base64 XDR representation of the transaction envelope.

type TransactionParams

type TransactionParams struct {
	SourceAccount        Account
	IncrementSequenceNum bool
	Operations           []Operation
	BaseFee              int64
	Memo                 Memo
	Preconditions        Preconditions
}

TransactionParams is a container for parameters which are used to construct new Transaction instances

type TrustLineAsset

type TrustLineAsset interface {
	BasicAsset
	ToXDR() (xdr.TrustLineAsset, error)
}

TrustLineAsset represents a Stellar trust line asset.

type TrustLineAssetWrapper

type TrustLineAssetWrapper struct {
	Asset
}

TrustLineAssetWrapper wraps a native/credit Asset so it generates xdr to be used in a trust line operation.

func (TrustLineAssetWrapper) ToXDR

ToXDR for TrustLineAssetWrapper generates the xdr.TrustLineAsset.

type ValidationError

type ValidationError struct {
	Field   string // Field is the struct field on which the validation error occurred.
	Message string // Message is the validation error message.
}

ValidationError is a custom error struct that holds validation errors of txnbuild's operation structs.

func NewValidationError

func NewValidationError(field, message string) *ValidationError

NewValidationError creates a ValidationError struct with the provided field and message values.

func (*ValidationError) Error

func (opError *ValidationError) Error() string

Error for ValidationError struct implements the error interface.

Jump to

Keyboard shortcuts

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