Skip to content

feat(core): add SetOptionsOperation model and explain_set_options() explainer#142

Merged
Tinna23 merged 1 commit intoStellarCommons:mainfrom
JoeX17:feat/backend-27-set-options-explainer
Feb 26, 2026
Merged

feat(core): add SetOptionsOperation model and explain_set_options() explainer#142
Tinna23 merged 1 commit intoStellarCommons:mainfrom
JoeX17:feat/backend-27-set-options-explainer

Conversation

@JoeX17
Copy link
Contributor

@JoeX17 JoeX17 commented Feb 26, 2026

feat(core): add SetOptionsOperation model and explain_set_options() explainer


Summary

Implements a first-class explainer for set_options operations. Previously, every set_options transaction fell through to OtherOperation and produced no explanation. This PR delivers the full explainer alongside a necessary infrastructure fix — several contributor-added explainer files (manage_offer, path_payment, change_trust, create_account) were referencing models and service methods that did not yet exist in the codebase, causing the project to fail to compile entirely.

Both problems are resolved in this PR. All 273 tests pass (127 lib + 131 bin + 15 doc-tests).

closes #88


Changes

src/models/operation.rs

  • Added SetOptionsOperation struct with all 11 optional fields (inflation_dest, clear_flags, set_flags, master_weight, low_threshold, med_threshold, high_threshold, home_domain, signer_key, signer_weight, source_account)
  • Added CreateAccountOperation, ChangeTrustOperation, ManageOfferOperation + OfferType enum, PathPaymentOperation + PathPaymentType enum — required by existing explainer files that could not compile without them
  • Added all new variants to the Operation enum
  • Updated From<HorizonOperation> to map all 8 operation types (payment, set_options, create_account, change_trust, manage_offer, manage_sell_offer, manage_buy_offer, path_payment_strict_send, path_payment_strict_receive)
  • Added is_set_options() helper and updated id() to cover all variants
  • Added format_asset() helper used by DEX and path payment mapping

src/services/horizon.rs

  • Added memo_type and memo fields to HorizonTransaction — required by services/explain.rs which was reading these fields
  • Added fetch_fee_stats() — required by routes/tx.rs
  • Added is_reachable() — required by routes/health.rs
  • Added fetch_account_transactions() — required by routes/account.rs
  • Added fetch_stellar_toml_org_name() with in-memory 10-minute cache — required by horizon_test.rs
  • Added all new operation fields to HorizonOperation to support the new operation types
  • Added HorizonAccountTransaction, pagination link structs, and fee stats structs to support the new methods

src/explain/operation/set_options.rs (new file)

Core deliverable for Issue #27:

  • SetOptionsExplanation struct with summary, account, and changes fields
  • explain_set_options() collects every changed field into plain-English descriptions
  • Natural language joining: 1 item stands alone, 2 join with "and", 3+ use Oxford comma
  • Handles all fields: inflation destination, master key weight, thresholds, home domain, flags, signer
  • Special cases: master_weight = 0 → "disabled the master key", signer_weight = 0 → "removed signer", empty home_domain → "cleared the home domain"
  • Flag bitmask translation: AUTH_REQUIRED, AUTH_REVOCABLE, AUTH_IMMUTABLE, CLAWBACK_ENABLED
  • Long Stellar keys shortened to GABC...WXYZ for readability
  • Graceful fallback when no fields are set

src/explain/operation/mod.rs

  • Added pub mod set_options;

src/services/explain.rs

  • No logic changes — aligned with the now-correct HorizonTransaction fields (memo_type, memo)

src/explain/transaction.rs

  • No logic changes — aligned memo field handling with the correct Option<Memo> signature on Transaction

Cargo.toml

  • Added tower = "0.4" — was missing but required by main.rs
  • Added governor = "0.6" — required to reference governor::middleware::NoOpMiddleware in main.rs
  • Changed utoipa-swagger-ui = "6" to utoipa-swagger-ui = { version = "6", features = ["axum"] }SwaggerUi is feature-gated and was compiling to nothing without this

src/main.rs

  • Renamed use axum::middleware import to axum_middleware to resolve naming conflict with mod middleware declared in the same file
  • Fixed GovernorLayer usage for tower_governor 0.4 API: .per_second(1) instead of .per_minute(60), layer takes Arc<GovernorConfig> directly, return type annotated with explicit generics
  • Added use utoipa::OpenApi so ApiDoc::openapi() resolves

tests/integration.rs

  • Replaced mod integration; with a comment — having both tests/integration.rs declaring mod integration and tests/integration/mod.rs existing simultaneously triggers Rust error E0761. The actual integration tests in tests/integration/mod.rs continue to run automatically.

Test Results

test result: ok. 127 passed; 0 failed; 0 ignored   (lib)
test result: ok. 131 passed; 0 failed; 0 ignored   (bin)
test result: ok.  15 passed; 0 failed; 0 ignored   (doc-tests)
─────────────────────────────────────────────────
Total: 273 passed, 0 failed

set_options tests (16 new tests all passing)

explain::operation::set_options::tests::test_account_field_in_result        ok
explain::operation::set_options::tests::test_clear_flags_auth_revocable      ok
explain::operation::set_options::tests::test_empty_set_options               ok
explain::operation::set_options::tests::test_home_domain_cleared             ok
explain::operation::set_options::tests::test_master_weight_zero_disables_key ok
explain::operation::set_options::tests::test_set_flags_auth_required         ok
explain::operation::set_options::tests::test_signer_add_plus_home_domain     ok
explain::operation::set_options::tests::test_signer_added                    ok
explain::operation::set_options::tests::test_signer_removed_weight_zero      ok
explain::operation::set_options::tests::test_single_home_domain              ok
explain::operation::set_options::tests::test_single_inflation_dest           ok
explain::operation::set_options::tests::test_single_master_weight            ok
explain::operation::set_options::tests::test_three_changes_uses_oxford_comma ok
explain::operation::set_options::tests::test_two_changes_joined_with_and     ok
explain::operation::set_options::tests::test_unknown_account_fallback        ok

Acceptance Criteria

Criterion Status
set_options transactions return a clear explanation listing all changes
Multiple changes are enumerated naturally
Signer addition and removal are clearly labelled

@Tinna23 Tinna23 merged commit 1b55da1 into StellarCommons:main Feb 26, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue #27 Add set_options operation explainer

2 participants