go: github.com/stellar/go/txnbuild Index | Examples | Files | Directories

package txnbuild

import "github.com/stellar/go/txnbuild"

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://www.stellar.org/developers/go/reference/index.html.

Index

Examples

Package Files

account_merge.go allow_trust.go asset.go bump_sequence.go change_trust.go create_account.go create_passive_offer.go helpers.go inflation.go manage_buy_offer.go manage_data.go manage_offer.go memo.go operation.go path_payment.go path_payment_strict_send.go payment.go price.go set_options.go signer_summary.go simple_account.go timebounds.go transaction.go

Constants

const AuthImmutable = AccountFlag(xdr.AccountFlagsAuthImmutableFlag)

AuthImmutable is a flag that if set prevents any authorization flags from being set, and prevents the account from ever being merged (deleted).

const AuthRequired = AccountFlag(xdr.AccountFlagsAuthRequiredFlag)

AuthRequired is a flag that requires the issuing account to give other accounts permission before they can hold the issuing account's credit.

const AuthRevocable = AccountFlag(xdr.AccountFlagsAuthRevocableFlag)

AuthRevocable is a flag that allows the issuing account to revoke its credit held by other accounts.

const MemoTextMaxLength = 28

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

const MinBaseFee = 100

MinBaseFee is the minimum transaction fee for the Stellar network.

const TimeoutInfinite = int64(0)

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

Variables

var MaxTrustlineLimit = amount.StringFromInt64(math.MaxInt64)

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

func NewHomeDomain Uses

func NewHomeDomain(hd string) *string

NewHomeDomain is syntactic sugar that makes instantiating SetOptions more convenient.

func NewInflationDestination Uses

func NewInflationDestination(ai string) *string

NewInflationDestination is syntactic sugar that makes instantiating SetOptions more convenient.

func SetOpSourceAccount Uses

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

SetOpSourceAccount sets the source account ID on an Operation.

func VerifyChallengeTxSigners Uses

func VerifyChallengeTxSigners(challengeTx, serverAccountID, network string, signers ...string) ([]string, error)

VerifyChallengeTxSigners verifies that for a SEP 10 challenge transaction all signatures on the transaction are accounted for. A transaction is verified if it is signed by the server account, and all other signatures match a signer that has been provided as an argument. Additional signers can be provided that do not have a signature, but all signatures must be matched to a signer for verification to succeed. If verification succeeds a list of signers that were found is returned, excluding the server account ID.

Signers that are not prefixed as an address/account ID strkey (G...) will be ignored.

Errors will be raised if:

- The transaction is invalid according to ReadChallengeTx.
- No client signatures are found on the transaction.
- One or more signatures in the transaction are not identifiable as the
  server account or one of the signers provided in the arguments.

func VerifyChallengeTxThreshold Uses

func VerifyChallengeTxThreshold(challengeTx, serverAccountID, network string, threshold Threshold, signerSummary SignerSummary) (signersFound []string, err error)

VerifyChallengeTxThreshold verifies that for a SEP 10 challenge transaction all signatures on the transaction are accounted for and that the signatures meet a threshold on an account. A transaction is verified if it is signed by the server account, and all other signatures match a signer that has been provided as an argument, and those signatures meet a threshold on the account.

Signers that are not prefixed as an address/account ID strkey (G...) will be ignored.

Errors will be raised if:

- The transaction is invalid according to ReadChallengeTx.
- No client signatures are found on the transaction.
- One or more signatures in the transaction are not identifiable as the
  server account or one of the signers provided in the arguments.
- The signatures are all valid but do not meet the threshold.

Code:

package main

import (
    "fmt"
    "sort"
    "time"

    "github.com/stellar/go/clients/horizonclient"
    "github.com/stellar/go/keypair"
    "github.com/stellar/go/network"
    "github.com/stellar/go/protocols/horizon"
    "github.com/stellar/go/txnbuild"
)

var serverAccount, _ = keypair.ParseFull("SCDXPYDGKV5HOAGVZN3FQSS5FKUPP5BAVBWH4FXKTAWAC24AE4757JSI")
var clientAccount, _ = keypair.ParseFull("SANVNCABRBVISCV7KH4SZVBKPJWWTT4424OVWUHUHPH2MVSF6RC7HPGN")
var clientSigner1, _ = keypair.ParseFull("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
var clientSigner2, _ = keypair.ParseFull("SBMSVD4KKELKGZXHBUQTIROWUAPQASDX7KEJITARP4VMZ6KLUHOGPTYW")
var horizonClient = func() horizonclient.ClientInterface {
    client := &horizonclient.MockClient{}
    client.
        On("AccountDetail", horizonclient.AccountRequest{AccountID: clientAccount.Address()}).
        Return(
            horizon.Account{
                Thresholds: horizon.AccountThresholds{LowThreshold: 1, MedThreshold: 10, HighThreshold: 100},
                Signers: []horizon.Signer{
                    {Key: clientSigner1.Address(), Weight: 40},
                    {Key: clientSigner2.Address(), Weight: 60},
                },
            },
            nil,
        )
    return client
}()

func main() {
    // Server builds challenge transaction
    var challengeTx string
    {
        tx, err := txnbuild.BuildChallengeTx(serverAccount.Seed(), clientAccount.Address(), "test", network.TestNetworkPassphrase, time.Minute)
        if err != nil {
            fmt.Println("Error:", err)
            return
        }
        challengeTx, err = tx.Base64()
        if err != nil {
            fmt.Println("Error:", err)
            return
        }
    }

    // Client reads and signs challenge transaction
    var signedChallengeTx string
    {
        tx, txClientAccountID, err := txnbuild.ReadChallengeTx(challengeTx, serverAccount.Address(), network.TestNetworkPassphrase)
        if err != nil {
            fmt.Println("Error:", err)
            return
        }
        if txClientAccountID != clientAccount.Address() {
            fmt.Println("Error: challenge tx is not for expected client account")
            return
        }
        tx, err = tx.Sign(network.TestNetworkPassphrase, clientSigner1, clientSigner2)
        if err != nil {
            fmt.Println("Error:", err)
            return
        }
        signedChallengeTx, err = tx.Base64()
        if err != nil {
            fmt.Println("Error:", err)
            return
        }
    }

    // Server verifies signed challenge transaction
    {
        _, txClientAccountID, err := txnbuild.ReadChallengeTx(challengeTx, serverAccount.Address(), network.TestNetworkPassphrase)
        if err != nil {
            fmt.Println("Error:", err)
            return
        }

        // Server gets account
        clientAccountExists := false
        horizonClientAccount, err := horizonClient.AccountDetail(horizonclient.AccountRequest{AccountID: txClientAccountID})
        if horizonclient.IsNotFoundError(err) {
            clientAccountExists = false
            fmt.Println("Account does not exist, use master key to verify")
        } else if err == nil {
            clientAccountExists = true
        } else {
            fmt.Println("Error:", err)
            return
        }

        if clientAccountExists {
            // Server gets list of signers from account
            signerSummary := horizonClientAccount.SignerSummary()

            // Server chooses the threshold to require: low, med or high
            threshold := txnbuild.Threshold(horizonClientAccount.Thresholds.MedThreshold)

            // Server verifies threshold is met
            signers, err := txnbuild.VerifyChallengeTxThreshold(signedChallengeTx, serverAccount.Address(), network.TestNetworkPassphrase, threshold, signerSummary)
            if err != nil {
                fmt.Println("Error:", err)
                return
            }
            fmt.Println("Client Signers Verified:")
            sort.Strings(signers)
            for _, signer := range signers {
                fmt.Println(signer, "weight:", signerSummary[signer])
            }
        } else {
            // Server verifies that master key has signed challenge transaction
            signersFound, err := txnbuild.VerifyChallengeTxSigners(signedChallengeTx, serverAccount.Address(), network.TestNetworkPassphrase, txClientAccountID)
            if err != nil {
                fmt.Println("Error:", err)
                return
            }
            fmt.Println("Client Master Key Verified:")
            for _, signerFound := range signersFound {
                fmt.Println(signerFound)
            }
        }
    }

}

type Account Uses

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://www.stellar.org/developers/guides/concepts/accounts.html

type AccountFlag Uses

type AccountFlag uint32

AccountFlag represents the bitmask flags used to set and clear account authorization options.

type AccountMerge Uses

type AccountMerge struct {
    Destination   string
    SourceAccount Account
}

AccountMerge represents the Stellar merge account operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := AccountMerge{
    Destination: "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z",
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAIAAAAAITg3tq8G0kvnvoIhZPMYJsY+9KVV8xAA6NxhtKxIXZUAAAAAAAAAAHqLnLFAAAAQC87HdYfOZpOx/isr7JEOy9ef3GH51ToKSkC6b4UJdDktlCqHFCD0cSttJ/F5MUx2ScSkwpeAlEVR8B62X6N/g4=

func (*AccountMerge) BuildXDR Uses

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

BuildXDR for AccountMerge returns a fully configured XDR Operation.

func (*AccountMerge) FromXDR Uses

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

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

func (*AccountMerge) GetSourceAccount Uses

func (am *AccountMerge) GetSourceAccount() Account

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

func (*AccountMerge) Validate Uses

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 Uses

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

AllowTrust represents the Stellar allow trust operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := AllowTrust{
    Trustor:   "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z",
    Type:      CreditAsset{"ABCD", "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z"},
    Authorize: true,
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAHAAAAAITg3tq8G0kvnvoIhZPMYJsY+9KVV8xAA6NxhtKxIXZUAAAAAUFCQ0QAAAABAAAAAAAAAAHqLnLFAAAAQBjcydaIxwvXxLFEhNK4jm1lJeYSjRDfxRmDSOIkZTZTqRKewI1NMmIYAIZCUis98Axi32ShqutfXXDscsGixA0=

func (*AllowTrust) BuildXDR Uses

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

BuildXDR for AllowTrust returns a fully configured XDR Operation.

func (*AllowTrust) FromXDR Uses

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

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

func (*AllowTrust) GetSourceAccount Uses

func (at *AllowTrust) GetSourceAccount() Account

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

func (*AllowTrust) Validate Uses

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 Uses

type Asset interface {
    GetType() (AssetType, error)
    IsNative() bool
    GetCode() string
    GetIssuer() string
    ToXDR() (xdr.Asset, error)
}

Asset represents a Stellar asset.

type AssetType Uses

type AssetType xdr.AssetType

AssetType represents the type of a Stellar asset.

const (
    AssetTypeNative           AssetType = AssetType(xdr.AssetTypeAssetTypeNative)
    AssetTypeCreditAlphanum4  AssetType = AssetType(xdr.AssetTypeAssetTypeCreditAlphanum4)
    AssetTypeCreditAlphanum12 AssetType = AssetType(xdr.AssetTypeAssetTypeCreditAlphanum12)
)

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

type BumpSequence Uses

type BumpSequence struct {
    BumpTo        int64
    SourceAccount Account
}

BumpSequence represents the Stellar bump sequence operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := BumpSequence{
    BumpTo: 9606132444168300,
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAALACIgugAAAGwAAAAAAAAAAeoucsUAAABAQi/I4d0+fzZyQpchIYXqxHhhTmjHvfmK8qsL/BLjrXmPUADja9tdIupKEkDn/v8NfnpRS/4u3u+Vy70zuOxHDg==

func (*BumpSequence) BuildXDR Uses

func (bs *BumpSequence) BuildXDR() (xdr.Operation, error)

BuildXDR for BumpSequence returns a fully configured XDR Operation.

func (*BumpSequence) FromXDR Uses

func (bs *BumpSequence) FromXDR(xdrOp xdr.Operation) error

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

func (*BumpSequence) GetSourceAccount Uses

func (bs *BumpSequence) GetSourceAccount() Account

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

func (*BumpSequence) Validate Uses

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 Uses

type ChangeTrust struct {
    Line          Asset
    Limit         string
    SourceAccount Account
}

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

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := ChangeTrust{
    Line:  CreditAsset{"ABCD", "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z"},
    Limit: "10",
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAGAAAAAUFCQ0QAAAAAhODe2rwbSS+e+giFk8xgmxj70pVXzEADo3GG0rEhdlQAAAAABfXhAAAAAAAAAAAB6i5yxQAAAECqpS4iUUyuUSVicZIseVoj8DjWgYDet21zUQeHNr1teTflnCUS+awFQ5lNqxl+AHPB34JzN6RYoEISoEIfNpIH

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := RemoveTrustlineOp(CreditAsset{"ABCD", "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z"})

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAGAAAAAUFCQ0QAAAAAhODe2rwbSS+e+giFk8xgmxj70pVXzEADo3GG0rEhdlQAAAAAAAAAAAAAAAAAAAAB6i5yxQAAAEAouZRZwuPF5j68byMRcw2mtToS6nFsxGJcZjO4oGm2dWVsVS1MGqFhr+JvIJlMRUKKdPxtZAoO9kjSbpUspUcC

func RemoveTrustlineOp Uses

func RemoveTrustlineOp(issuedAsset Asset) ChangeTrust

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

func (*ChangeTrust) BuildXDR Uses

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

BuildXDR for ChangeTrust returns a fully configured XDR Operation.

func (*ChangeTrust) FromXDR Uses

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

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

func (*ChangeTrust) GetSourceAccount Uses

func (ct *ChangeTrust) GetSourceAccount() Account

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

func (*ChangeTrust) Validate Uses

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 CreateAccount Uses

type CreateAccount struct {
    Destination   string
    Amount        string
    SourceAccount Account
}

CreateAccount represents the Stellar create account operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := CreateAccount{
    Destination: "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z",
    Amount:      "10",
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAITg3tq8G0kvnvoIhZPMYJsY+9KVV8xAA6NxhtKxIXZUAAAAAAX14QAAAAAAAAAAAeoucsUAAABAqyuXG3pGL9a4MZwrX5OTWF1gd094rsowh2zXSZzDPDoGlAVljE/yjo7p6MkUY7TpMAa3Y+iXC5ael6JVD0pyDQ==

func (*CreateAccount) BuildXDR Uses

func (ca *CreateAccount) BuildXDR() (xdr.Operation, error)

BuildXDR for CreateAccount returns a fully configured XDR Operation.

func (*CreateAccount) FromXDR Uses

func (ca *CreateAccount) FromXDR(xdrOp xdr.Operation) error

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

func (*CreateAccount) GetSourceAccount Uses

func (ca *CreateAccount) GetSourceAccount() Account

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

func (*CreateAccount) Validate Uses

func (ca *CreateAccount) Validate() error

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

type CreatePassiveSellOffer Uses

type CreatePassiveSellOffer struct {
    Selling Asset
    Buying  Asset
    Amount  string
    Price   string

    SourceAccount Account
    // contains filtered or unexported fields
}

CreatePassiveSellOffer represents the Stellar create passive offer operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := CreatePassiveSellOffer{
    Selling: NativeAsset{},
    Buying:  CreditAsset{"ABCD", "GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP"},
    Amount:  "10",
    Price:   "1.0",
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAEAAAAAAAAAAFBQkNEAAAAACXK8doPx27P6IReQlRRuweSSUiUfjqgyswxiu3Sh2R+AAAAAAX14QAAAAABAAAAAQAAAAAAAAAB6i5yxQAAAEAThdst0NXPUzAL0GzzieSoryHIeF5VtjOc1KIA/SGI/xq69woAydjPccm/MzwfSr8rkw++AFp6Edn+1C1o9IYG

func (*CreatePassiveSellOffer) BuildXDR Uses

func (cpo *CreatePassiveSellOffer) BuildXDR() (xdr.Operation, error)

BuildXDR for CreatePassiveSellOffer returns a fully configured XDR Operation.

func (*CreatePassiveSellOffer) FromXDR Uses

func (cpo *CreatePassiveSellOffer) FromXDR(xdrOp xdr.Operation) error

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

func (*CreatePassiveSellOffer) GetSourceAccount Uses

func (cpo *CreatePassiveSellOffer) GetSourceAccount() Account

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

func (*CreatePassiveSellOffer) Validate Uses

func (cpo *CreatePassiveSellOffer) Validate() error

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

type CreditAsset Uses

type CreditAsset struct {
    Code   string
    Issuer string
}

CreditAsset represents non-XLM assets on the Stellar network.

func (CreditAsset) GetCode Uses

func (ca CreditAsset) GetCode() string

GetCode for CreditAsset returns the asset code.

func (CreditAsset) GetIssuer Uses

func (ca CreditAsset) GetIssuer() string

GetIssuer for CreditAsset returns the address of the issuing account.

func (CreditAsset) GetType Uses

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

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

func (CreditAsset) IsNative Uses

func (ca CreditAsset) IsNative() bool

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

func (CreditAsset) ToXDR Uses

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

ToXDR for CreditAsset produces a corresponding XDR asset.

type FeeBumpTransaction Uses

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 Uses

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

NewFeeBumpTransaction returns a new FeeBumpTransaction instance

func (*FeeBumpTransaction) AddSignatureBase64 Uses

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) Base64 Uses

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

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

func (*FeeBumpTransaction) BaseFee Uses

func (t *FeeBumpTransaction) BaseFee() int64

BaseFee returns the per operation fee for this transaction.

func (*FeeBumpTransaction) FeeAccount Uses

func (t *FeeBumpTransaction) FeeAccount() string

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

func (*FeeBumpTransaction) Hash Uses

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 Uses

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 Uses

func (t *FeeBumpTransaction) InnerTransaction() *Transaction

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

func (*FeeBumpTransaction) MarshalBinary Uses

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

MarshalBinary returns the binary XDR representation of the transaction envelope.

func (*FeeBumpTransaction) MaxFee Uses

func (t *FeeBumpTransaction) MaxFee() int64

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

func (*FeeBumpTransaction) Sign Uses

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 Uses

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://www.stellar.org/developers/guides/concepts/multi-sig.html#hashx.

func (*FeeBumpTransaction) SignWithKeyString Uses

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 Uses

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) TxEnvelope Uses

func (t *FeeBumpTransaction) TxEnvelope() (xdr.TransactionEnvelope, error)

TxEnvelope returns the a xdr.TransactionEnvelope instance which is equivalent to this transaction.

type FeeBumpTransactionParams Uses

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 Uses

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 TransactionFromXDR Uses

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

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

func (GenericTransaction) FeeBump Uses

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) Transaction Uses

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.

type Inflation Uses

type Inflation struct {
    SourceAccount Account
}

Inflation represents the Stellar inflation operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := Inflation{}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAJAAAAAAAAAAHqLnLFAAAAQP3NHWXvzKIHB3+jjhHITdc/tBPntWYj3SoTjpON+dxjKqU5ohFamSHeqi5ONXkhE9Uajr5sVZXjQfUcTTzsWAA=

func (*Inflation) BuildXDR Uses

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

BuildXDR for Inflation returns a fully configured XDR Operation.

func (*Inflation) FromXDR Uses

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

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

func (*Inflation) GetSourceAccount Uses

func (inf *Inflation) GetSourceAccount() Account

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

func (*Inflation) Validate Uses

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 ManageBuyOffer Uses

type ManageBuyOffer struct {
    Selling Asset
    Buying  Asset
    Amount  string
    Price   string

    OfferID       int64
    SourceAccount Account
    // contains filtered or unexported fields
}

ManageBuyOffer represents the Stellar manage buy offer operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBZVMB74Z76QZ3ZOY7UTDFYKMEGKW5XFJEB6PFKBF4UYSSWHG4EDH7PY")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

buyOffer := ManageBuyOffer{
    Selling: NativeAsset{},
    Buying:  CreditAsset{"ABCD", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"},
    Amount:  "100",
    Price:   "0.01",
    OfferID: 0,
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&buyOffer},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAH4RyzTWNfXhqwLUoCw91aWkZtgIzY8SAVkIPc0uFVmYAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAMAAAAAAAAAAFBQkNEAAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAADuaygAAAAABAAAAZAAAAAAAAAAAAAAAAAAAAAEuFVmYAAAAQPh8h1TrzDpcgzB/VE8V0X2pFGV8/JyuYrx0I5bRfBJuLJr0l8yL1isP1wZjvMdX7fNiktwSLuUuj749nWA6wAo=

func (*ManageBuyOffer) BuildXDR Uses

func (mo *ManageBuyOffer) BuildXDR() (xdr.Operation, error)

BuildXDR for ManageBuyOffer returns a fully configured XDR Operation.

func (*ManageBuyOffer) FromXDR Uses

func (mo *ManageBuyOffer) FromXDR(xdrOp xdr.Operation) error

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

func (*ManageBuyOffer) GetSourceAccount Uses

func (mo *ManageBuyOffer) GetSourceAccount() Account

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

func (*ManageBuyOffer) Validate Uses

func (mo *ManageBuyOffer) Validate() error

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

type ManageData Uses

type ManageData struct {
    Name          string
    Value         []byte
    SourceAccount Account
}

ManageData represents the Stellar manage data operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := ManageData{
    Name:  "Fruit preference",
    Value: []byte("Apple"),
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAKAAAAEEZydWl0IHByZWZlcmVuY2UAAAABAAAABUFwcGxlAAAAAAAAAAAAAAHqLnLFAAAAQO1ELJBEoqBDyIsS7uSJwe1LOimV/E+09MyF1G/+yrxSggFVPEjD5LXcm/6POze3IsMuIYJU1et5Q2Vt9f73zQo=

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := ManageData{
    Name: "Fruit preference",
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAKAAAAEEZydWl0IHByZWZlcmVuY2UAAAAAAAAAAAAAAAHqLnLFAAAAQMWkjW+mHMbwOfLhpUMDu3I6U/nv132RY7RT++arqlZOs2hx3r7FOJTvndbnSSwSxwDp/VY3BSxB/4MLCZl+ogA=

func (*ManageData) BuildXDR Uses

func (md *ManageData) BuildXDR() (xdr.Operation, error)

BuildXDR for ManageData returns a fully configured XDR Operation.

func (*ManageData) FromXDR Uses

func (md *ManageData) FromXDR(xdrOp xdr.Operation) error

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

func (*ManageData) GetSourceAccount Uses

func (md *ManageData) GetSourceAccount() Account

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

func (*ManageData) Validate Uses

func (md *ManageData) Validate() error

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

type ManageSellOffer Uses

type ManageSellOffer struct {
    Selling Asset
    Buying  Asset
    Amount  string
    Price   string

    OfferID       int64
    SourceAccount Account
    // contains filtered or unexported fields
}

ManageSellOffer represents the Stellar manage offer operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

selling := NativeAsset{}
buying := CreditAsset{"ABCD", "GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP"}
sellAmount := "100"
price := "0.01"
op, err := CreateOfferOp(selling, buying, sellAmount, price)
check(err)

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAADAAAAAAAAAAFBQkNEAAAAACXK8doPx27P6IReQlRRuweSSUiUfjqgyswxiu3Sh2R+AAAAADuaygAAAAABAAAAZAAAAAAAAAAAAAAAAAAAAAHqLnLFAAAAQG1+s35VQTuILAGTT6uaDT9RrgMi0xYTLqdoZbGgMGLiSwIglJk/OS/v1DrmshoXIhwL/O7Ilychy/vcA/4dAQo=

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

offerID := int64(2921622)
op, err := DeleteOfferOp(offerID)
check(err)

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAADAAAAAAAAAAFGQUtFAAAAAEEHgGTElYZi82AkGiJdSja2OBaU2aEcwwp3AY3tFJ2xAAAAAAAAAAAAAAABAAAAAQAAAAAALJSWAAAAAAAAAAHqLnLFAAAAQGcT6ggtq6q3qbx+PsMgE1b9cGYonfhIu8d3E/Ti9vbpojyr2L/an3+kkydY946gjDR/qOt5HfTqo8kWGMy2XgY=

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

selling := NativeAsset{}
buying := CreditAsset{"ABCD", "GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP"}
sellAmount := "50"
price := "0.02"
offerID := int64(2497628)
op, err := UpdateOfferOp(selling, buying, sellAmount, price, offerID)
check(err)

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAADAAAAAAAAAAFBQkNEAAAAACXK8doPx27P6IReQlRRuweSSUiUfjqgyswxiu3Sh2R+AAAAAB3NZQAAAAABAAAAMgAAAAAAJhxcAAAAAAAAAAHqLnLFAAAAQKY77jK6QC4tG1HghFY9W2jJnYsl5qKk+55z78zUkYOhMU9QsOXeSC6A/BXeavSO8w0CsF1HxLc1TDfWC1PlNw4=

func CreateOfferOp Uses

func CreateOfferOp(selling, buying Asset, amount, price string, sourceAccount ...Account) (ManageSellOffer, error)

CreateOfferOp returns a ManageSellOffer operation to create a new offer, by setting the OfferID to "0". The sourceAccount is optional, and if not provided, will be that of the surrounding transaction.

func DeleteOfferOp Uses

func DeleteOfferOp(offerID int64, sourceAccount ...Account) (ManageSellOffer, error)

DeleteOfferOp returns a ManageSellOffer operation to delete an offer, by setting the Amount to "0". The sourceAccount is optional, and if not provided, will be that of the surrounding transaction.

func UpdateOfferOp Uses

func UpdateOfferOp(selling, buying Asset, amount, price string, offerID int64, sourceAccount ...Account) (ManageSellOffer, error)

UpdateOfferOp returns a ManageSellOffer operation to update an offer. The sourceAccount is optional, and if not provided, will be that of the surrounding transaction.

func (*ManageSellOffer) BuildXDR Uses

func (mo *ManageSellOffer) BuildXDR() (xdr.Operation, error)

BuildXDR for ManageSellOffer returns a fully configured XDR Operation.

func (*ManageSellOffer) FromXDR Uses

func (mo *ManageSellOffer) FromXDR(xdrOp xdr.Operation) error

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

func (*ManageSellOffer) GetSourceAccount Uses

func (mo *ManageSellOffer) GetSourceAccount() Account

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

func (*ManageSellOffer) Validate Uses

func (mo *ManageSellOffer) Validate() error

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

type Memo Uses

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

Memo represents the superset of all memo types.

type MemoHash Uses

type MemoHash [32]byte

MemoHash is a hash representing a reference to another transaction.

func (MemoHash) ToXDR Uses

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

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

type MemoID Uses

type MemoID uint64

MemoID is an identifier representing the transaction originator.

func (MemoID) ToXDR Uses

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

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

type MemoReturn Uses

type MemoReturn [32]byte

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

func (MemoReturn) ToXDR Uses

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

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

type MemoText Uses

type MemoText string

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

func (MemoText) ToXDR Uses

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

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

type NativeAsset Uses

type NativeAsset struct{}

NativeAsset represents the native XLM asset.

func (NativeAsset) GetCode Uses

func (na NativeAsset) GetCode() string

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

func (NativeAsset) GetIssuer Uses

func (na NativeAsset) GetIssuer() string

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

func (NativeAsset) GetType Uses

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

GetType for NativeAsset returns the enum type of the asset.

func (NativeAsset) IsNative Uses

func (na NativeAsset) IsNative() bool

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

func (NativeAsset) ToXDR Uses

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

ToXDR for NativeAsset produces a corresponding XDR asset.

type Operation Uses

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

Operation represents the operation types of the Stellar network.

type PathPayment Uses

type PathPayment = PathPaymentStrictReceive

PathPayment represents the Stellar path_payment operation. This operation was removed in Stellar Protocol 12 and replaced by PathPaymentStrictReceive. Deprecated: This operation was renamed to PathPaymentStrictReceive, which functions identically.

Code:

kp, _ := keypair.Parse("SBZVMB74Z76QZ3ZOY7UTDFYKMEGKW5XFJEB6PFKBF4UYSSWHG4EDH7PY")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

abcdAsset := CreditAsset{"ABCD", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"}
op := PathPayment{
    SendAsset:   NativeAsset{},
    SendMax:     "10",
    Destination: kp.Address(),
    DestAsset:   NativeAsset{},
    DestAmount:  "1",
    Path:        []Asset{abcdAsset},
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAH4RyzTWNfXhqwLUoCw91aWkZtgIzY8SAVkIPc0uFVmYAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAACAAAAAAAAAAAF9eEAAAAAAH4RyzTWNfXhqwLUoCw91aWkZtgIzY8SAVkIPc0uFVmYAAAAAAAAAAAAmJaAAAAAAQAAAAFBQkNEAAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAAAAAAAEuFVmYAAAAQOGE+w2bvIp8JQIPIFXWk5kO77cNUOlPZwlItA5V68/qmZTbJWq8wqdZtjELkZtNcQQX4x8EToShbn5nitG3RA4=

type PathPaymentStrictReceive Uses

type PathPaymentStrictReceive struct {
    SendAsset     Asset
    SendMax       string
    Destination   string
    DestAsset     Asset
    DestAmount    string
    Path          []Asset
    SourceAccount Account
}

PathPaymentStrictReceive represents the Stellar path_payment_strict_receive operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBZVMB74Z76QZ3ZOY7UTDFYKMEGKW5XFJEB6PFKBF4UYSSWHG4EDH7PY")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

abcdAsset := CreditAsset{"ABCD", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"}
op := PathPaymentStrictReceive{
    SendAsset:   NativeAsset{},
    SendMax:     "10",
    Destination: kp.Address(),
    DestAsset:   NativeAsset{},
    DestAmount:  "1",
    Path:        []Asset{abcdAsset},
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAH4RyzTWNfXhqwLUoCw91aWkZtgIzY8SAVkIPc0uFVmYAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAACAAAAAAAAAAAF9eEAAAAAAH4RyzTWNfXhqwLUoCw91aWkZtgIzY8SAVkIPc0uFVmYAAAAAAAAAAAAmJaAAAAAAQAAAAFBQkNEAAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAAAAAAAEuFVmYAAAAQOGE+w2bvIp8JQIPIFXWk5kO77cNUOlPZwlItA5V68/qmZTbJWq8wqdZtjELkZtNcQQX4x8EToShbn5nitG3RA4=

func (*PathPaymentStrictReceive) BuildXDR Uses

func (pp *PathPaymentStrictReceive) BuildXDR() (xdr.Operation, error)

BuildXDR for PathPaymentStrictReceive returns a fully configured XDR Operation.

func (*PathPaymentStrictReceive) FromXDR Uses

func (pp *PathPaymentStrictReceive) FromXDR(xdrOp xdr.Operation) error

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

func (*PathPaymentStrictReceive) GetSourceAccount Uses

func (pp *PathPaymentStrictReceive) GetSourceAccount() Account

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

func (*PathPaymentStrictReceive) Validate Uses

func (pp *PathPaymentStrictReceive) Validate() error

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

type PathPaymentStrictSend Uses

type PathPaymentStrictSend struct {
    SendAsset     Asset
    SendAmount    string
    Destination   string
    DestAsset     Asset
    DestMin       string
    Path          []Asset
    SourceAccount Account
}

PathPaymentStrictSend represents the Stellar path_payment_strict_send operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBZVMB74Z76QZ3ZOY7UTDFYKMEGKW5XFJEB6PFKBF4UYSSWHG4EDH7PY")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

abcdAsset := CreditAsset{"ABCD", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"}
op := PathPaymentStrictSend{
    SendAsset:   NativeAsset{},
    SendAmount:  "1",
    Destination: kp.Address(),
    DestAsset:   NativeAsset{},
    DestMin:     "10",
    Path:        []Asset{abcdAsset},
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAH4RyzTWNfXhqwLUoCw91aWkZtgIzY8SAVkIPc0uFVmYAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAANAAAAAAAAAAAAmJaAAAAAAH4RyzTWNfXhqwLUoCw91aWkZtgIzY8SAVkIPc0uFVmYAAAAAAAAAAAF9eEAAAAAAQAAAAFBQkNEAAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAAAAAAAEuFVmYAAAAQNXoKZHgBO+2baoHMcT1SqpL3lmcggeCm5TuFNk7fwMeF/6h5lDTYMa+y3i9gwwAg8aQwCwuV8A38AWKfPvgMAM=

func (*PathPaymentStrictSend) BuildXDR Uses

func (pp *PathPaymentStrictSend) BuildXDR() (xdr.Operation, error)

BuildXDR for Payment returns a fully configured XDR Operation.

func (*PathPaymentStrictSend) FromXDR Uses

func (pp *PathPaymentStrictSend) FromXDR(xdrOp xdr.Operation) error

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

func (*PathPaymentStrictSend) GetSourceAccount Uses

func (pp *PathPaymentStrictSend) GetSourceAccount() Account

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

func (*PathPaymentStrictSend) Validate Uses

func (pp *PathPaymentStrictSend) Validate() error

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

type Payment Uses

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

Payment represents the Stellar payment operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := Payment{
    Destination: "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z",
    Amount:      "10",
    Asset:       NativeAsset{},
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAABAAAAAITg3tq8G0kvnvoIhZPMYJsY+9KVV8xAA6NxhtKxIXZUAAAAAAAAAAAF9eEAAAAAAAAAAAHqLnLFAAAAQHb8LTro4QVpzcGzOToW28p340o54KX5/xxodABM+izweQlbVKb9bISRUOu+sNfi50weXeAeGVL+oTQS5YR4lgI=

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op1 := Payment{
    Destination: "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z",
    Amount:      "10",
    Asset:       NativeAsset{},
}

op2 := Payment{
    Destination: "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z",
    Amount:      "100",
    Asset:       NativeAsset{},
}

// get fees from network
feeStats, err := client.FeeStats()
check(err)

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op1, &op2},
        BaseFee:              feeStats.MaxFee.P50,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAEsAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAABAAAAAITg3tq8G0kvnvoIhZPMYJsY+9KVV8xAA6NxhtKxIXZUAAAAAAAAAAAF9eEAAAAAAAAAAAEAAAAAhODe2rwbSS+e+giFk8xgmxj70pVXzEADo3GG0rEhdlQAAAAAAAAAADuaygAAAAAAAAAAAeoucsUAAABAyY5c/6T3cQ1i27t681O7aHrdSQ2tCcXpyLj06HVe59DeuHNLgN3X7oBeqBZrgVty+VNVGPEK6uR+UjhGi/bGBA==

func (*Payment) BuildXDR Uses

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

BuildXDR for Payment returns a fully configured XDR Operation.

func (*Payment) FromXDR Uses

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

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

func (*Payment) GetSourceAccount Uses

func (p *Payment) GetSourceAccount() Account

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

func (*Payment) Validate Uses

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 SetOptions Uses

type SetOptions struct {
    InflationDestination *string
    SetFlags             []AccountFlag
    ClearFlags           []AccountFlag
    MasterWeight         *Threshold
    LowThreshold         *Threshold
    MediumThreshold      *Threshold
    HighThreshold        *Threshold
    HomeDomain           *string
    Signer               *Signer

    SourceAccount Account
    // contains filtered or unexported fields
}

SetOptions represents the Stellar set options operation. See https://www.stellar.org/developers/guides/concepts/list-of-operations.html

Code:

kp, _ := keypair.Parse("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R")
client := horizonclient.DefaultTestNetClient
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
check(err)

op := SetOptions{
    InflationDestination: NewInflationDestination("GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z"),
    ClearFlags:           []AccountFlag{AuthRevocable},
    SetFlags:             []AccountFlag{AuthRequired, AuthImmutable},
    MasterWeight:         NewThreshold(10),
    LowThreshold:         NewThreshold(1),
    MediumThreshold:      NewThreshold(2),
    HighThreshold:        NewThreshold(2),
    HomeDomain:           NewHomeDomain("LovelyLumensLookLuminous.com"),
    Signer:               &Signer{Address: "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z", Weight: Threshold(4)},
}

tx, err := NewTransaction(
    TransactionParams{
        SourceAccount:        &sourceAccount,
        IncrementSequenceNum: true,
        Operations:           []Operation{&op},
        BaseFee:              MinBaseFee,
        Timebounds:           NewInfiniteTimeout(), // Use a real timeout in production!
    },
)
check(err)

tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

txe, err := tx.Base64()
check(err)
fmt.Println(txe)

Output:

AAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAZAAMoj8AAAAEAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAFAAAAAQAAAACE4N7avBtJL576CIWTzGCbGPvSlVfMQAOjcYbSsSF2VAAAAAEAAAACAAAAAQAAAAUAAAABAAAACgAAAAEAAAABAAAAAQAAAAIAAAABAAAAAgAAAAEAAAAcTG92ZWx5THVtZW5zTG9va0x1bWlub3VzLmNvbQAAAAEAAAAAhODe2rwbSS+e+giFk8xgmxj70pVXzEADo3GG0rEhdlQAAAAEAAAAAAAAAAHqLnLFAAAAQHGdxG4uiB41Dywb1OiNQwHpCYoNZiaEXTRbPjdRf3SkBCdI1wkBDG6vREDsWfouMks5urKNx0hzg/YMLTa7TwY=

func (*SetOptions) BuildXDR Uses

func (so *SetOptions) BuildXDR() (xdr.Operation, error)

BuildXDR for SetOptions returns a fully configured XDR Operation.

func (*SetOptions) FromXDR Uses

func (so *SetOptions) FromXDR(xdrOp xdr.Operation) error

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

func (*SetOptions) GetSourceAccount Uses

func (so *SetOptions) GetSourceAccount() Account

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

func (*SetOptions) Validate Uses

func (so *SetOptions) Validate() error

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

type Signer Uses

type Signer struct {
    Address string
    Weight  Threshold
}

Signer represents the Signer in a SetOptions operation. If the signer already exists, it is updated. If the weight is 0, the signer is deleted.

type SignerSummary Uses

type SignerSummary map[string]int32

SignerSummary is a map of signers to their weights.

type SimpleAccount Uses

type SimpleAccount struct {
    AccountID string
    Sequence  int64
}

SimpleAccount is a minimal implementation of an Account.

func NewSimpleAccount Uses

func NewSimpleAccount(accountID string, sequence int64) SimpleAccount

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

func (*SimpleAccount) GetAccountID Uses

func (sa *SimpleAccount) GetAccountID() string

GetAccountID returns the Account ID.

func (*SimpleAccount) GetSequenceNumber Uses

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

GetSequenceNumber returns the sequence number of the account.

func (*SimpleAccount) IncrementSequenceNumber Uses

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

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

type Threshold Uses

type Threshold uint8

Threshold is the datatype for MasterWeight, Signer.Weight, and Thresholds. Each is a number between 0-255 inclusive.

func NewThreshold Uses

func NewThreshold(t Threshold) *Threshold

NewThreshold is syntactic sugar that makes instantiating SetOptions more convenient.

type Timebounds Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 specifiy the Timebound you require.

type Transaction Uses

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

Transaction represents a Stellar transaction. See https://www.stellar.org/developers/guides/concepts/transactions.html 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 BuildChallengeTx Uses

func BuildChallengeTx(serverSignerSecret, clientAccountID, anchorName, network string, timebound time.Duration) (*Transaction, error)

BuildChallengeTx is a factory method that creates a valid SEP 10 challenge, for use in web authentication. "timebound" is the time duration the transaction should be valid for, and must be greater than 1s (300s is recommended). More details on SEP 10: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md

Code:

// Generate random nonce
serverSignerSeed := "SBZVMB74Z76QZ3ZOY7UTDFYKMEGKW5XFJEB6PFKBF4UYSSWHG4EDH7PY"
clientAccountID := "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"
anchorName := "SDF"
timebound := time.Duration(5 * time.Minute)

tx, err := BuildChallengeTx(serverSignerSeed, clientAccountID, anchorName, network.TestNetworkPassphrase, timebound)
check(err)

txeBase64, err := tx.Base64()
check(err)
_, err = checkChallengeTx(txeBase64, anchorName)

check(err)

func NewTransaction Uses

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

NewTransaction returns a new Transaction instance

func ReadChallengeTx Uses

func ReadChallengeTx(challengeTx, serverAccountID, network string) (tx *Transaction, clientAccountID string, err error)

ReadChallengeTx reads a SEP 10 challenge transaction and returns the decoded transaction and client account ID contained within.

It also verifies that transaction is signed by the server.

It does not verify that the transaction has been signed by the client or that any signatures other than the servers on the transaction are valid. Use one of the following functions to completely verify the transaction: - VerifyChallengeTxThreshold - VerifyChallengeTxSigners

func (*Transaction) AddSignatureBase64 Uses

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) Base64 Uses

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

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

func (*Transaction) BaseFee Uses

func (t *Transaction) BaseFee() int64

BaseFee returns the per operation fee for this transaction.

func (*Transaction) Hash Uses

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 Uses

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 Uses

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

MarshalBinary returns the binary XDR representation of the transaction envelope.

func (*Transaction) MaxFee Uses

func (t *Transaction) MaxFee() int64

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

func (*Transaction) Memo Uses

func (t *Transaction) Memo() Memo

Memo returns the memo configured for this transaction.

func (*Transaction) Operations Uses

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) Sign Uses

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 Uses

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://www.stellar.org/developers/guides/concepts/multi-sig.html#hashx.

func (*Transaction) SignWithKeyString Uses

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 Uses

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 Uses

func (t *Transaction) SourceAccount() SimpleAccount

SourceAccount returns the account which is originating this account.

func (*Transaction) Timebounds Uses

func (t *Transaction) Timebounds() Timebounds

Timebounds returns the Timebounds configured for this transaction.

func (*Transaction) TxEnvelope Uses

func (t *Transaction) TxEnvelope() (xdr.TransactionEnvelope, error)

TxEnvelope returns the a xdr.TransactionEnvelope instance which is equivalent to this transaction.

type TransactionParams Uses

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

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

type ValidationError Uses

type ValidationError struct {
    Field   string // Field is the struct field on which the validation error occured.
    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 Uses

func NewValidationError(field, message string) *ValidationError

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

func (*ValidationError) Error Uses

func (opError *ValidationError) Error() string

Error for ValidationError struct implements the error interface.

Directories

PathSynopsis
examplehorizonclientPackage examplehorizonclient provides a dummy client for use with the GoDoc examples.

Package txnbuild imports 19 packages (graph) and is imported by 35 packages. Updated 2020-05-21. Refresh now. Tools for package owners.