### Verifying Horizon Binary Installation Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md A simple command to execute the newly built `stellar-horizon` binary with the `--help` flag, confirming that the build and installation were successful by displaying the command-line options. ```bash stellar-horizon --help ``` -------------------------------- ### Start Horizon Docker (Testnet) Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Runs the start.sh script to build Horizon and start Docker containers for Horizon, Postgres, and optionally Core on the Stellar test network. This is the default behavior if no parameter is supplied. ```Bash ./services/horizon/docker/start.sh testnet ``` -------------------------------- ### Building Stellar Horizon Binary Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Provides the necessary bash commands to navigate to the Horizon service directory, compile the Go binary, install it, and add the resulting executable to the system's PATH for convenient access. ```bash cd go/services/horizon/ go build -o stellar-horizon && go install export PATH=$PATH:{absolute-path-to-horizon-folder} ``` -------------------------------- ### Start Horizon Docker (Standalone) Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Runs the start.sh script to build Horizon and start Docker containers for Horizon, Postgres, and Core on a private standalone Stellar network. This is useful for quickly spinning up services. ```Bash ./services/horizon/docker/start.sh standalone ``` -------------------------------- ### Start Horizon Docker (Pubnet) Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Runs the start.sh script to build Horizon and start Docker containers for Horizon, Postgres, and optionally Core on the Stellar public network. This is useful for quickly spinning up services. ```Bash ./services/horizon/docker/start.sh pubnet ``` -------------------------------- ### Install and View Help for regulated-assets-approval-server Source: https://github.com/stellar/go/blob/master/services/regulated-assets-approval-server/README.md Instructions to install the regulated-assets-approval-server Go program and view its main help message, listing available commands. ```shell $ go install $ regulated-assets-approval-server --help SEP-8 Approval Server Usage: regulated-assets-approval-server [command] [flags] regulated-assets-approval-server [command] Available Commands: configure-issuer Configure the Asset Issuer Account for SEP-8 Regulated Assets migrate Run migrations on the database serve Serve the SEP-8 Approval Server Use "regulated-assets-approval-server [command] --help" for more information about a command. ``` -------------------------------- ### Installing the ALB Replayer Tool Source: https://github.com/stellar/go/blob/master/tools/alb-replay/README.md Command to compile and install the `alb-replay` binary using the Go toolchain. This requires a Go development environment to be set up. ```bash go install ./tools/alb-replay ``` -------------------------------- ### Install Keystored Command (Shell) Source: https://github.com/stellar/go/blob/master/services/keystore/cmd/keystored/README.md Installs the `keystored` executable command-line tool by navigating to the keystore service directory and using the Go build tools. ```Shell cd github.com/stellar/go/exp/services/keystore go install ./cmd/keystored ``` -------------------------------- ### Install horizon-cmp Tool (Go) Source: https://github.com/stellar/go/blob/master/tools/horizon-cmp/README.md This command compiles and installs the `horizon-cmp` binary from the source code located in the `./tools/horizon-cmp` directory of the Stellar Go repository. ```bash go install ./tools/horizon-cmp ``` -------------------------------- ### Start Horizon Postgres Docker Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Starts the Horizon Postgres database as a Docker container using the specified docker-compose file. The database will be accessible on port 5432. ```Bash docker-compose -f ./services/horizon/docker/docker-compose.yml up -d horizon-postgres ``` -------------------------------- ### Configure VS Code Debugger for Horizon Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Example VS Code launch configuration for debugging the local Horizon process. It sets environment variables required for database connection, migrations, network selection, and rate limiting. ```JSON { "name": "Horizon Debugger", "type": "go", "request": "launch", "mode": "debug", "program": "${workspaceRoot}/services/horizon/main.go", "env": { "DATABASE_URL": "postgres://postgres@localhost:5432/horizon?sslmode=disable", "APPLY_MIGRATIONS": "true", "NETWORK": "testnet", "PER_HOUR_RATE_LIMIT": "0" }, "args": [] } ``` -------------------------------- ### Specifying Stellar Core Version Overrides Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Environment variables used to override the default Stellar Protocol, Core Docker image, and Stellar Core version when starting the network via the `start.sh` script. Includes an example command demonstrating how to apply these overrides. ```bash export PROTOCOL_VERSION="21" export CORE_IMAGE="stellar/stellar-core:21" export STELLAR_CORE_VERSION="21.3.1-2007.4ede19620.focal" # Example command using overrides: PROTOCOL_VERSION=21 CORE_IMAGE=stellar/stellar-core:21 STELLAR_CORE_VERSION=21.3.1-2007.4ede19620.focal ./start.sh [standalone|pubnet] ``` -------------------------------- ### Basic Logging Calls in Go Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Demonstrates simple logging statements using `log.Info` for basic messages and `log.Infof` for formatted strings, assuming the `go/support/log` package is imported. ```go log.Info("my log line") log.Infof("I take a %s", "format string") ``` -------------------------------- ### Starting State Ingestion Logs Source: https://github.com/stellar/go/blob/master/services/horizon/internal/ingest/TESTING.md These log messages indicate the beginning of the state ingestion process, either from an empty state or by reading from a History Archive Snapshot. ```Log INFO[2019-08-29T13:04:13.473+02:00] Starting ingestion system from empty state... pid=5965 service=ingest temp_set="*io.MemoryTempSet" INFO[2019-08-29T13:04:15.263+02:00] Reading from History Archive Snapshot ledger=25565887 pid=5965 service=ingest ``` -------------------------------- ### Example JSON Response for Market Data Source: https://github.com/stellar/go/blob/master/services/ticker/docs/API.md An example of the JSON response returned by the GET /markets.json endpoint, showing the structure and data provided for multiple trade pairs, including 24h and 7-day statistics. ```json { "generated_at": 1556828634778, "generated_at_rfc3339": "2019-05-02T17:23:54-03:00", "pairs": [ { "name": "ABDT_DOP", "base_volume": 27933.1306978, "counter_volume": 703779.0492835, "trade_count": 73, "open": 0.03987601218950153, "low": 0.038593480963638155, "high": 0.03989875591737053, "change": -0.0011995715564988227, "base_volume_7d": 199598.77306629982, "counter_volume_7d": 5004887.537185903, "trade_count_7d": 488, "open_7d": 0.03988668687332845, "low_7d": 0.038593480963638155, "high_7d": 0.04145936964569084, "change_7d": -0.0012102462403257436, "price": 0.038676440633002705, "close": 0.038676440633002705, "close_time": "2019-05-02T12:23:57-03:00", "bid_count": 200, "bid_volume": 229694.35403809912, "bid_max": 25.8555333333, "ask_count": 36, "ask_volume": 149041.62309569685, "ask_min": 25.902828723, "spread": 0.0018258774053509135, "spread_mid_point": 25.856446272002675 }, { "name": "BTC_CNY", "base_volume": 0.0737282, "counter_volume": 2686.9835871000005, "trade_count": 49, "open": 0.0000276, "low": 0.0000269, "high": 0.0000278, "change": -3.9999999999999956e-7, "base_volume_7d": 0.37105660000000024, "counter_volume_7d": 13616.162691900003, "trade_count_7d": 285, "open_7d": 0.0000264, "low_7d": 0.0000263, "high_7d": 0.000028, "change_7d": 7.999999999999991e-7, "price": 0.0000272, "close": 0.0000272, "close_time": "2019-05-02T12:48:41-03:00", "bid_count": 27, "bid_volume": 22126.4118872, "bid_max": 36630.03663003663, "ask_count": 21, "ask_volume": 4438.404611090742, "ask_min": 36900.36900369004, "spread": 0.007326007326007345, "spread_mid_point": 36630.04029304029 } ] } ``` -------------------------------- ### Define and Prepare Ledger Range - Stellar Ingestion - Go Source: https://github.com/stellar/go/blob/master/ingest/README.md Specifies the starting ledger sequence (excluding genesis) and the total number of ledgers to process. Constructs a bounded ledger range object. Calls the backend's `PrepareRange` method to make the specified ledger range available for reading, which might take time depending on the backend and range size. ```Go // Prepare a range to be ingested: var startingSeq uint32 = 2 // can't start with genesis ledger var ledgersToRead uint32 = 10000 fmt.Printf("Preparing range (%d ledgers)...\n", ledgersToRead) ledgerRange := backends.BoundedRange(startingSeq, startingSeq+ledgersToRead) err = backend.PrepareRange(ctx, ledgerRange) panicIf(err) ``` -------------------------------- ### Iterate Ledgers and Create Transaction Reader - Stellar Ingestion - Go Source: https://github.com/stellar/go/blob/master/ingest/README.md Initializes counters for successful/failed transactions and operations. Starts a loop iterating from the starting ledger sequence up to the end of the defined range. Inside the loop, it prints the current ledger being processed and creates a `LedgerTransactionReader` for the current sequence using the backend and network passphrase. Defers closing the reader. ```Go // These are the statistics that we're tracking. var successfulTransactions, failedTransactions int var operationsInSuccessful, operationsInFailed int for seq := startingSeq; seq <= startingSeq+ledgersToRead; seq++ { fmt.Printf("Processed ledger %d...\r", seq) txReader, err := ingest.NewLedgerTransactionReader( ctx, backend, config.NetworkPassphrase, seq, ) panicIf(err) defer txReader.Close() ``` -------------------------------- ### Installing stellar-archivist with Go Source: https://github.com/stellar/go/blob/master/tools/stellar-archivist/README.md Command to install the stellar-archivist tool using the Go package manager. This requires a Go environment to be set up on your system. ```Shell go install github.com/stellar/go/tools/stellar-archivist ``` -------------------------------- ### Install stellar-sign Utility (Go) Source: https://github.com/stellar/go/blob/master/tools/stellar-sign/README.md Installs the `stellar-sign` command-line utility using the Go package manager. This command fetches the latest version from the specified GitHub repository. ```bash $ go get -u github.com/stellar/go/tools/stellar-sign ``` -------------------------------- ### Create and Fund Stellar TestNet Account (Go) Source: https://github.com/stellar/go/blob/master/docs/reference/examples.md This Go code snippet demonstrates the process of creating and funding accounts on the Stellar TestNet. It generates a new keypair, uses the friendbot service to fund the initial account, retrieves the account details, generates a second keypair, constructs a 'CreateAccount' operation, builds and signs a transaction containing this operation, and finally submits the transaction to the Horizon server. ```go package main import ( "log" "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/keypair" "github.com/stellar/go/network" "github.com/stellar/go/txnbuild" ) func main() { // Generate a new randomly generated address pair, err := keypair.Random() if err != nil { log.Fatal(err) } log.Println("Seed 0:", pair.Seed()) log.Println("Address 0:", pair.Address()) // Create and fund the address on TestNet, using friendbot client := horizonclient.DefaultTestNetClient client.Fund(pair.Address()) // Get information about the account we just created accountRequest := horizonclient.AccountRequest{AccountID: pair.Address()} hAccount0, err := client.AccountDetail(accountRequest) if err != nil { log.Fatal(err) } // Generate a second randomly generated address kp1, err := keypair.Random() if err != nil { log.Fatal(err) } log.Println("Seed 1:", kp1.Seed()) log.Println("Address 1:", kp1.Address()) // Construct the operation createAccountOp := txnbuild.CreateAccount{ Destination: kp1.Address(), Amount: "10", } // Construct the transaction that will carry the operation txParams := txnbuild.TransactionParams{ SourceAccount: &hAccount0, IncrementSequenceNum: true, Operations: []txnbuild.Operation{&createAccountOp}, Timebounds: txnbuild.NewTimeout(300), BaseFee: 100, } tx, _ := txnbuild.NewTransaction(txParams) // Sign the transaction, and base 64 encode its XDR representation signedTx, _ := tx.Sign(network.TestNetworkPassphrase, pair) txeBase64, _ := signedTx.Base64() log.Println("Transaction base64: ", txeBase64) // Submit the transaction resp, err := client.SubmitTransactionXDR(txeBase64) if err != nil { hError := err.(*horizonclient.Error) log.Fatal("Error submitting transaction:", hError.Problem) } log.Println("\nTransaction response: ", resp) } ``` -------------------------------- ### Run Market Tracker Executable (Shell) Source: https://github.com/stellar/go/blob/master/exp/services/market-tracker/README.md Execute the compiled market tracker application. This will start the service, which will begin monitoring asset pairs and serving metrics. ```Shell ./market-tracker ``` -------------------------------- ### Building the Federation Service (Go) Source: https://github.com/stellar/go/blob/master/services/federation/README.md Go command to fetch and build the Stellar federation service source code from the GitHub repository, assuming Go tools are installed and configured. ```Go go get -u github.com/stellar/go/services/federation ``` -------------------------------- ### Example Output of Captive Stellar-Core Ingestion (Shell) Source: https://github.com/stellar/go/blob/master/ingest/README.md This snippet displays the console output generated when running the Go program that uses the Captive Stellar-Core backend. It includes various log messages from `stellar-core` related to configuration loading, database initialization, history archive catchup, bucket downloading and applying, and ultimately the program's output showing the ingested ledger sequence. ```Shell $ go run ./example.go INFO[...] default: Config from /tmp/captive-stellar-core365405852/stellar-core.conf pid=20574 INFO[...] default: RUN_STANDALONE enabled in configuration file - node will not function properly with most networks pid=20574 INFO[...] default: Generated QUORUM_SET: { pid=20574 INFO[...] "t" : 2, pid=20574 INFO[...] "v" : [ "sdf_testnet_2", "sdf_testnet_3", "sdf_testnet_1" ] pid=20574 INFO[...] } pid=20574 INFO[...] default: Assigning calculated value of 1 to FAILURE_SAFETY pid=20574 INFO[...] Database: Connecting to: sqlite3://:memory: pid=20574 INFO[...] SCP: LocalNode::LocalNode@GCVAA qSet: 59d361 pid=20574 INFO[...] default: * pid=20574 INFO[...] default: * The database has been initialized pid=20574 INFO[...] default: * pid=20574 INFO[...] Database: Applying DB schema upgrade to version 13 pid=20574 INFO[...] Database: Adding column 'ledgerext' to table 'accounts' pid=20574 ... INFO[...] Ledger: Established genesis ledger, closing pid=20574 INFO[...] Ledger: Root account seed: SDHOAMBNLGCE2MV5ZKIVZAQD3VCLGP53P3OBSBI6UN5L5XZI5TKHFQL4 pid=20574 INFO[...] default: * pid=20574 INFO[...] default: * The next launch will catchup from the network afresh. pid=20574 INFO[...] default: * pid=20574 INFO[...] default: Application destructing pid=20574 INFO[...] default: Application destroyed pid=20574 ... INFO[...] History: Starting catchup with configuration: pid=20574 INFO[...] lastClosedLedger: 1 pid=20574 INFO[...] toLedger: 123457 pid=20574 INFO[...] count: 2 pid=20574 INFO[...] History: Catching up to ledger 123457: Downloading state file history/00/01/e2/history-0001e27f.json for ledger 123519 pid=20574 ... INFO[...] History: Catching up to ledger 123457: downloading and verifying buckets: 16/17 (94%) pid=20574 INFO[...] History: Verifying bucket d4db982884941c0b82422996e26ae0778b4a85385ef657ffacee9b11adf72882 pid=20574 INFO[...] History: Catching up to ledger 123457: Succeeded: download-verify-buckets : 17/17 children completed pid=20574 INFO[...] History: Applying buckets pid=20574 INFO[...] History: Catching up to ledger 123457: Applying buckets 0%. Currently on level 9 pid=20574 ... INFO[...] Bucket: Bucket-apply: 158366 entries in 17.12MB/17.12MB in 17/17 files (100%) pid=20574 INFO[...] History: Catching up to ledger 123457: Applying buckets 100%. Currently on level 0 pid=20574 INFO[...] History: ApplyBuckets : done, restarting merges pid=20574 INFO[...] History: Catching up to ledger 123457: Succeeded: download-verify-apply-buckets pid=20574 ``` -------------------------------- ### Getting Horizon CLI Help (Go) Source: https://github.com/stellar/go/blob/master/services/horizon/CHANGELOG.md Explains how to view available commands and parameters for the Horizon CLI tool by running the help command. ```Shell horizon help ``` -------------------------------- ### Example Usage of ALB Replayer Source: https://github.com/stellar/go/blob/master/tools/alb-replay/README.md Demonstrates how to run the `alb-replay` tool with specific parameters, including setting the number of workers, providing the log file path, and specifying the target URL. Sample output lines show replayed requests with their timing. ```bash alb-replay --workers 100 746476062914_elasticloadbalancing_us-east-1_app.stellar002-prd-horizon2.d65c0ca4271aa022_20210628T0000Z_54.208.185.115_567ts68u.log https://horizon.stellar.org 2021/08/04 16:36:13 (4) 506.607706ms https://horizon.stellar.org/ledgers?limit=1&order=desc&c=0.344613637344948 2021/08/04 16:36:13 (1) 517.0601ms https://horizon.stellar.org/ 2021/08/04 16:36:13 (5) 518.765858ms https://horizon.stellar.org/trades?cursor=155070734820388867-0&X-Client-Name=js-stellar-sdk&X-Client-Version=7.0.0 2021/08/04 16:36:13 (10) 518.778775ms https://horizon.stellar.org/offers?seller=GDYYFHJ34WSXDSNTPGQMS3NIS6PJR5WPZKSVZPADAR43RKDHZRIU7A5V 2021/08/04 16:36:13 (3) 519.966962ms https://horizon.stellar.org/order_book?selling_asset_type=credit_alphanum12&selling_asset_code=DOGET&selling_asset_issuer=GDOEVDDBU6OBWKL7VHDAOKD77UP4DKHQYKOKJJT5PR3WRDBTX35HUEUX&buying_asset_type=native&X-Client-Name=js-stellar-sdk&X-Client-Version=8.0.0 2021/08/04 16:36:13 (2) 520.147353ms https://horizon.stellar.org/accounts/GDNXSZSF7HIGVRL2LG6VWXN5PWV3KHI77DQTHLLPKNPLUZFKRRDQJBXP?c=0.020849836853811032 2021/08/04 16:36:13 (6) 520.645528ms https://horizon.stellar.org/trades?base_asset_type=native&counter_asset_type=credit_alphanum12&counter_asset_code=DOGET&counter_asset_issuer=GDOEVDDBU6OBWKL7VHDAOKD77UP4DKHQYKOKJJT5PR3WRDBTX35HUEUX&limit=50&order=desc&c=0.433731649711667 2021/08/04 16:36:13 (8) 523.850289ms https://horizon.stellar.org/order_book?selling_asset_type=native&buying_asset_type=credit_alphanum12&buying_asset_code=Falcon9&buying_asset_issuer=GCHG35QMNQ6MOZEIQNHKGABUWOEVF7STLOBYEPQXARI7QAIV6ZVVPNKQ&limit=200&c=0.7329191653797233 [...] ``` -------------------------------- ### Displaying Main webauth Commands (Shell) Source: https://github.com/stellar/go/blob/master/exp/services/webauth/README.md Shows the top-level usage of the `webauth` command-line tool, listing available subcommands like `genjwk` and `serve`. It also provides instructions for getting more detailed help on specific commands. ```Shell $ webauth --help ``` -------------------------------- ### State Completion and Ledger Ingestion Logs Source: https://github.com/stellar/go/blob/master/services/horizon/internal/ingest/TESTING.md These logs show the completion of state ingestion for a ledger, followed by the start and processing of subsequent ledgers using the ledger pipeline. ```Log INFO[2019-08-29T13:39:41.590+02:00] Processing entries from History Archive Snapshot ledger=25565887 numEntries=5300000 pid=5965 service=ingest INFO[2019-08-29T13:39:44.518+02:00] Processing entries from History Archive Snapshot ledger=25565887 numEntries=5400000 pid=5965 service=ingest INFO[2019-08-29T13:39:47.488+02:00] Processing entries from History Archive Snapshot ledger=25565887 numEntries=5500000 pid=5965 service=ingest INFO[2019-08-29T13:40:00.670+02:00] Processed ledger ledger=25565887 pid=5965 service=ingest type=state_pipeline INFO[2019-08-29T13:40:00.670+02:00] Finished processing History Archive Snapshot duration=2145.337575904 ledger=25565887 numEntries=5529931 pid=5965 service=ingest shutdown=false INFO[2019-08-29T13:40:00.693+02:00] Reading new ledger ledger=25565888 pid=5965 service=ingest INFO[2019-08-29T13:40:00.694+02:00] Processing ledger ledger=25565888 pid=5965 service=ingest type=ledger_pipeline updating_database=true INFO[2019-08-29T13:40:00.779+02:00] Processed ledger ledger=25565888 pid=5965 service=ingest type=ledger_pipeline INFO[2019-08-29T13:40:00.779+02:00] Finished processing ledger duration=0.086024492 ledger=25565888 pid=5965 service=ingest shutdown=false transactions=14 INFO[2019-08-29T13:40:00.815+02:00] Reading new ledger ledger=25565889 pid=5965 service=ingest INFO[2019-08-29T13:40:00.816+02:00] Processing ledger ledger=25565889 pid=5965 service=ingest type=ledger_pipeline updating_database=true INFO[2019-08-29T13:40:00.881+02:00] Processed ledger ledger=25565889 pid=5965 service=ingest type=ledger_pipeline INFO[2019-08-29T13:40:00.881+02:00] Finished processing ledger duration=0.06619956 ledger=25565889 pid=5965 service=ingest shutdown=false transactions=29 INFO[2019-08-29T13:40:00.901+02:00] Reading new ledger ledger=25565890 pid=5965 service=ingest INFO[2019-08-29T13:40:00.902+02:00] Processing ledger ledger=25565890 pid=5965 service=ingest type=ledger_pipeline updating_database=true INFO[2019-08-29T13:40:00.972+02:00] Processed ledger ledger=25565890 pid=5965 service=ingest type=ledger_pipeline INFO[2019-08-29T13:40:00.972+02:00] Finished processing ledger duration=0.071039012 ledger=25565890 pid=5965 service=ingest shutdown=false transactions=20 ``` -------------------------------- ### Running Horizon Unit Tests Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Commands to change into the Horizon service directory and execute all standard Go unit tests within the package. This requires a running Stellar-Core instance and a configured Horizon database. ```bash cd go/services/horizon/ go test ./... ``` -------------------------------- ### GET /keys Error Example: Not Found (JSON) Source: https://github.com/stellar/go/blob/master/services/keystore/spec.md Demonstrates a `not_found` error scenario for the GET /keys endpoint when no keys are found associated with the authenticated user ID. Provides the structure of the error response body. ```json { "type": "not_found", "title": "Resourse Missing", "status": 404, "detail": "The resource at the url requested was not found. This\n\t\tusually occurs for one of two reasons: The url requested is not valid,\n\t\tor no data in our database could be found with the parameters\n\t\tprovided." } ``` -------------------------------- ### Serving the SEP-8 Approval Server (Shell) Source: https://github.com/stellar/go/blob/master/services/regulated-assets-approval-server/README.md This snippet shows the command to install and run the SEP-8 Approval Server, along with the available command-line flags for configuring its behavior, such as database URL, asset details, network settings, and port. ```shell $ go install $ regulated-assets-approval-server serve --help Serve the SEP-8 Approval Server Usage: regulated-assets-approval-server serve [flags] Flags: --asset-code string The code of the regulated asset (ASSET_CODE) --base-url string The base url address to this server (BASE_URL) --database-url string Database URL (DATABASE_URL) (default "postgres://localhost:5432/?sslmode=disable") --friendbot-payment-amount int The amount of regulated assets the friendbot will be distributing (FRIENDBOT_PAYMENT_AMOUNT) (default 10000) --horizon-url string Horizon URL used for looking up account details (HORIZON_URL) (default "https://horizon-testnet.stellar.org/") --issuer-account-secret string Secret key of the issuer account. (ISSUER_ACCOUNT_SECRET) --kyc-required-payment-amount-threshold string The amount threshold when KYC is required, may contain decimals and is greater than 0 (KYC_REQUIRED_PAYMENT_AMOUNT_THRESHOLD) (default "500") --network-passphrase string Network passphrase of the Stellar network transactions should be signed for (NETWORK_PASSPHRASE) (default "Test SDF Network ; September 2015") --port int Port to listen and serve on (PORT) (default 8000) ``` -------------------------------- ### Example Claimable Balance Response - JSON Source: https://github.com/stellar/go/blob/master/services/horizon/CHANGELOG.md This JSON snippet shows a sample response structure for the GET /claimable_balances/{id} endpoint in Stellar Horizon, illustrating the fields available for a claimable balance resource, including links, id, asset, amount, sponsor, last modified ledger, claimants, and paging token. ```json { "_links": { "self": { "href": "/claimable_balances/000000000102030000000000000000000000000000000000000000000000000000000000" } }, "id": "000000000102030000000000000000000000000000000000000000000000000000000000", "asset": "native", "amount": "10.0000000", "sponsor": "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML", "last_modified_ledger": 123, "claimants": [ { "destination": "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML", "predicate": { "unconditional": true } } ], "paging_token": "123-000000000102030000000000000000000000000000000000000000000000000000000000" } ``` -------------------------------- ### Installing Stellar Vanity Address Generator (Bash) Source: https://github.com/stellar/go/blob/master/tools/stellar-vanity-gen/README.md Installs the `stellar-vanity-gen` utility using the Go package manager. The `-u` flag updates the package if it's already installed. ```bash go get -u github.com/stellar/go/tools/stellar-vanity-gen ``` -------------------------------- ### Example Response for Stellar Ticker Assets Endpoint (JSON) Source: https://github.com/stellar/go/blob/master/services/ticker/docs/API.md This JSON snippet shows a sample response from the GET https://ticker.stellar.org/assets.json endpoint. It illustrates the structure and data returned for a list of assets, including metadata like asset code, issuer, type, account counts, and various flags and descriptions. ```json { "generated_at": 1556828621410, "generated_at_rfc3339": "2019-05-02T17:23:41-03:00", "assets": [ { "code": "AngelXYZ", "issuer": "GANZBUS4726LBT2CBJ3BGF3TP4NJT5MHZMI423NHMXFRWGO2DCBQEXYZ", "type": "credit_alphanum12", "num_accounts": 282, "auth_required": false, "auth_revocable": false, "amount": 4999999999.999953, "asset_controlled_by_domain": true, "anchor_asset": "", "anchor_asset_type": "", "display_decimals": 0, "name": "", "desc": "", "conditions": "", "is_asset_anchored": false, "fixed_number": 0, "max_number": 0, "is_unlimited": false, "redemption_instructions": "", "collateral_addresses": [], "collateral_address_signatures": [], "countries": "", "status": "", "last_valid": 1555509989002 }, { "code": "PUSH", "issuer": "GBB5TTFQE5KT3TEBCR7Z3FZR3R3WTVD654XL2KHKVONRIOBEI5UGOFQQ", "type": "credit_alphanum4", "num_accounts": 15, "auth_required": false, "auth_revocable": false, "amount": 1000000000, "asset_controlled_by_domain": true, "anchor_asset": "", "anchor_asset_type": "", "display_decimals": 2, "name": "Push", "desc": "1 PUSH token entitles you to access the push API.", "conditions": "Token used to access the PUSH api to send a push request to the stellar network.", "is_asset_anchored": false, "fixed_number": 0, "max_number": 0, "is_unlimited": false, "redemption_instructions": "", "collateral_addresses": [], "collateral_address_signatures": [], "countries": "", "status": "", "last_valid": 1555509990457 } ] } ``` -------------------------------- ### Initialize Captive Core Backend - Stellar Ingestion - Go Source: https://github.com/stellar/go/blob/master/ingest/README.md Sets up the main function for ledger statistics analysis. Imports required Stellar ingestion libraries, context, and logging. Initializes a logger configured to only show errors from the backend. Creates and defers closing a new Captive Core backend instance using a predefined configuration. ```Go package main import ( "context" "fmt" "io" "github.com/sirupsen/logrus" "github.com/stellar/go/ingest" backends "github.com/stellar/go/ingest/ledgerbackend" "github.com/stellar/go/support/log" ) func statistics() { ctx := context.Background() // Only log errors from the backend to keep output cleaner. lg := log.New() lg.SetLevel(logrus.ErrorLevel) config.Log = lg backend, err := backends.NewCaptive(config) panicIf(err) defer backend.Close() // ... ``` -------------------------------- ### Running Horizon Integration Tests Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Bash commands to set environment variables required for enabling integration tests, specifying the Stellar Core protocol version and Docker image, and then running the integration test suite with race detection, a timeout, and verbose output. ```bash export HORIZON_INTEGRATION_TESTS_ENABLED=true export HORIZON_INTEGRATION_TESTS_CORE_MAX_SUPPORTED_PROTOCOL=21 export HORIZON_INTEGRATION_TESTS_DOCKER_IMG=stellar/stellar-core:21 go test -race -timeout 25m -v ./services/horizon/internal/integration/... ``` -------------------------------- ### Compile Rust Contracts to WASM Test Fixtures (Bash) Source: https://github.com/stellar/go/blob/master/services/horizon/internal/integration/contracts/README.md These commands navigate to the contract source directory, update dependencies, compile the Rust code to WASM for the `wasm32-unknown-unknown` target in release mode, and copy the resulting `.wasm` files to the `testdata/` directory for integration tests. Requires the Rust toolchain and updated `Cargo.toml`. ```Bash cd ./services/horizon/internal/integration/contracts cargo update cargo build --target wasm32-unknown-unknown --release cp target/wasm32-unknown-unknown/release/*.wasm ../testdata/ ``` -------------------------------- ### Configuring Single Domain Federation (TOML) Source: https://github.com/stellar/go/blob/master/services/federation/README.md Example TOML configuration for the Stellar federation service, demonstrating how to restrict federation and reverse federation queries to a single domain (`acme.org`) using SQL conditions. ```TOML federation = "SELECT username as memo, 'text' as memo_type, 'GD6WU64OEP5C4LRBH6NK3MHYIA2ADN6K6II6EXPNVUR3ERBXT4AN4ACD' as id FROM Users WHERE username = ? AND ? = 'acme.org'" reverse-federation = "SELECT username as name, 'acme.org' as domain FROM Users WHERE account_id = ?" ``` -------------------------------- ### Helper Error Handling Function - Go Source: https://github.com/stellar/go/blob/master/ingest/README.md Defines a simple helper function `panicIf` intended for use in tutorials or examples. It checks if the provided error is not nil and, if so, calls `panic` with the error. This function is explicitly noted as unsuitable for production code due to its use of `panic`. ```Go func panicIf(err error) { if err != nil { panic(err) } } ``` -------------------------------- ### Initialize Asset Stats Table - CLI Source: https://github.com/stellar/go/blob/master/services/horizon/CHANGELOG.md Runs the command to initialize the 'asset_stats' table in the Horizon database. This is required once before starting ingestion if asset statistics are enabled. ```CLI horizon db init-asset-stats ``` -------------------------------- ### Running Go Code Formatting Scripts Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Provides bash commands to execute scripts included in the repository for automated code formatting (`gofmt.sh`), static analysis (`govet.sh`), and additional checks (`staticcheck.sh`) to ensure code quality and consistency. ```bash ./gofmt.sh ./govet.sh ./staticcheck.sh ``` -------------------------------- ### Accelerated Standalone Network Configuration Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Configuration settings to speed up the standalone Stellar network for testing. This involves modifying the captive-core configuration file and setting the `CHECKPOINT_FREQUENCY` environment variable for Horizon. ```bash # In captive-core-standalone.cfg: # ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING=true # In terminal: export CHECKPOINT_FREQUENCY=8 ``` -------------------------------- ### Configuring Captive Stellar-Core Backend with Testnet Defaults (Go) Source: https://github.com/stellar/go/blob/master/ingest/README.md This snippet shows how to create the configuration (`config`) required for the Captive Stellar-Core backend. It uses default history archive URLs and network passphrase for the SDF testnet, creates a `CaptiveCoreToml` configuration, and then constructs the `CaptiveCoreConfig` object, including the path to the `stellar-core` binary. It relies on a `panicIf` helper function for error handling. ```Go archiveURLs := network.TestNetworkhistoryArchiveURLs networkPassphrase := network.TestNetworkPassphrase captiveCoreToml, err := ledgerbackend.NewCaptiveCoreToml( ledgerbackend.CaptiveCoreTomlParams{ NetworkPassphrase: networkPassphrase, HistoryArchiveURLs: archiveURLs, }, }) panicIf(err) config := ledgerbackend.CaptiveCoreConfig{ // Change these based on your environment: BinaryPath: "/usr/bin/stellar-core", NetworkPassphrase: networkPassphrase, HistoryArchiveURLs: archiveURLs, Toml: captiveCoreToml, } ``` -------------------------------- ### Ingesting a Specific Ledger using Captive Stellar-Core Backend (Go) Source: https://github.com/stellar/go/blob/master/ingest/README.md This snippet demonstrates how to initialize the Captive Stellar-Core backend, prepare a specific ledger range (in this case, a single ledger), retrieve the ledger data, and print its sequence number. It requires a `config` object for backend configuration and a `panicIf` helper function for error handling. The retrieved `ledger` is a raw `xdr.LedgerCloseMeta` object. ```Go package main import ( "context" "fmt" backends "github.com/stellar/go/ingest/ledgerbackend" ) func main() { ctx := context.Background() backend, err := backends.NewCaptive(config) panicIf(err) defer backend.Close() // Prepare a single ledger to be ingested, err = backend.PrepareRange(ctx, backends.BoundedRange(123456, 123456)) panicIf(err) // then retrieve it: ledger, err := backend.GetLedger(ctx, 123456) panicIf(err) // Now `ledger` is a raw `xdr.LedgerCloseMeta` object containing the // transactions contained within this ledger. fmt.Printf("\nHello, Sequence %d.\n", ledger.LedgerSequence()) } ``` -------------------------------- ### Run Keystored in Production (Shell) Source: https://github.com/stellar/go/blob/master/services/keystore/cmd/keystored/README.md Starts the keystored service in production mode, requiring paths to valid TLS certificates and keys. Authentication is enabled by default but can be disabled with a flag. ```Shell keystored -tls-cert=PATH_TO_TLS_CERT -tls-key=PATH_TO_TLS_KEY serve ``` -------------------------------- ### Downloading Go Module Dependencies Source: https://github.com/stellar/go/blob/master/DEVELOPING.md Downloads all required dependencies for the repository for offline development. Dependencies are typically installed automatically, but this command ensures all are present beforehand. ```Shell go mod download ``` -------------------------------- ### ALB Replayer Command Line Usage Source: https://github.com/stellar/go/blob/master/tools/alb-replay/README.md Displays the available command-line arguments for the `alb-replay` tool, including options for filtering requests by path or status code, controlling concurrency, setting timeout, and specifying a starting point. ```bash Usage of ./alb-replay: -path-filter string Regular expression with which to filter in requests based on their paths -quiet Only log failed requests -start-from int What URL number to start from (default 1) -status-code-filter string Regular expression with which to filter in request based on their status codes (default "^2[0-9][0-9]$") -timeout duration HTTP request timeout (default 5s) -workers int How many parallel workers to use (default 1) ``` -------------------------------- ### Standard Go Print Output for XDR Source: https://github.com/stellar/go/blob/master/tools/xdr2go/README.md Example showing the default output of `fmt.Printf("%#v", value)` for an XDR transaction envelope, highlighting issues like hexadecimal memory addresses and redundant nil pointers. ```Go xdr.TransactionEnvelope{Type: 2, V0: (*xdr.TransactionV0Envelope)(nil), V1: (*xdr.TransactionV1Envelope)(0xc0000aa2d0), FeeBump: (*xdr.FeeBumpTransactionEnvelope)(nil) ``` -------------------------------- ### Connecting to a Stellar History Archive (Go) Source: https://github.com/stellar/go/blob/master/ingest/README.md Establishes a connection to a Stellar history archive using the provided configuration details, including the archive URL, network passphrase, S3 region, and unsigned requests option. Handles potential connection errors. ```Go // Open a history archive using our existing configuration details. historyArchive, err := historyarchive.Connect( config.HistoryArchiveURLs[0], // assumes a CaptiveCoreConfig historyarchive.ConnectOptions{ NetworkPassphrase: config.NetworkPassphrase, S3Region: "us-west-1", UnsignedRequests: false, }, ) panicIf(err) ``` -------------------------------- ### Clone Stellar Go Monorepo Source: https://github.com/stellar/go/blob/master/services/horizon/internal/docs/GUIDE_FOR_DEVELOPERS.md Clones the Stellar Go monorepo containing the Horizon source code from GitHub. Developers contributing to the project should consider forking the repository and cloning their fork instead. ```Bash git clone https://github.com/stellar/go.git ``` -------------------------------- ### Importing historyarchive package (Go) Source: https://github.com/stellar/go/blob/master/ingest/README.md Imports the necessary `historyarchive` package from the Stellar Go SDK to interact with history archives. This is required for reading ledger changes from checkpoints. ```Go import "github.com/stellar/go/historyarchive" ``` -------------------------------- ### Example Orderbook Response from Stellar Horizon Source: https://github.com/stellar/go/blob/master/services/ticker/docs/API.md A sample JSON response from the Stellar Horizon orderbook endpoint, showing the structure of bid and ask data, along with details of the base and counter assets. ```json { "bids": [ { "price_r": { "n": 223, "d": 10000000 }, "price": "0.0000223", "amount": "0.0006261" }, { "price_r": { "n": 16469, "d": 739692077 }, "price": "0.0000223", "amount": "0.0037850" }, { "price_r": { "n": 16469, "d": 741750702 }, "price": "0.0000222", "amount": "0.0037745" }, { "price_r": { "n": 111, "d": 5000000 }, "price": "0.0000222", "amount": "0.0040000" } ], "asks": [ { "price_r": { "n": 7, "d": 312500 }, "price": "0.0000224", "amount": "150.8482143" }, { "price_r": { "n": 9, "d": 400000 }, "price": "0.0000225", "amount": "348.4311112" }, { "price_r": { "n": 113, "d": 5000000 }, "price": "0.0000226", "amount": "335.6238939" } ], "base": { "asset_type": "native" }, "counter": { "asset_type": "credit_alphanum4", "asset_code": "BTC", "asset_issuer": "GATEMHCCKCY67ZUCKTROYN24ZYT5GK4EQZ65JJLDHKHRUZI3EUEKMTCH" } } ```