txnbuild

package
v0.0.0-...-3a1fdf7 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: Apache-2.0, Apache-2.0 Imports: 19 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/TosinShada/stellar-core/clients/horizonclient"
        "github.com/TosinShada/stellar-core/keypair"
        "github.com/TosinShada/stellar-core/network"
        "github.com/TosinShada/stellar-core/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/TosinShada/stellar-core/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/TosinShada/stellar-core/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/TosinShada/stellar-core/tree/master/clients/horizonclient). Together, these two libraries provide a complete Stellar SDK. For more information and further examples, see https://github.com/TosinShada/stellar-core/blob/master/docs/reference/readme.md

Index

Examples

Constants

AuthClawbackEnabled is a flag that if set allows clawing back assets.

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

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

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

View Source
const LiquidityPoolFeeV18 = xdr.LiquidityPoolFeeV18
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.

TrustLineAuthorized is a flag that indicates whether the trustline is authorized.

View Source
const TrustLineAuthorizedToMaintainLiabilities = TrustLineFlag(xdr.TrustLineFlagsAuthorizedToMaintainLiabilitiesFlag)

TrustLineAuthorizedToMaintainLiabilities is a flag that if set, will allow a trustline to maintain liabilities without permitting any other operations.

TrustLineClawbackEnabled is a flag that if set allows clawing back assets.

Variables

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

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

Functions

func AndPredicate

func AndPredicate(left xdr.ClaimPredicate, right xdr.ClaimPredicate) xdr.ClaimPredicate

AndPredicate returns a xdr.ClaimPredicate

func BeforeAbsoluteTimePredicate

func BeforeAbsoluteTimePredicate(epochSeconds int64) xdr.ClaimPredicate

BeforeAbsoluteTimePredicate returns a Before Absolute Time xdr.ClaimPredicate

This predicate will be fulfilled if the closing time of the ledger that includes the CreateClaimableBalance operation is less than this (absolute) Unix timestamp.

func BeforeRelativeTimePredicate

func BeforeRelativeTimePredicate(secondsBefore int64) xdr.ClaimPredicate

BeforeRelativeTimePredicate returns a Before Relative Time xdr.ClaimPredicate

This predicate will be fulfilled if the closing time of the ledger that includes the CreateClaimableBalance operation plus this relative time delta (in seconds) is less than the current time.

func NewHomeDomain

func NewHomeDomain(hd string) *string

NewHomeDomain is syntactic sugar that makes instantiating SetOptions more convenient.

func NewInflationDestination

func NewInflationDestination(ai string) *string

NewInflationDestination is syntactic sugar that makes instantiating SetOptions more convenient.

func NotPredicate

func NotPredicate(pred xdr.ClaimPredicate) xdr.ClaimPredicate

NotPredicate returns a new predicate inverting the passed in predicate

func OrPredicate

func OrPredicate(left xdr.ClaimPredicate, right xdr.ClaimPredicate) xdr.ClaimPredicate

OrPredicate returns a xdr.ClaimPredicate

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).

func VerifyChallengeTxSigners

func VerifyChallengeTxSigners(challengeTx, serverAccountID, network, webAuthDomain string, homeDomains []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.

The homeDomain field is reserved for future use and not used.

If the challenge contains a subsequent Manage Data operation with key web_auth_domain the value will be checked to match the webAuthDomain provided. If it does not match the function will return an error.

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

func VerifyChallengeTxThreshold(challengeTx, serverAccountID, network, webAuthDomain string, homeDomains []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.

The homeDomain field is reserved for future use and not used.

If the challenge contains a subsequent Manage Data operation with key web_auth_domain the value will be checked to match the webAuthDomain provided. If it does not match the function will return an error.

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.
Example
package main

import (
	"fmt"
	"sort"
	"time"

	"github.com/TosinShada/stellar-core/clients/horizonclient"
	"github.com/TosinShada/stellar-core/keypair"
	"github.com/TosinShada/stellar-core/network"
	"github.com/TosinShada/stellar-core/protocols/horizon"
	"github.com/TosinShada/stellar-core/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(), "webauthdomain.stellar.org", "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, "webauthdomain.stellar.org", []string{"test"})
		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, "webauthdomain.stellar.org", []string{"test"})
		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, "webauthdomain.stellar.org", []string{"test"}, 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, "webauthdomain.stellar.org", []string{"test"}, txClientAccountID)
			if err != nil {
				fmt.Println("Error:", err)
				return
			}
			fmt.Println("Client Master Key Verified:")
			for _, signerFound := range signersFound {
				fmt.Println(signerFound)
			}
		}
	}

}
Output:

Client Signers Verified:
GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP weight: 60
GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 weight: 40

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 AccountFlag

type AccountFlag uint32

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

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/

Example
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAACAAAAACE4N7avBtJL576CIWTzGCbGPvSlVfMQAOjcYbSsSF2VAAAAAAAAAAB6i5yxQAAAEAvOx3WHzmaTsf4rK+yRDsvXn9xh+dU6CkpAum+FCXQ5LZQqhxQg9HErbSfxeTFMdknEpMKXgJRFUfAetl+jf4O

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/

Example
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABwAAAACE4N7avBtJL576CIWTzGCbGPvSlVfMQAOjcYbSsSF2VAAAAAFBQkNEAAAAAQAAAAAAAAAB6i5yxQAAAEAY3MnWiMcL18SxRITSuI5tZSXmEo0Q38UZg0jiJGU2U6kSnsCNTTJiGACGQlIrPfAMYt9koarrX11w7HLBosQN

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 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 BeginSponsoringFutureReserves

type BeginSponsoringFutureReserves struct {
	SponsoredID   string
	SourceAccount string
}

BeginSponsoringFutureReserves represents the Stellar begin sponsoring future reserves operation. See https://developers.stellar.org/docs/start/list-of-operations/

Example
test := InitSponsorshipTestConfig()

asset, err := test.Assets[0].ToChangeTrustAsset()
check(err)

// If the sponsoree submits the transaction, the `SourceAccount` fields can
// be omitted for the "sponsor sandwich" operations.
sponsorTrustline := []Operation{
	&BeginSponsoringFutureReserves{SponsoredID: test.A.Address()},
	&ChangeTrust{
		SourceAccount: test.Aaccount.AccountID,
		Line:          asset,
		Limit:         MaxTrustlineLimit,
	},
	&EndSponsoringFutureReserves{},
}

// The sponsorer obviously must sign the tx, but so does the sponsoree, to
// consent to the sponsored operation.
txb64, err := newSignedTransaction(
	TransactionParams{
		SourceAccount:        &test.Aaccount,
		Operations:           sponsorTrustline,
		Preconditions:        Preconditions{TimeBounds: NewInfiniteTimeout()},
		BaseFee:              MinBaseFee,
		IncrementSequenceNum: true,
	},
	network.TestNetworkPassphrase,
	test.S1,
	test.A,
)
check(err)
fmt.Println(txb64)
Output:

AAAAAgAAAAC0FS8Odh4yFSpaseK1sYMMVdTpVCJmylGJpMeYu9LOKAAAASwAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAEAAAAAC0FS8Odh4yFSpaseK1sYMMVdTpVCJmylGJpMeYu9LOKAAAAAEAAAAAtBUvDnYeMhUqWrHitbGDDFXU6VQiZspRiaTHmLvSzigAAAAGAAAAAUFCQ0QAAAAAfhHLNNY19eGrAtSgLD3VpaRm2AjNjxIBWQg9zS4VWZh//////////wAAAAAAAAARAAAAAAAAAAIuFVmYAAAAQARLe8wjGKq6WwdOPGkw2jo4eltp6dAHXEum4kYKzIjYx9fs4kdNJAaJE0s3Fy6JAIo1ttrGWp8zq6VX6P5CcAW70s4oAAAAQNpzu6NxKgcYd70mJl6EHyRPdjNTfxGm1w4XIIyIfZElRpmuZ6aWpXA0wwS6BimT3UQizK55T1kt1B2Pi3KyPAw=
Example (Transfer)
test := InitSponsorshipTestConfig()

asset, err := test.Assets[1].ToTrustLineAsset()
check(err)

transferOps := []Operation{
	&BeginSponsoringFutureReserves{
		SourceAccount: test.S2account.AccountID,
		SponsoredID:   test.S1.Address(),
	},
	&RevokeSponsorship{
		SponsorshipType: RevokeSponsorshipTypeTrustLine,
		Account:         &test.Aaccount.AccountID,
		TrustLine: &TrustLineID{
			Account: test.A.Address(),
			Asset:   asset,
		},
	},
	&EndSponsoringFutureReserves{},
}

// For transfers, both the old and new sponsor need to sign.
txb64, err := newSignedTransaction(
	TransactionParams{
		SourceAccount:        &test.S1account,
		Operations:           transferOps,
		Preconditions:        Preconditions{TimeBounds: NewInfiniteTimeout()},
		BaseFee:              MinBaseFee,
		IncrementSequenceNum: true,
	},
	network.TestNetworkPassphrase,
	test.S1,
	test.S2,
)
check(err)
fmt.Println(txb64)
Output:

AAAAAgAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAASwAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAABAAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFAAAAEAAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAAAAAAAASAAAAAAAAAAEAAAAAtBUvDnYeMhUqWrHitbGDDFXU6VQiZspRiaTHmLvSzigAAAABRUZHSAAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAAAAAAAARAAAAAAAAAAIuFVmYAAAAQDx6tSWzDT5MCVpolKLvhBwM/PpV9d/Om8PlJ4GZekp+DY6H2XAZ+Rldlfa0DqK8KNuMF921Vha6fpmK7FY4/QrqLnLFAAAAQCxxzLrpHFwd+CS6xmAoytq+ORtrkxUy2k6B7wIuASrlJDnYAHZptf7bBKXPn5ImcpJIcB3E5Xl98s/lEA0+YAA=

func (*BeginSponsoringFutureReserves) BuildXDR

BuildXDR for BeginSponsoringFutureReserves returns a fully configured XDR Operation.

func (*BeginSponsoringFutureReserves) FromXDR

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

FromXDR for BeginSponsoringFutureReserves initializes the txnbuild struct from the corresponding xdr Operation.

func (*BeginSponsoringFutureReserves) GetSourceAccount

func (bs *BeginSponsoringFutureReserves) GetSourceAccount() string

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

func (*BeginSponsoringFutureReserves) Validate

func (bs *BeginSponsoringFutureReserves) Validate() error

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

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/

Example
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAACwAiILoAAABsAAAAAAAAAAHqLnLFAAAAQEIvyOHdPn82ckKXISGF6sR4YU5ox735ivKrC/wS4615j1AA42vbXSLqShJA5/7/DX56UUv+Lt7vlcu9M7jsRw4=

func (*BumpSequence) BuildXDR

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

BuildXDR for BumpSequence returns a fully configured XDR Operation.

func (*BumpSequence) FromXDR

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

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

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.

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

asset, err := CreditAsset{"ABCD", "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z"}.ToChangeTrustAsset()
check(err)

op := ChangeTrust{
	Line:  asset,
	Limit: "10",
}

tx, err := NewTransaction(
	TransactionParams{
		SourceAccount:        &sourceAccount,
		IncrementSequenceNum: true,
		Operations:           []Operation{&op},
		BaseFee:              MinBaseFee,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABgAAAAFBQkNEAAAAAITg3tq8G0kvnvoIhZPMYJsY+9KVV8xAA6NxhtKxIXZUAAAAAAX14QAAAAAAAAAAAeoucsUAAABAqqUuIlFMrlElYnGSLHlaI/A41oGA3rdtc1EHhza9bXk35ZwlEvmsBUOZTasZfgBzwd+CczekWKBCEqBCHzaSBw==
Example (RemoveTrustline)
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"}.MustToChangeTrustAsset())

tx, err := NewTransaction(
	TransactionParams{
		SourceAccount:        &sourceAccount,
		IncrementSequenceNum: true,
		Operations:           []Operation{&op},
		BaseFee:              MinBaseFee,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABgAAAAFBQkNEAAAAAITg3tq8G0kvnvoIhZPMYJsY+9KVV8xAA6NxhtKxIXZUAAAAAAAAAAAAAAAAAAAAAeoucsUAAABAKLmUWcLjxeY+vG8jEXMNprU6EupxbMRiXGYzuKBptnVlbFUtTBqhYa/ibyCZTEVCinT8bWQKDvZI0m6VLKVHAg==

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
	GetLiquidityPoolID() (LiquidityPoolId, bool)
	GetLiquidityPoolParameters() (LiquidityPoolParameters, bool)
	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) GetLiquidityPoolID

func (ctaw ChangeTrustAssetWrapper) GetLiquidityPoolID() (LiquidityPoolId, bool)

GetLiquidityPoolID for ChangeTrustAssetWrapper returns false.

func (ChangeTrustAssetWrapper) GetLiquidityPoolParameters

func (ctaw ChangeTrustAssetWrapper) GetLiquidityPoolParameters() (LiquidityPoolParameters, bool)

GetLiquidityPoolParameters for ChangeTrustAssetWrapper returns false.

func (ChangeTrustAssetWrapper) ToXDR

ToXDR for ChangeTrustAssetWrapper generates the xdr.TrustLineAsset.

type ClaimClaimableBalance

type ClaimClaimableBalance struct {
	BalanceID     string
	SourceAccount string
}

ClaimClaimableBalance represents the Stellar claim claimable balance operation. See https://developers.stellar.org/docs/start/list-of-operations/

Example
A := "SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4"
aKeys := keypair.MustParseFull(A)
aAccount := SimpleAccount{AccountID: aKeys.Address()}

balanceId := "000000000bf0a78c7ca2a980768b66980ba97934f3b3b45a05ce7a5195a44b64b7dedadb"
claimBalance := ClaimClaimableBalance{BalanceID: balanceId}

txb64, err := newSignedTransaction(
	TransactionParams{
		SourceAccount:        &aAccount, // or Account B, depending on the condition!
		IncrementSequenceNum: true,
		BaseFee:              MinBaseFee,
		Preconditions:        Preconditions{TimeBounds: NewInfiniteTimeout()},
		Operations:           []Operation{&claimBalance},
	},
	network.TestNetworkPassphrase,
	aKeys,
)
check(err)
fmt.Println(txb64)
Output:

AAAAAgAAAAC0FS8Odh4yFSpaseK1sYMMVdTpVCJmylGJpMeYu9LOKAAAAGQAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAADwAAAAAL8KeMfKKpgHaLZpgLqXk087O0WgXOelGVpEtkt97a2wAAAAAAAAABu9LOKAAAAEAesnN9L5oVpoZloBoUYfafhhuGSXAsJL2q15zyyWysc7fOADPdiQXQTEuySp12/ciGYWbZhw/fvyzLJlTgqmsI

func (*ClaimClaimableBalance) BuildXDR

func (cb *ClaimClaimableBalance) BuildXDR() (xdr.Operation, error)

BuildXDR for ClaimClaimableBalance returns a fully configured XDR Operation.

func (*ClaimClaimableBalance) FromXDR

func (cb *ClaimClaimableBalance) FromXDR(xdrOp xdr.Operation) error

FromXDR for ClaimClaimableBalance initializes the txnbuild struct from the corresponding xdr Operation.

func (*ClaimClaimableBalance) GetSourceAccount

func (cb *ClaimClaimableBalance) GetSourceAccount() string

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

func (*ClaimClaimableBalance) Validate

func (cb *ClaimClaimableBalance) Validate() error

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

type Claimant

type Claimant struct {
	Destination string
	Predicate   xdr.ClaimPredicate
}

Claimant represents a claimable balance claimant

func NewClaimant

func NewClaimant(destination string, predicate *xdr.ClaimPredicate) Claimant

NewClaimant returns a new Claimant, if predicate is nil then a Claimant with unconditional predicate is returned.

type Clawback

type Clawback struct {
	From          string
	Amount        string
	Asset         Asset
	SourceAccount string
}

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

func (*Clawback) BuildXDR

func (cb *Clawback) BuildXDR() (xdr.Operation, error)

BuildXDR for Clawback returns a fully configured XDR Operation.

func (*Clawback) FromXDR

func (cb *Clawback) FromXDR(xdrOp xdr.Operation) error

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

func (*Clawback) GetSourceAccount

func (cb *Clawback) GetSourceAccount() string

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

func (*Clawback) Validate

func (cb *Clawback) Validate() error

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

type ClawbackClaimableBalance

type ClawbackClaimableBalance struct {
	BalanceID     string
	SourceAccount string
}

ClawbackClaimableBalance represents the Stellar clawback claimable balance operation. See https://developers.stellar.org/docs/start/list-of-operations/

func (*ClawbackClaimableBalance) BuildXDR

func (cb *ClawbackClaimableBalance) BuildXDR() (xdr.Operation, error)

BuildXDR for ClawbackClaimableBalance returns a fully configured XDR Operation.

func (*ClawbackClaimableBalance) FromXDR

func (cb *ClawbackClaimableBalance) FromXDR(xdrOp xdr.Operation) error

FromXDR for ClawbackClaimableBalance initializes the txnbuild struct from the corresponding xdr Operation.

func (*ClawbackClaimableBalance) GetSourceAccount

func (cb *ClawbackClaimableBalance) GetSourceAccount() string

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

func (*ClawbackClaimableBalance) Validate

func (cb *ClawbackClaimableBalance) Validate() error

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

type CreateAccount

type CreateAccount struct {
	Destination   string
	Amount        string
	SourceAccount string
}

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

Example
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAACE4N7avBtJL576CIWTzGCbGPvSlVfMQAOjcYbSsSF2VAAAAAAF9eEAAAAAAAAAAAHqLnLFAAAAQKsrlxt6Ri/WuDGcK1+Tk1hdYHdPeK7KMIds10mcwzw6BpQFZYxP8o6O6ejJFGO06TAGt2PolwuWnpeiVQ9Kcg0=

func (*CreateAccount) BuildXDR

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

BuildXDR for CreateAccount returns a fully configured XDR Operation.

func (*CreateAccount) FromXDR

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

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

func (*CreateAccount) GetSourceAccount

func (ca *CreateAccount) GetSourceAccount() string

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

func (*CreateAccount) Validate

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 CreateClaimableBalance

type CreateClaimableBalance struct {
	Amount        string
	Asset         Asset
	Destinations  []Claimant
	SourceAccount string
}

CreateClaimableBalance represents the Stellar create claimable balance operation. See https://developers.stellar.org/docs/start/list-of-operations/

Example
A := "SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4"
B := "GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5"

aKeys := keypair.MustParseFull(A)
aAccount := SimpleAccount{AccountID: aKeys.Address()}

soon := time.Now().Add(time.Second * 60)
bCanClaim := BeforeRelativeTimePredicate(60)
aCanReclaim := NotPredicate(BeforeAbsoluteTimePredicate(soon.Unix()))

claimants := []Claimant{
	NewClaimant(B, &bCanClaim),
	NewClaimant(aKeys.Address(), &aCanReclaim),
}

claimableBalanceEntry := CreateClaimableBalance{
	Destinations: claimants,
	Asset:        NativeAsset{},
	Amount:       "420",
}

// Build and sign the transaction
tx, err := NewTransaction(
	TransactionParams{
		SourceAccount:        &aAccount,
		IncrementSequenceNum: true,
		BaseFee:              MinBaseFee,
		Preconditions:        Preconditions{TimeBounds: NewInfiniteTimeout()},
		Operations:           []Operation{&claimableBalanceEntry},
	},
)
check(err)
tx, err = tx.Sign(network.TestNetworkPassphrase, aKeys)
check(err)

balanceId, err := tx.ClaimableBalanceID(0)
check(err)
fmt.Println(balanceId)
Output:

000000000bf0a78c7ca2a980768b66980ba97934f3b3b45a05ce7a5195a44b64b7dedadb

func (*CreateClaimableBalance) BuildXDR

func (cb *CreateClaimableBalance) BuildXDR() (xdr.Operation, error)

BuildXDR for CreateClaimableBalance returns a fully configured XDR Operation.

func (*CreateClaimableBalance) FromXDR

func (cb *CreateClaimableBalance) FromXDR(xdrOp xdr.Operation) error

FromXDR for CreateClaimableBalance initializes the txnbuild struct from the corresponding xdr Operation.

func (*CreateClaimableBalance) GetSourceAccount

func (cb *CreateClaimableBalance) GetSourceAccount() string

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

func (*CreateClaimableBalance) Validate

func (cb *CreateClaimableBalance) Validate() error

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

type CreatePassiveSellOffer

type CreatePassiveSellOffer struct {
	Selling       Asset
	Buying        Asset
	Amount        string
	Price         xdr.Price
	SourceAccount string
}

CreatePassiveSellOffer represents the Stellar create passive offer operation. See https://developers.stellar.org/docs/start/list-of-operations/

Example
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:   xdr.Price{1, 1},
}

tx, err := NewTransaction(
	TransactionParams{
		SourceAccount:        &sourceAccount,
		IncrementSequenceNum: true,
		Operations:           []Operation{&op},
		BaseFee:              MinBaseFee,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABAAAAAAAAAABQUJDRAAAAAAlyvHaD8duz+iEXkJUUbsHkklIlH46oMrMMYrt0odkfgAAAAAF9eEAAAAAAQAAAAEAAAAAAAAAAeoucsUAAABAE4XbLdDVz1MwC9Bs84nkqK8hyHheVbYznNSiAP0hiP8auvcKAMnYz3HJvzM8H0q/K5MPvgBaehHZ/tQtaPSGBg==

func (*CreatePassiveSellOffer) BuildXDR

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

BuildXDR for CreatePassiveSellOffer returns a fully configured XDR Operation.

func (*CreatePassiveSellOffer) FromXDR

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

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

func (*CreatePassiveSellOffer) GetSourceAccount

func (cpo *CreatePassiveSellOffer) GetSourceAccount() string

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

func (*CreatePassiveSellOffer) Validate

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

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 DataID

type DataID struct {
	Account  string
	DataName string
}

type EndSponsoringFutureReserves

type EndSponsoringFutureReserves struct {
	SourceAccount string
}

EndSponsoringFutureReserves represents the Stellar begin sponsoring future reserves operation. See https://developers.stellar.org/docs/start/list-of-operations/

func (*EndSponsoringFutureReserves) BuildXDR

func (es *EndSponsoringFutureReserves) BuildXDR() (xdr.Operation, error)

BuildXDR for EndSponsoringFutureReserves returns a fully configured XDR Operation.

func (*EndSponsoringFutureReserves) FromXDR

func (es *EndSponsoringFutureReserves) FromXDR(xdrOp xdr.Operation) error

FromXDR for EndSponsoringFutureReserves initializes the txnbuild struct from the corresponding xdr Operation.

func (*EndSponsoringFutureReserves) GetSourceAccount

func (es *EndSponsoringFutureReserves) GetSourceAccount() string

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

func (*EndSponsoringFutureReserves) Validate

func (es *EndSponsoringFutureReserves) Validate() error

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

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.

Example
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,
		Preconditions:        Preconditions{TimeBounds: NewInfiniteTimeout()}, // Use a real timeout in production!
	},
)
check(err)
tx, err = tx.Sign(network.TestNetworkPassphrase, kp.(*keypair.Full))
check(err)

feeBumpKP, _ := keypair.Parse("SBZVMB74Z76QZ3ZOY7UTDFYKMEGKW5XFJEB6PFKBF4UYSSWHG4EDH7PY")
feeBumpTx, err := NewFeeBumpTransaction(
	FeeBumpTransactionParams{
		Inner:      tx,
		FeeAccount: feeBumpKP.Address(),
		BaseFee:    MinBaseFee,
	},
)
check(err)
feeBumpTx, err = feeBumpTx.Sign(network.TestNetworkPassphrase, feeBumpKP.(*keypair.Full))
check(err)

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

AAAABQAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAAAAAAADIAAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAACwAiILoAAABsAAAAAAAAAAHqLnLFAAAAQEIvyOHdPn82ckKXISGF6sR4YU5ox735ivKrC/wS4615j1AA42vbXSLqShJA5/7/DX56UUv+Lt7vlcu9M7jsRw4AAAAAAAAAAS4VWZgAAABAeD0gL6WpzSdGTzWd4c9yUu3r+W21hOTLT4ItHGBTHYPT20Wk3dytuqfP89EzlkZXvtG8/N0HH4w+oJCLOL/5Aw==

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/

Example
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAACQAAAAAAAAAB6i5yxQAAAED9zR1l78yiBwd/o44RyE3XP7QT57VmI90qE46TjfncYyqlOaIRWpkh3qouTjV5IRPVGo6+bFWV40H1HE087FgA

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 LiquidityPoolDeposit

type LiquidityPoolDeposit struct {
	SourceAccount   string
	LiquidityPoolID LiquidityPoolId
	MaxAmountA      string
	MaxAmountB      string
	MinPrice        xdr.Price
	MaxPrice        xdr.Price
}

LiquidityPoolDeposit represents the Stellar liquidity pool deposit operation. See https://developers.stellar.org/docs/start/list-of-operations/

Example
test := InitLiquidityPoolTestConfig()

poolId, err := NewLiquidityPoolId(test.Assets[0], test.Assets[1])
check(err)

depositOps := []Operation{
	// Change of trust the first time ensures that the pool exists.
	&ChangeTrust{
		Line: LiquidityPoolShareChangeTrustAsset{
			LiquidityPoolParameters: LiquidityPoolParameters{
				AssetA: test.Assets[0],
				AssetB: test.Assets[1],
				Fee:    LiquidityPoolFeeV18,
			},
		},
		SourceAccount: test.AAccount.AccountID,
		Limit:         MaxTrustlineLimit,
	},

	// Add our deposit to the pool
	&LiquidityPoolDeposit{
		SourceAccount:   test.A.Address(),
		LiquidityPoolID: poolId,
		MaxAmountA:      "0.1000000",
		MaxAmountB:      "0.1000000",
		MinPrice:        price.MustParse("0.1000000"),
		MaxPrice:        price.MustParse("0.1000000"),
	},
}

// With revocation, only the new sponsor needs to sign.
txb64, err := newSignedTransaction(
	TransactionParams{
		SourceAccount:        &test.AAccount,
		Operations:           depositOps,
		Preconditions:        Preconditions{TimeBounds: NewInfiniteTimeout()},
		BaseFee:              MinBaseFee,
		IncrementSequenceNum: true,
	},
	network.TestNetworkPassphrase,
	test.A,
)
check(err)
fmt.Println(txb64)
Output:

AAAAAgAAAAC0FS8Odh4yFSpaseK1sYMMVdTpVCJmylGJpMeYu9LOKAAAAMgAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAABAAAAALQVLw52HjIVKlqx4rWxgwxV1OlUImbKUYmkx5i70s4oAAAABgAAAAMAAAAAAAAAAUFCQ0QAAAAAtBUvDnYeMhUqWrHitbGDDFXU6VQiZspRiaTHmLvSzigAAAABRUZHSAAAAAC0FS8Odh4yFSpaseK1sYMMVdTpVCJmylGJpMeYu9LOKAAAAB5//////////wAAAAEAAAAAtBUvDnYeMhUqWrHitbGDDFXU6VQiZspRiaTHmLvSzigAAAAWeDFASRchw0mM6/TK0AbZw13MsKye384/nzGgEZhWzzsAAAAAAA9CQAAAAAAAD0JAAAAAAQAAAAoAAAABAAAACgAAAAAAAAABu9LOKAAAAECsEeCUf0w62cgGpgaZxR2cb47Ln3jvfUOvTXl2sJkmEM3CIHIZzkFkMz7RZCRGn70DUjl5TXeow0zxipPL1K0H

func NewLiquidityPoolDeposit

func NewLiquidityPoolDeposit(
	sourceAccount string,
	a, b AssetAmount,
	minPrice,
	maxPrice xdr.Price,
) (LiquidityPoolDeposit, error)

NewLiquidityPoolDeposit creates a new LiquidityPoolDeposit operation, checking the ordering assets so we generate the correct pool id. minPrice, and maxPrice are in terms of a/b. Each AssetAmount is a pair of the asset with the maximum amount of that asset to deposit.

func (*LiquidityPoolDeposit) BuildXDR

func (lpd *LiquidityPoolDeposit) BuildXDR() (xdr.Operation, error)

BuildXDR for LiquidityPoolDeposit returns a fully configured XDR Operation.

func (*LiquidityPoolDeposit) FromXDR

func (lpd *LiquidityPoolDeposit) FromXDR(xdrOp xdr.Operation) error

FromXDR for LiquidityPoolDeposit initializes the txnbuild struct from the corresponding xdr Operation.

func (*LiquidityPoolDeposit) GetSourceAccount

func (lpd *LiquidityPoolDeposit) GetSourceAccount() string

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

func (*LiquidityPoolDeposit) Validate

func (lpd *LiquidityPoolDeposit) Validate() error

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

type LiquidityPoolId

type LiquidityPoolId [32]byte

LiquidityPoolId represents the Stellar liquidity pool id.

func NewLiquidityPoolId

func NewLiquidityPoolId(a, b Asset) (LiquidityPoolId, error)

func (LiquidityPoolId) ToXDR

func (lpi LiquidityPoolId) ToXDR() (xdr.PoolId, error)

type LiquidityPoolParameters

type LiquidityPoolParameters struct {
	AssetA Asset
	AssetB Asset
	Fee    int32
}

LiquidityPoolParameters represents the Stellar liquidity pool parameters

func (LiquidityPoolParameters) ToXDR

type LiquidityPoolShareChangeTrustAsset

type LiquidityPoolShareChangeTrustAsset struct {
	LiquidityPoolParameters LiquidityPoolParameters
}

LiquidityPoolShareChangeTrustAsset represents non-XLM assets on the Stellar network.

func (LiquidityPoolShareChangeTrustAsset) GetCode

GetCode for LiquidityPoolShareChangeTrustAsset returns blank string

func (LiquidityPoolShareChangeTrustAsset) GetIssuer

func (lpsa LiquidityPoolShareChangeTrustAsset) GetIssuer() string

GetIssuer for LiquidityPoolShareChangeTrustAsset returns blank string

func (LiquidityPoolShareChangeTrustAsset) GetLiquidityPoolID

func (lpsa LiquidityPoolShareChangeTrustAsset) GetLiquidityPoolID() (LiquidityPoolId, bool)

GetLiquidityPoolID for LiquidityPoolShareChangeTrustAsset returns the pool id computed from the parameters.

func (LiquidityPoolShareChangeTrustAsset) GetLiquidityPoolParameters

func (lpsa LiquidityPoolShareChangeTrustAsset) GetLiquidityPoolParameters() (LiquidityPoolParameters, bool)

GetLiquidityPoolParameters for LiquidityPoolShareChangeTrustAsset returns the pool parameters.

func (LiquidityPoolShareChangeTrustAsset) GetType

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

func (LiquidityPoolShareChangeTrustAsset) IsNative

func (lpsa LiquidityPoolShareChangeTrustAsset) IsNative() bool

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

func (LiquidityPoolShareChangeTrustAsset) MustToAsset

func (lpsa LiquidityPoolShareChangeTrustAsset) MustToAsset() Asset

MustToAsset for LiquidityPoolShareChangeTrustAsset panics.

func (LiquidityPoolShareChangeTrustAsset) MustToChangeTrustAsset

func (lpsa LiquidityPoolShareChangeTrustAsset) MustToChangeTrustAsset() ChangeTrustAsset

MustToChangeTrustAsset for LiquidityPoolShareChangeTrustAsset returns itself unchanged.

func (LiquidityPoolShareChangeTrustAsset) MustToTrustLineAsset

func (lpsa LiquidityPoolShareChangeTrustAsset) MustToTrustLineAsset() TrustLineAsset

MustToTrustLineAsset for LiquidityPoolShareChangeTrustAsset hashes the pool parameters to get the pool id, and converts this to a TrustLineAsset. It panics on failure.

func (LiquidityPoolShareChangeTrustAsset) ToAsset

ToAsset for LiquidityPoolShareChangeTrustAsset returns an error.

func (LiquidityPoolShareChangeTrustAsset) ToChangeTrustAsset

func (lpsa LiquidityPoolShareChangeTrustAsset) ToChangeTrustAsset() (ChangeTrustAsset, error)

ToChangeTrustAsset for LiquidityPoolShareChangeTrustAsset returns itself unchanged.

func (LiquidityPoolShareChangeTrustAsset) ToTrustLineAsset

func (lpsa LiquidityPoolShareChangeTrustAsset) ToTrustLineAsset() (TrustLineAsset, error)

ToTrustLineAsset for LiquidityPoolShareChangeTrustAsset hashes the pool parameters to get the pool id, and converts this to a TrustLineAsset.

func (LiquidityPoolShareChangeTrustAsset) ToXDR

ToXDR for LiquidityPoolShareChangeTrustAsset produces a corresponding XDR change trust asset.

type LiquidityPoolShareTrustLineAsset

type LiquidityPoolShareTrustLineAsset struct {
	LiquidityPoolID LiquidityPoolId
}

LiquidityPoolShareTrustLineAsset represents shares in a liquidity pool on the Stellar network.

func (LiquidityPoolShareTrustLineAsset) GetCode

GetCode for LiquidityPoolShareAsset returns blank string

func (LiquidityPoolShareTrustLineAsset) GetIssuer

func (lpsa LiquidityPoolShareTrustLineAsset) GetIssuer() string

GetIssuer for LiquidityPoolShareAsset returns blank string

func (LiquidityPoolShareTrustLineAsset) GetLiquidityPoolID

func (lpsa LiquidityPoolShareTrustLineAsset) GetLiquidityPoolID() (LiquidityPoolId, bool)

GetLiquidityPoolID for LiquidityPoolShareTrustLineAsset returns the pool id.

func (LiquidityPoolShareTrustLineAsset) GetType

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

func (LiquidityPoolShareTrustLineAsset) IsNative

func (lpsa LiquidityPoolShareTrustLineAsset) IsNative() bool

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

func (LiquidityPoolShareTrustLineAsset) MustToAsset

func (lpsa LiquidityPoolShareTrustLineAsset) MustToAsset() Asset

MustToAsset for LiquidityPoolShareTrustLineAsset panics.

func (LiquidityPoolShareTrustLineAsset) MustToChangeTrustAsset

func (lpsa LiquidityPoolShareTrustLineAsset) MustToChangeTrustAsset() ChangeTrustAsset

MustToChangeTrustAsset for LiquidityPoolShareTrustLineAsset panics.

func (LiquidityPoolShareTrustLineAsset) MustToTrustLineAsset

func (lpsa LiquidityPoolShareTrustLineAsset) MustToTrustLineAsset() TrustLineAsset

MustToTrustLineAsset for LiquidityPoolShareTrustLineAsset returns itself unchanged.

func (LiquidityPoolShareTrustLineAsset) ToAsset

func (lpsa LiquidityPoolShareTrustLineAsset) ToAsset() (Asset, error)

ToAsset for LiquidityPoolShareTrustLineAsset returns an error.

func (LiquidityPoolShareTrustLineAsset) ToChangeTrustAsset

func (lpsa LiquidityPoolShareTrustLineAsset) ToChangeTrustAsset() (ChangeTrustAsset, error)

ToChangeTrustAsset for LiquidityPoolShareTrustLineAsset returns an error.

func (LiquidityPoolShareTrustLineAsset) ToTrustLineAsset

func (lpsa LiquidityPoolShareTrustLineAsset) ToTrustLineAsset() (TrustLineAsset, error)

ToTrustLineAsset for LiquidityPoolShareTrustLineAsset returns itself unchanged.

func (LiquidityPoolShareTrustLineAsset) ToXDR

ToXDR for LiquidityPoolShareAsset produces a corresponding XDR asset.

type LiquidityPoolWithdraw

type LiquidityPoolWithdraw struct {
	SourceAccount   string
	LiquidityPoolID LiquidityPoolId
	Amount          string
	MinAmountA      string
	MinAmountB      string
}

LiquidityPoolWithdraw represents the Stellar liquidity pool withdraw operation. See https://developers.stellar.org/docs/start/list-of-operations/

Example
test := InitLiquidityPoolTestConfig()

poolId, err := NewLiquidityPoolId(test.Assets[0], test.Assets[1])
check(err)

withdrawOps := []Operation{
	&LiquidityPoolWithdraw{
		SourceAccount:   test.A.Address(),
		LiquidityPoolID: poolId,
		Amount:          "0.1000000",
		MinAmountA:      "0.1000000",
		MinAmountB:      "0.1000000",
	},
}

// With revocation, only the new sponsor needs to sign.
txb64, err := newSignedTransaction(
	TransactionParams{
		SourceAccount:        &test.AAccount,
		Operations:           withdrawOps,
		Preconditions:        Preconditions{TimeBounds: NewInfiniteTimeout()},
		BaseFee:              MinBaseFee,
		IncrementSequenceNum: true,
	},
	network.TestNetworkPassphrase,
	test.A,
)
check(err)
fmt.Println(txb64)
Output:

AAAAAgAAAAC0FS8Odh4yFSpaseK1sYMMVdTpVCJmylGJpMeYu9LOKAAAAGQAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAALQVLw52HjIVKlqx4rWxgwxV1OlUImbKUYmkx5i70s4oAAAAF3gxQEkXIcNJjOv0ytAG2cNdzLCsnt/OP58xoBGYVs87AAAAAAAPQkAAAAAAAA9CQAAAAAAAD0JAAAAAAAAAAAG70s4oAAAAQHc2K5XVrm6+ICFt3xOrJFbXZXV4jhCZ2kruYJnJ/JJatgRZerVjiCp6BI37hcrd9CM3yTnb8McOSNXHmtgEMQM=

func NewLiquidityPoolWithdraw

func NewLiquidityPoolWithdraw(
	sourceAccount string,
	a, b AssetAmount,
	amount string,
) (LiquidityPoolWithdraw, error)

NewLiquidityPoolWithdraw creates a new LiquidityPoolWithdraw operation, checking the ordering assets so we generate the correct pool id. Each AssetAmount is a pair of the asset with the minimum amount of that asset to withdraw.

func (*LiquidityPoolWithdraw) BuildXDR

func (lpd *LiquidityPoolWithdraw) BuildXDR() (xdr.Operation, error)

BuildXDR for LiquidityPoolWithdraw returns a fully configured XDR Operation.

func (*LiquidityPoolWithdraw) FromXDR

func (lpd *LiquidityPoolWithdraw) FromXDR(xdrOp xdr.Operation) error

FromXDR for LiquidityPoolWithdraw initializes the txnbuild struct from the corresponding xdr Operation.

func (*LiquidityPoolWithdraw) GetSourceAccount

func (lpd *LiquidityPoolWithdraw) GetSourceAccount() string

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

func (*LiquidityPoolWithdraw) Validate

func (lpd *LiquidityPoolWithdraw) Validate() error

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

type ManageBuyOffer

type ManageBuyOffer struct {
	Selling       Asset
	Buying        Asset
	Amount        string
	Price         xdr.Price
	OfferID       int64
	SourceAccount string
}

ManageBuyOffer represents the Stellar manage buy offer operation. See https://developers.stellar.org/docs/start/list-of-operations/

Example
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:   price.MustParse("0.01"),
	OfferID: 0,
}

tx, err := NewTransaction(
	TransactionParams{
		SourceAccount:        &sourceAccount,
		IncrementSequenceNum: true,
		Operations:           []Operation{&buyOffer},
		BaseFee:              MinBaseFee,
		Preconditions:        Preconditions{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:

AAAAAgAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAADAAAAAAAAAABQUJDRAAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAAA7msoAAAAAAQAAAGQAAAAAAAAAAAAAAAAAAAABLhVZmAAAAED4fIdU68w6XIMwf1RPFdF9qRRlfPycrmK8dCOW0XwSbiya9JfMi9YrD9cGY7zHV+3zYpLcEi7lLo++PZ1gOsAK

func (*ManageBuyOffer) BuildXDR

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

BuildXDR for ManageBuyOffer returns a fully configured XDR Operation.

func (*ManageBuyOffer) FromXDR

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

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

func (*ManageBuyOffer) GetSourceAccount

func (mo *ManageBuyOffer) GetSourceAccount() string

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

func (*ManageBuyOffer) Validate

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

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

ManageData represents the Stellar manage data operation. See https://developers.stellar.org/docs/start/list-of-operations/

Example
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAACgAAABBGcnVpdCBwcmVmZXJlbmNlAAAAAQAAAAVBcHBsZQAAAAAAAAAAAAAB6i5yxQAAAEDtRCyQRKKgQ8iLEu7kicHtSzoplfxPtPTMhdRv/sq8UoIBVTxIw+S13Jv+jzs3tyLDLiGCVNXreUNlbfX+980K
Example (RemoveDataEntry)
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAACgAAABBGcnVpdCBwcmVmZXJlbmNlAAAAAAAAAAAAAAAB6i5yxQAAAEDFpI1vphzG8Dny4aVDA7tyOlP579d9kWO0U/vmq6pWTrNocd6+xTiU753W50ksEscA6f1WNwUsQf+DCwmZfqIA

func (*ManageData) BuildXDR

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

BuildXDR for ManageData returns a fully configured XDR Operation.

func (*ManageData) FromXDR

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

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

func (*ManageData) GetSourceAccount

func (md *ManageData) GetSourceAccount() string

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

func (*ManageData) Validate

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

type ManageSellOffer struct {
	Selling       Asset
	Buying        Asset
	Amount        string
	Price         xdr.Price
	OfferID       int64
	SourceAccount string
}

ManageSellOffer represents the Stellar manage offer operation. See https://developers.stellar.org/docs/start/list-of-operations/

Example
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"
op, err := CreateOfferOp(selling, buying, sellAmount, price.MustParse("0.01"))
check(err)

tx, err := NewTransaction(
	TransactionParams{
		SourceAccount:        &sourceAccount,
		IncrementSequenceNum: true,
		Operations:           []Operation{&op},
		BaseFee:              MinBaseFee,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAAAAAABQUJDRAAAAAAlyvHaD8duz+iEXkJUUbsHkklIlH46oMrMMYrt0odkfgAAAAA7msoAAAAAAQAAAGQAAAAAAAAAAAAAAAAAAAAB6i5yxQAAAEBtfrN+VUE7iCwBk0+rmg0/Ua4DItMWEy6naGWxoDBi4ksCIJSZPzkv79Q65rIaFyIcC/zuyJcnIcv73AP+HQEK
Example (DeleteOffer)
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAAAAAABRkFLRQAAAABBB4BkxJWGYvNgJBoiXUo2tjgWlNmhHMMKdwGN7RSdsQAAAAAAAAAAAAAAAQAAAAEAAAAAACyUlgAAAAAAAAAB6i5yxQAAAEBnE+oILauqt6m8fj7DIBNW/XBmKJ34SLvHdxP04vb26aI8q9i/2p9/pJMnWPeOoIw0f6jreR306qPJFhjMtl4G
Example (UpdateOffer)
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"
offerID := int64(2497628)
op, err := UpdateOfferOp(selling, buying, sellAmount, price.MustParse("0.02"), offerID)
check(err)

tx, err := NewTransaction(
	TransactionParams{
		SourceAccount:        &sourceAccount,
		IncrementSequenceNum: true,
		Operations:           []Operation{&op},
		BaseFee:              MinBaseFee,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAwAAAAAAAAABQUJDRAAAAAAlyvHaD8duz+iEXkJUUbsHkklIlH46oMrMMYrt0odkfgAAAAAdzWUAAAAAAQAAADIAAAAAACYcXAAAAAAAAAAB6i5yxQAAAECmO+4yukAuLRtR4IRWPVtoyZ2LJeaipPuec+/M1JGDoTFPULDl3kgugPwV3mr0jvMNArBdR8S3NUw31gtT5TcO

func CreateOfferOp

func CreateOfferOp(selling, buying Asset, amount string, price xdr.Price, sourceAccount ...string) (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

func DeleteOfferOp(offerID int64, sourceAccount ...string) (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

func UpdateOfferOp(selling, buying Asset, amount string, price xdr.Price, offerID int64, sourceAccount ...string) (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

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

BuildXDR for ManageSellOffer returns a fully configured XDR Operation.

func (*ManageSellOffer) FromXDR

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

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

func (*ManageSellOffer) GetSourceAccount

func (mo *ManageSellOffer) GetSourceAccount() string

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

func (*ManageSellOffer) Validate

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

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 OfferID

type OfferID struct {
	SellerAccountAddress string
	OfferID              int64
}

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 PathPayment

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.

Example
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAgAAAAAAAAAABfXhAAAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAAAAAAAAAAJiWgAAAAAEAAAABQUJDRAAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAAAAAAABLhVZmAAAAEDhhPsNm7yKfCUCDyBV1pOZDu+3DVDpT2cJSLQOVevP6pmU2yVqvMKnWbYxC5GbTXEEF+MfBE6EoW5+Z4rRt0QO

type PathPaymentStrictReceive

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

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

Example
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAgAAAAAAAAAABfXhAAAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAAAAAAAAAAJiWgAAAAAEAAAABQUJDRAAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAAAAAAABLhVZmAAAAEDhhPsNm7yKfCUCDyBV1pOZDu+3DVDpT2cJSLQOVevP6pmU2yVqvMKnWbYxC5GbTXEEF+MfBE6EoW5+Z4rRt0QO

func (*PathPaymentStrictReceive) BuildXDR

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

BuildXDR for PathPaymentStrictReceive returns a fully configured XDR Operation.

func (*PathPaymentStrictReceive) FromXDR

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

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

func (*PathPaymentStrictReceive) GetSourceAccount

func (pp *PathPaymentStrictReceive) GetSourceAccount() string

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

func (*PathPaymentStrictReceive) Validate

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

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

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

Example
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAADQAAAAAAAAAAAJiWgAAAAAB+Ecs01jX14asC1KAsPdWlpGbYCM2PEgFZCD3NLhVZmAAAAAAAAAAABfXhAAAAAAEAAAABQUJDRAAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAAAAAAABLhVZmAAAAEDV6CmR4ATvtm2qBzHE9UqqS95ZnIIHgpuU7hTZO38DHhf+oeZQ02DGvst4vYMMAIPGkMAsLlfAN/AFinz74DAD

func (*PathPaymentStrictSend) BuildXDR

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

BuildXDR for Payment returns a fully configured XDR Operation.

func (*PathPaymentStrictSend) FromXDR

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

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

func (*PathPaymentStrictSend) GetSourceAccount

func (pp *PathPaymentStrictSend) GetSourceAccount() string

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

func (*PathPaymentStrictSend) Validate

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

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/

Example
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAACE4N7avBtJL576CIWTzGCbGPvSlVfMQAOjcYbSsSF2VAAAAAAAAAAABfXhAAAAAAAAAAAB6i5yxQAAAEB2/C066OEFac3Bszk6FtvKd+NKOeCl+f8caHQATPos8HkJW1Sm/WyEkVDrvrDX4udMHl3gHhlS/qE0EuWEeJYC
Example (SetBaseFee)
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAABLAADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAQAAAACE4N7avBtJL576CIWTzGCbGPvSlVfMQAOjcYbSsSF2VAAAAAAAAAAABfXhAAAAAAAAAAABAAAAAITg3tq8G0kvnvoIhZPMYJsY+9KVV8xAA6NxhtKxIXZUAAAAAAAAAAA7msoAAAAAAAAAAAHqLnLFAAAAQMmOXP+k93ENYtu7evNTu2h63UkNrQnF6ci49Oh1XufQ3rhzS4Dd1+6AXqgWa4FbcvlTVRjxCurkflI4Rov2xgQ=

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 RevokeSponsorship

type RevokeSponsorship struct {
	SourceAccount   string
	SponsorshipType RevokeSponsorshipType
	// Account ID (strkey)
	Account   *string
	TrustLine *TrustLineID
	Offer     *OfferID
	Data      *DataID
	// Claimable Balance ID
	ClaimableBalance *string
	Signer           *SignerID
}

RevokeSponsorship is a union type representing a RevokeSponsorship Operation. SponsorshipType stablishes which sponsorship is being revoked. The other fields should be ignored.

Example
test := InitSponsorshipTestConfig()

asset1, err := test.Assets[1].ToTrustLineAsset()
check(err)

asset2, err := test.Assets[2].ToTrustLineAsset()
check(err)

revokeOps := []Operation{
	&RevokeSponsorship{
		SponsorshipType: RevokeSponsorshipTypeTrustLine,
		Account:         &test.Aaccount.AccountID,
		TrustLine: &TrustLineID{
			Account: test.A.Address(),
			Asset:   asset1,
		},
	},
	&RevokeSponsorship{
		SponsorshipType: RevokeSponsorshipTypeTrustLine,
		Account:         &test.Aaccount.AccountID,
		TrustLine: &TrustLineID{
			Account: test.A.Address(),
			Asset:   asset2,
		},
	},
}

// With revocation, only the new sponsor needs to sign.
txb64, err := newSignedTransaction(
	TransactionParams{
		SourceAccount:        &test.S2account,
		Operations:           revokeOps,
		Preconditions:        Preconditions{TimeBounds: NewInfiniteTimeout()},
		BaseFee:              MinBaseFee,
		IncrementSequenceNum: true,
	},
	network.TestNetworkPassphrase,
	test.S2,
)
check(err)
fmt.Println(txb64)
Output:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAMgAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAEgAAAAAAAAABAAAAALQVLw52HjIVKlqx4rWxgwxV1OlUImbKUYmkx5i70s4oAAAAAUVGR0gAAAAAfhHLNNY19eGrAtSgLD3VpaRm2AjNjxIBWQg9zS4VWZgAAAAAAAAAEgAAAAAAAAABAAAAALQVLw52HjIVKlqx4rWxgwxV1OlUImbKUYmkx5i70s4oAAAAAUlKS0wAAAAA4Nxt4XJcrGZRYrUvrOc1sooiQ+QdEk1suS1wo+oucsUAAAAAAAAAAeoucsUAAABA9YO+xRc5Vb8ueP1U8go7ka+u/gZJd2z075c2pdFxYb+4AvQUQGvg+N4wvtNll43lPwXq5XAz74BfP99wugplDQ==

func (*RevokeSponsorship) BuildXDR

func (r *RevokeSponsorship) BuildXDR() (xdr.Operation, error)

func (*RevokeSponsorship) FromXDR

func (r *RevokeSponsorship) FromXDR(xdrOp xdr.Operation) error

func (*RevokeSponsorship) GetSourceAccount

func (r *RevokeSponsorship) GetSourceAccount() string

func (*RevokeSponsorship) Validate

func (r *RevokeSponsorship) Validate() error

type RevokeSponsorshipType

type RevokeSponsorshipType int
const (
	RevokeSponsorshipTypeAccount RevokeSponsorshipType = iota + 1
	RevokeSponsorshipTypeTrustLine
	RevokeSponsorshipTypeOffer
	RevokeSponsorshipTypeData
	RevokeSponsorshipTypeClaimableBalance
	RevokeSponsorshipTypeSigner
)

type SetOptions

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

	SourceAccount string
	// contains filtered or unexported fields
}

SetOptions represents the Stellar set options operation. See https://developers.stellar.org/docs/start/list-of-operations/

Example
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,
		Preconditions:        Preconditions{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:

AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQADKI/AAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABQAAAAEAAAAAhODe2rwbSS+e+giFk8xgmxj70pVXzEADo3GG0rEhdlQAAAABAAAAAgAAAAEAAAAFAAAAAQAAAAoAAAABAAAAAQAAAAEAAAACAAAAAQAAAAIAAAABAAAAHExvdmVseUx1bWVuc0xvb2tMdW1pbm91cy5jb20AAAABAAAAAITg3tq8G0kvnvoIhZPMYJsY+9KVV8xAA6NxhtKxIXZUAAAABAAAAAAAAAAB6i5yxQAAAEBxncRuLogeNQ8sG9TojUMB6QmKDWYmhF00Wz43UX90pAQnSNcJAQxur0RA7Fn6LjJLObqyjcdIc4P2DC02u08G

func (*SetOptions) BuildXDR

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

BuildXDR for SetOptions returns a fully configured XDR Operation.

func (*SetOptions) FromXDR

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

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

func (*SetOptions) GetSourceAccount

func (so *SetOptions) GetSourceAccount() string

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

func (*SetOptions) Validate

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 SetTrustLineFlags

type SetTrustLineFlags struct {
	Trustor       string
	Asset         Asset
	SetFlags      []TrustLineFlag
	ClearFlags    []TrustLineFlag
	SourceAccount string
}

SetTrustLineFlags represents the Stellar set trust line flags operation. See https://developers.stellar.org/docs/start/list-of-operations/

func (*SetTrustLineFlags) BuildXDR

func (stf *SetTrustLineFlags) BuildXDR() (xdr.Operation, error)

BuildXDR for SetTrustLineFlags returns a fully configured XDR Operation.

func (*SetTrustLineFlags) FromXDR

func (stf *SetTrustLineFlags) FromXDR(xdrOp xdr.Operation) error

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

func (*SetTrustLineFlags) GetSourceAccount

func (stf *SetTrustLineFlags) GetSourceAccount() string

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

func (*SetTrustLineFlags) Validate

func (stf *SetTrustLineFlags) Validate() error

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

type Signer

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 SignerID

type SignerID struct {
	AccountID     string
	SignerAddress string
}

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 Threshold

type Threshold uint8

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

func NewThreshold

func NewThreshold(t Threshold) *Threshold

NewThreshold is syntactic sugar that makes instantiating SetOptions more convenient.

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 BuildChallengeTx

func BuildChallengeTx(serverSignerSecret, clientAccountID, webAuthDomain, homeDomain, 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

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

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

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

fmt.Println(ok)
Output:

true

func NewTransaction

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

NewTransaction returns a new Transaction instance

func ReadChallengeTx

func ReadChallengeTx(challengeTx, serverAccountID, network, webAuthDomain string, homeDomains []string) (tx *Transaction, clientAccountID string, matchedHomeDomain string, err error)

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

Before calling this function, retrieve the SIGNING_KEY included in the TOML file hosted on the service's homeDomain and ensure it matches the serverAccountID you intend to pass.

This function verifies the serverAccountID signed the challenge. If the serverAccountID also matches the SIGNING_KEY included in the TOML file hosted the service's homeDomain passed, malicious web services will not be able to use the challenge transaction POSTed back to the authentication endpoint.

The challenge's first Manage Data operation is expected to contain the homeDomain parameter passed to the function.

If the challenge contains a subsequent Manage Data operation with key web_auth_domain the value will be checked to match the webAuthDomain provided. If it does not match the function will return an error.

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

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) ClaimableBalanceID

func (t *Transaction) ClaimableBalanceID(operationIndex int) (string, error)

ClaimableBalanceID returns the claimable balance ID for the operation at the given index within the transaction. given index (which should be a `CreateClaimableBalance` operation).

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
	GetLiquidityPoolID() (LiquidityPoolId, bool)
	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) GetLiquidityPoolID

func (tlaw TrustLineAssetWrapper) GetLiquidityPoolID() (LiquidityPoolId, bool)

GetLiquidityPoolID for TrustLineAssetWrapper returns false.

func (TrustLineAssetWrapper) ToXDR

ToXDR for TrustLineAssetWrapper generates the xdr.TrustLineAsset.

type TrustLineFlag

type TrustLineFlag uint32

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

type TrustLineID

type TrustLineID struct {
	Account string
	Asset   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.

Directories

Path Synopsis
cmd
demo
Demo is an interactive demonstration of the Go SDK using the Stellar TestNet.
Demo is an interactive demonstration of the Go SDK using the Stellar TestNet.
demo/operations
Package demo is an interactive demonstration of the Go SDK using the Stellar TestNet.
Package demo is an interactive demonstration of the Go SDK using the Stellar TestNet.
Package examplehorizonclient provides a dummy client for use with the GoDoc examples.
Package examplehorizonclient provides a dummy client for use with the GoDoc examples.

Jump to

Keyboard shortcuts

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