internal

package
v0.0.0-...-292effe Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAccountExists error = errors.New(fmt.Sprintf("createAccountAlreadyExist (%s)", createAccountAlreadyExistXDR))
View Source
var ErrAccountFunded error = errors.New("account already funded to starting balance")

Functions

func CheckAccountExists

func CheckAccountExists(ctx context.Context, minion *Minion, networkClient NetworkClient, address string) (bool, string, error)

CheckAccountExists checks if the specified address exists as a Stellar account. And returns the current native balance of the account also. This should also be passed to the minion.

func CheckSequenceRefresh

func CheckSequenceRefresh(ctx context.Context, minion *Minion, networkClient NetworkClient) error

CheckSequenceRefresh establishes the minion's initial sequence number, if needed. This should also be passed to the minion.

Types

type Account

type Account struct {
	AccountID string
	Sequence  int64
}

Account implements the `txnbuild.Account` interface.

func (Account) GetAccountID

func (a Account) GetAccountID() string

GetAccountID returns the Account ID.

func (Account) GetSequenceNumber

func (a Account) GetSequenceNumber() (int64, error)

func (Account) IncrementSequenceNumber

func (a Account) IncrementSequenceNumber() (int64, error)

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

func (*Account) RefreshSequenceNumber

func (a *Account) RefreshSequenceNumber(ctx context.Context, networkClient NetworkClient) error

RefreshSequenceNumber gets an Account's correct in-memory sequence number from the network.

type AccountDetails

type AccountDetails struct {
	Sequence int64
	Balance  string
}

AccountDetails contains the minimal information needed about an account.

type Bot

type Bot struct {
	Minions               []Minion
	NetworkClient         NetworkClient
	FundContractAddresses bool
	// contains filtered or unexported fields
}

Bot represents the friendbot subsystem and primarily delegates work to its Minions.

func (*Bot) Pay

func (bot *Bot) Pay(ctx context.Context, destAddress string) (*TransactionResult, error)

Pay funds the account at `destAddress`.

func (*Bot) SupportsContractAddresses

func (bot *Bot) SupportsContractAddresses() bool

SupportsContractAddresses returns true if the bot is configured to fund contract addresses (C addresses) and the network client supports it.

type FriendbotHandler

type FriendbotHandler struct {
	Friendbot *Bot
	// contains filtered or unexported fields
}

FriendbotHandler causes an account at `Address` to be created.

func NewFriendbotHandler

func NewFriendbotHandler(fb *Bot) *FriendbotHandler

NewFriendbotHandler returns friendbot handler based on the tracing enabled

func (*FriendbotHandler) Handle

func (handler *FriendbotHandler) Handle(w http.ResponseWriter, r *http.Request)

Handle is a method that implements http.HandlerFunc

type Minion

type Minion struct {
	Account         Account
	Keypair         *keypair.Full
	BotAccount      txnbuild.Account
	BotKeypair      *keypair.Full
	NetworkClient   NetworkClient
	Network         string
	StartingBalance string
	BaseFee         int64

	// Mockable functions
	SubmitTransaction    func(ctx context.Context, minion *Minion, networkClient NetworkClient, txHash [32]byte, tx string) (*TransactionResult, error)
	CheckSequenceRefresh func(ctx context.Context, minion *Minion, networkClient NetworkClient) error
	CheckAccountExists   func(ctx context.Context, minion *Minion, networkClient NetworkClient, destAddress string) (bool, string, error)
	// contains filtered or unexported fields
}

Minion contains a Stellar channel account and Go channels to communicate with friendbot.

func (*Minion) Run

func (minion *Minion) Run(ctx context.Context, destAddress string, resultChan chan SubmitResult)

Run reads a payment destination address and an output channel. It attempts to pay that address and submits the result to the channel.

type NetworkClient

type NetworkClient interface {
	// SubmitTransaction submits a transaction and blocks until it can return a result.
	SubmitTransaction(ctx context.Context, txXDR string) error

	// GetAccountDetails retrieves account information for the given account ID.
	GetAccountDetails(ctx context.Context, accountID string) (*AccountDetails, error)

	// SimulateTransaction simulates a transaction and returns the result.
	// This is required for Soroban transactions to get resource fees and auth entries.
	// For network clients that don't support simulation (like Horizon), this returns an error.
	SimulateTransaction(ctx context.Context, txXDR string) (*SimulateTransactionResult, error)

	// SupportsContractAddresses returns true if this network client can fund
	// contract addresses (C addresses). RPC supports this, Horizon does not.
	SupportsContractAddresses() bool
}

NetworkClient defines a general interface for interacting with Stellar network services. It abstracts the functionality needed for friendbot operations, allowing different implementations (Horizon, RPC, etc.) to be used interchangeably.

type NetworkError

type NetworkError interface {
	error
	// IsNotFound returns true if the error indicates the requested resource was not found.
	IsNotFound() bool
	// IsBadSequence returns true if the error indicates a bad sequence number.
	IsBadSequence() bool
	// IsTimeout returns true if the error indicates a timeout occurred.
	IsTimeout() bool
	// ResultString returns the result string from the error, if available.
	ResultString() (string, error)
	// DiagnosticEventStrings returns the diagnostic event XDR strings from the error, if available.
	DiagnosticEventStrings() []string
}

NetworkError represents a network operation error with abstracted checking methods.

type SimulateTransactionResult

type SimulateTransactionResult struct {
	// TransactionDataXDR is the SorobanTransactionData XDR in base64.
	TransactionDataXDR string
	// ResultXDR is the ScVal XDR return value from simulation in base64.
	ResultXDR string
}

SimulateTransactionResult contains the result of simulating a transaction.

type SubmitResult

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

SubmitResult is the result from the asynchronous tx submission.

type TransactionResult

type TransactionResult struct {
	Successful  bool   `json:"successful"`
	Hash        string `json:"hash"`
	EnvelopeXdr string `json:"envelope_xdr"`
}

TransactionResult contains the final transaction result returned to callers.

func SubmitTransaction

func SubmitTransaction(ctx context.Context, minion *Minion, networkClient NetworkClient, txHash [32]byte, tx string) (*TransactionResult, error)

SubmitTransaction should be passed to the Minion.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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