Skip to content

refactor: rename oracle_address→condition_oracle, add assert_valid_bp… - #654

Open
ironclad-x wants to merge 1 commit into
Stellar-split:mainfrom
ironclad-x:feature/issues-627-628-629-630
Open

refactor: rename oracle_address→condition_oracle, add assert_valid_bp…#654
ironclad-x wants to merge 1 commit into
Stellar-split:mainfrom
ironclad-x:feature/issues-627-628-629-630

Conversation

@ironclad-x

Copy link
Copy Markdown

Title: refactor: rename condition_oracle, assert_valid_bps, InvoiceExt defaults, #[must_use]
distribute_with_remainder

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Description:

This PR addresses four independent cleanup issues across the split contract.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Changes

#627 — Rename oracle_address → condition_oracle in InvoiceExt

InvoiceExt had both oracle_address and price_oracle fields, which were easy to confuse. oracle_address is
specifically the release-condition oracle (gating condition_met), not the price oracle. Renamed to condition_oracle
across types.rs, lib.rs, test.rs, and fuzz/src/lib.rs.

Closes #627

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────

#628 — Extract penalty_bps validation into validation.rs as assert_valid_bps

Added pub fn assert_valid_bps(bps: u32) -> Result<(), ContractError> to contracts/split/src/validation.rs. Returns
Err(ContractError::InvalidAmount) when bps > 10_000. Replaced the three inline assert! guards for penalty_bps,
tax_bps, and insurance_premium_bps in _create_invoice with calls to this function. Added unit tests covering both
valid (0, 5000, 10_000) and out-of-range (10_001) values.

Closes #628

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────

#629 — Add Default impl to InvoiceExt and InvoiceExt2 to simplify from_legacy

Added InvoiceExt::default(env: &Env) and InvoiceExt2::default(env: &Env) factory methods in types.rs. Rewrote
Invoice::from_legacy to start from those defaults and override only the fields that LegacyInvoice actually carries,
replacing a ~70-line manual zero-fill block with a concise override pattern. No behaviour change.

Closes #629

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────

#630 — Add #[must_use] to distribute_with_remainder

Added #[must_use = "the distribution result must be applied to recipients"] to distribute_with_remainder in
calc.rs. The compiler will now emit a warning if a caller discards the return value, preventing silent
fund-distribution bugs. Documented the expected warning in a code comment per the acceptance criteria.

Closes #630

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  • All existing tests continue to pass (cargo test --workspace)
  • New unit tests added in validation.rs for assert_valid_bps
  • No storage key changes — snapshot test unaffected

…s, Default for InvoiceExt/2, #[must_use] on distribute_with_remainder

- Stellar-split#627: Rename InvoiceExt::oracle_address to condition_oracle across
  types.rs, lib.rs, test.rs, and fuzz/src/lib.rs to distinguish the
  release-condition oracle from price_oracle.

- Stellar-split#628: Extract basis-points validation into validation.rs as
  assert_valid_bps(bps) -> Result<(), ContractError>. Wire it into
  _create_invoice for penalty_bps, tax_bps, and insurance_premium_bps.
  Add unit tests for valid (0, 5000, 10_000) and out-of-range (10_001)
  values.

- Stellar-split#629: Implement InvoiceExt::default(env) and InvoiceExt2::default(env)
  in types.rs. Rewrite Invoice::from_legacy to start from those defaults
  and override only the fields LegacyInvoice carries, eliminating the
  long manual zero-fill block.

- Stellar-split#630: Add #[must_use = "the distribution result must be applied to
  recipients"] to distribute_with_remainder in calc.rs so the compiler
  warns when the return value is silently dropped.
@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@ironclad-x Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant