blockchain.stellar #
requirements
to use this tool you need the stellar command line installed.
fn encode_tx_to_xdr #
fn encode_tx_to_xdr(json_encoding string) !string
fn fetch_highest_bid_price #
fn fetch_highest_bid_price(orderBook OrderBook) Price
fn fetch_lowest_ask_price #
fn fetch_lowest_ask_price(orderBook OrderBook) Price
fn fund_account #
fn fund_account(address string) !
Funds a Stellar account on the test network using Friendbot.
Arguments:- address
(string): The public key of the account to be funded.
Errors:- Returns an error if the funding request fails.
fn generate_keys #
fn generate_keys(args GenerateAccountArgs) !StellarAccountKeys
Generates a new Stellar account and returns the associated keys. This function generates a new Stellar account using the 'stellar keys generate' command. If the 'fund' parameter is true, the account is funded on the network. If the 'cache' parameter is true, the generated keys are cached locally.
Arguments:- args
(CreateAccountArgs): Struct containing account creation parameters.
Returns:- StellarAccountKeys
: Struct with the public and secret keys for the account.
Errors:- Returns an error if key generation fails or cached key removal fails.
fn get_account_keys #
fn get_account_keys(name string) !StellarAccountKeys
fn get_address #
fn get_address(secret string) !string
fn get_client #
fn get_client(config GetStellarClientArgs) !StellarClient
fn get_network_config #
fn get_network_config(network StellarNetwork) !NetworkConfig
fn get_offer_asset_type #
fn get_offer_asset_type(asset_type string, asset_code string, asset_issuer string) OfferAssetType
fn get_offer_id_from_result_xdr #
fn get_offer_id_from_result_xdr(result_xdr string) !MakeOfferResult
fn get_offer_price #
fn get_offer_price(price f32) Price
fn new_asset_type #
fn new_asset_type(code string, issuer string) AssetType
fn new_client #
fn new_client(config NewStellarClientArgs) !StellarClient
fn new_horizon_client #
fn new_horizon_client(network StellarNetwork) !HorizonClient
Todo: this needs to be configured to work on both networks
fn new_signer #
fn new_signer(args NewSignerArgs) TXSigner
adding a new signer
type OfferAssetType #
type OfferAssetType = AssetType | string
enum StellarNetwork #
enum StellarNetwork {
mainnet
testnet
}
struct AddChangeTrustArgs #
struct AddChangeTrustArgs {
pub mut:
asset_code string @[required]
issuer string @[required]
limit u64 = (u64(1) << 63) - 1
source_address ?string
signers []string
}
struct AddSignersArgs #
struct AddSignersArgs {
pub:
source_address ?string
signers_to_add []TXSigner
signers []string
}
struct Asset #
struct Asset {
pub mut:
asset_code string
issuer string
}
struct AssetType #
struct AssetType {
pub mut:
credit_alphanum4 ?Asset
credit_alphanum12 ?Asset
}
struct Balance #
struct Balance {
pub mut:
balance string
limit string
buying_liabilities string
selling_liabilities string
last_modified_ledger int
is_authorized bool
is_authorized_to_maintain_liabilities bool
asset_type string
asset_code string
asset_issuer string
}
struct ChangeTrust #
struct ChangeTrust {
pub mut:
line AssetType
limit ?u64
}
struct Condition #
struct Condition {
pub:
time TimeBounds
}
struct Embedded #
struct Embedded {
pub:
records []TransactionRecord
}
struct Flags #
struct Flags {
pub mut:
auth_required bool
auth_revocable bool
auth_immutable bool
auth_clawback_enabled bool
}
struct GenerateAccountArgs #
struct GenerateAccountArgs {
pub mut:
network StellarNetwork = .testnet // Specifies the Stellar network (testnet or mainnet). Defaults to testnet.
name string @[required] // Name of the account. This is required.
fund bool // Whether to fund the account on the test network after creation.
cache bool // Whether to cache the generated keys locally.
}
Struct to hold arguments for creating a Stellar account.
struct GetOfferArgs #
struct GetOfferArgs {
pub mut:
seller string
limit int = 100
}
struct GetOfferAssetInfo #
struct GetOfferAssetInfo {
pub mut:
asset_type string
asset_code string
asset_issuer string
}
struct GetStellarClientArgs #
struct GetStellarClientArgs {
pub:
network StellarNetwork = .testnet
account_name string
}
struct HorizonClient #
struct HorizonClient {
pub mut:
url string
}
fn (HorizonClient) get_account #
fn (self HorizonClient) get_account(pubkey string) !StellarAccount
fn (HorizonClient) get_last_transaction #
fn (self HorizonClient) get_last_transaction(address string) !TransactionInfo
fn (HorizonClient) get_order_book #
fn (self HorizonClient) get_order_book(order_book_request OrderBookRequest) !OrderBook
Function to get the order book
fn (HorizonClient) get_offers #
fn (self HorizonClient) get_offers(args GetOfferArgs) ![]OfferModel
Function to list offers
struct Link #
struct Link {
pub mut:
href string
templated bool
}
struct Links #
struct Links {
pub mut:
self Link
transactions Link
operations Link
payments Link
effects Link
offers Link
trades Link
data Link
}
struct MakeOfferOpArgs #
struct MakeOfferOpArgs {
offer_id u64
offer OfferArgs
sell bool
buy bool
}
struct MakeOfferResult #
struct MakeOfferResult {
pub mut:
offer_id u64
claimed bool
}
struct MergeArgs #
struct MergeArgs {
pub:
source_account_name ?string
address string
}
pub fn (mut client StellarClient) balance_check(params CheckBalanceParams) !string { asset_id := if params.assetid == '' { client.default_assetid } else { params.assetid } cmd := 'stellar contract invoke --id ${asset_id} --source-account ${params.account_id} --network ${client.network} -- balance --id ${params.account_id} --quiet' result := os.execute(cmd) if result.exit_code != 0 { return error('Failed to check balance: ${result.output}') } return result.output.trim_space() }
struct NetworkConfig #
struct NetworkConfig {
url string
passphrase string
}
struct NewSignerArgs #
struct NewSignerArgs {
pub mut:
key string @[required] // Signer address
weight int = 1 // Weight
}
Struct to hold a transaction signer.
struct NewStellarClientArgs #
struct NewStellarClientArgs {
pub:
network StellarNetwork = .testnet
account_name string
account_secret string @[required]
cache bool = true // If you do not want to cache account keys, set to false. If it is true and you send the same account name twice, the saved keys will be overwritten.
}
struct Offer #
struct Offer {
pub mut:
selling OfferAssetType
buying OfferAssetType
amount ?u64 // stroops
buy_amount ?u64 // stroops
price Price
offer_id u64
}
struct OfferArgs #
struct OfferArgs {
pub mut:
sell bool
buy bool
source_address ?string
selling OfferAssetType
buying OfferAssetType
amount f64 @[required] // in stroops
price f32 @[required] // Price of 1 unit of selling in terms of buying
signers []string
}
struct OfferModel #
struct OfferModel {
pub mut:
id string
paging_token string
seller string
amount string
price string
last_modified_ledger int
last_modified_time string
selling GetOfferAssetInfo
buying GetOfferAssetInfo
}
struct Operation #
struct Operation {
source_address string
threshold ThresholdLevel
}
struct OperationBody #
struct OperationBody {
pub mut:
set_options ?SetOptions
create_account ?TXCreateAccount
payment ?PaymentOptions
change_trust ?ChangeTrust
manage_sell_offer ?Offer
manage_buy_offer ?Offer
}
struct Order #
struct Order {
pub:
price_r Price // Price ratio as returned by Stellar Horizon
price string
amount string
}
struct OrderBook #
struct OrderBook {
// Add fields based on the Horizon API order book response
pub:
bids []Order
asks []Order
}
Struct for the order book response (you'll need to match Horizon API's response format)
struct OrderBookRequest #
struct OrderBookRequest {
pub mut:
selling_asset_type string @[json: 'sellingAssetType']
selling_asset_code string @[json: 'sellingAssetCode']
selling_asset_issuer string @[json: 'sellingAssetIssuer']
buying_asset_type string @[json: 'buyingAssetType']
buying_asset_code string @[json: 'buyingAssetCode']
buying_asset_issuer string @[json: 'buyingAssetIssuer']
limit int
}
Struct for the order book request
struct PaymentOptions #
struct PaymentOptions {
pub mut:
destination string
amount u64
asset OfferAssetType
}
a placeholder.
struct PreConditionTimeBounds #
struct PreConditionTimeBounds {
pub:
min_time string
}
struct Preconditions #
struct Preconditions {
pub:
timebounds PreConditionTimeBounds
}
struct Price #
struct Price {
pub mut:
n int
d int
}
struct RecordLinks #
struct RecordLinks {
pub:
self Link
account Link
ledger Link
operations Link
effects Link
precedes Link
succeeds Link
transaction Link
}
struct RemoveCachedKeysArgs #
struct RemoveCachedKeysArgs {
pub mut:
network StellarNetwork = .testnet // Specifies the Stellar network (testnet or mainnet). Defaults to testnet.
name string @[required] // Name of the account. This is required.
}
Struct to hold arguments for removing cached Stellar keys.
struct RemoveSignerArgs #
struct RemoveSignerArgs {
pub:
source_address ?string
address string
signers []string
}
struct RootLinks #
struct RootLinks {
pub:
self Link
next Link
prev Link
}
struct SendPaymentParams #
struct SendPaymentParams {
pub mut:
asset OfferAssetType = OfferAssetType('native')
destination string @[required]
amount u64 @[required]
source_address ?string // the secret of the source account
signers []string // secret of signers
}
struct SetOptions #
struct SetOptions {
pub mut:
inflation_dest ?string
clear_flags ?int
set_flags ?int
master_weight ?int
low_threshold ?int
med_threshold ?int
high_threshold ?int
home_domain ?string
signer ?TXSigner
}
struct Signer #
struct Signer {
pub mut:
weight int
key string
@type string
}
struct StellarAccount #
struct StellarAccount {
pub mut:
links Links
id string
account_id string
sequence string
sequence_ledger int
sequence_time string
subentry_count int
last_modified_ledger int
last_modified_time string
thresholds Thresholds
flags Flags
balances []Balance
signers []Signer
data map[string]string
num_sponsoring int
num_sponsored int
paging_token string
}
struct StellarAccountKeys #
struct StellarAccountKeys {
pub:
name string
address string
secret string
}
struct StellarClient #
struct StellarClient {
pub mut:
network StellarNetwork
account_name string
account_secret string
account_address string
}
fn (StellarClient) add_signers #
fn (mut client StellarClient) add_signers(args AddSignersArgs) !string
fn (StellarClient) add_trust_line #
fn (mut client StellarClient) add_trust_line(args AddChangeTrustArgs) !string
fn (StellarClient) create_account #
fn (mut client StellarClient) create_account(args StellarCreateAccountArgs) !string
fn (StellarClient) create_offer #
fn (mut client StellarClient) create_offer(args OfferArgs) !MakeOfferResult
fn (StellarClient) default_assetid_get #
fn (mut client StellarClient) default_assetid_get() !string
fn (StellarClient) delete_offer #
fn (mut client StellarClient) delete_offer(offer_id u64, args_ OfferArgs) !
fn (StellarClient) merge_accounts #
fn (mut client StellarClient) merge_accounts(args MergeArgs) !
fn (StellarClient) payment_send #
fn (mut client StellarClient) payment_send(args SendPaymentParams) !string
fn (StellarClient) remove_signer #
fn (mut client StellarClient) remove_signer(args RemoveSignerArgs) !string
fn (StellarClient) update_offer #
fn (mut client StellarClient) update_offer(offer_id u64, args OfferArgs) !
fn (StellarClient) update_threshold #
fn (mut client StellarClient) update_threshold(args UpdateThresholdArgs) !string
struct StellarCreateAccountArgs #
struct StellarCreateAccountArgs {
pub mut:
address string
starting_balance u64
source_address ?string
signers []string
}
struct TXAddSetOptionsOperationArgs #
struct TXAddSetOptionsOperationArgs {
source_account ?string
set_options SetOptions
}
struct TXAddSignerArgs #
struct TXAddSignerArgs {
pub:
source_account ?string
signer TXSigner
}
struct TXCreateAccount #
struct TXCreateAccount {
pub mut:
destination string @[required] // The public key of the account to create
starting_balance u64 @[required] // Use f64 for the raw balance (in this case, 100.0)
}
Struct for the "create_account" request
struct TXSigner #
struct TXSigner {
pub:
key string
weight int = 1
}
struct Thresholds #
struct Thresholds {
pub mut:
low_threshold int
med_threshold int
high_threshold int
}
struct TimeBounds #
struct TimeBounds {
pub:
min_time u64
max_time u64
}
struct Transaction #
struct Transaction {
pub mut:
source_account string
fee int
seq_num u64
cond Condition
memo string = 'none'
operations []TransactionOperation
ext string = 'v0'
}
struct TransactionEnvelope #
struct TransactionEnvelope {
pub mut:
tx Transaction
signatures []string
}
struct TransactionInfo #
struct TransactionInfo {
pub:
links RootLinks @[json: '_links']
embedded Embedded @[json: '_embedded']
}
struct TransactionOperation #
struct TransactionOperation {
pub mut:
source_account ?string
body OperationBody
}
struct TransactionRecord #
struct TransactionRecord {
pub:
links RecordLinks @[json: '_links']
id string
paging_token string
successful bool
hash string
ledger int
created_at string
source_account string
source_account_sequence string
fee_account string
fee_charged string
max_fee string
operation_count int
envelope_xdr string
result_xdr string
fee_meta_xdr string
memo_type string
signatures []string
preconditions Preconditions
}
struct UpdateThresholdArgs #
struct UpdateThresholdArgs {
pub mut:
source_address ?string
low_threshold ?int
med_threshold ?int
high_threshold ?int
signers []string
}
- README
- fn encode_tx_to_xdr
- fn fetch_highest_bid_price
- fn fetch_lowest_ask_price
- fn fund_account
- fn generate_keys
- fn get_account_keys
- fn get_address
- fn get_client
- fn get_network_config
- fn get_offer_asset_type
- fn get_offer_id_from_result_xdr
- fn get_offer_price
- fn new_asset_type
- fn new_client
- fn new_horizon_client
- fn new_signer
- type OfferAssetType
- enum StellarNetwork
- struct AddChangeTrustArgs
- struct AddSignersArgs
- struct Asset
- struct AssetType
- struct Balance
- struct ChangeTrust
- struct Condition
- struct Embedded
- struct Flags
- struct GenerateAccountArgs
- struct GetOfferArgs
- struct GetOfferAssetInfo
- struct GetStellarClientArgs
- struct HorizonClient
- struct Link
- struct Links
- struct MakeOfferOpArgs
- struct MakeOfferResult
- struct MergeArgs
- struct NetworkConfig
- struct NewSignerArgs
- struct NewStellarClientArgs
- struct Offer
- struct OfferArgs
- struct OfferModel
- struct Operation
- struct OperationBody
- struct Order
- struct OrderBook
- struct OrderBookRequest
- struct PaymentOptions
- struct PreConditionTimeBounds
- struct Preconditions
- struct Price
- struct RecordLinks
- struct RemoveCachedKeysArgs
- struct RemoveSignerArgs
- struct RootLinks
- struct SendPaymentParams
- struct SetOptions
- struct Signer
- struct StellarAccount
- struct StellarAccountKeys
- struct StellarClient
- struct StellarCreateAccountArgs
- struct TXAddSetOptionsOperationArgs
- struct TXAddSignerArgs
- struct TXCreateAccount
- struct TXSigner
- struct Thresholds
- struct TimeBounds
- struct Transaction
- struct TransactionEnvelope
- struct TransactionInfo
- struct TransactionOperation
- struct TransactionRecord
- struct UpdateThresholdArgs