Skip to content

feat: add public getter for current ledger sequence (#15) - #320

Open
Rodrigoue9 wants to merge 1 commit into
Vero-protocol:mainfrom
Rodrigoue9:feat/issue-15-get-ledger-sequence
Open

Rodrigoue9 wants to merge 1 commit into
Vero-protocol:mainfrom
Rodrigoue9:feat/issue-15-get-ledger-sequence

Conversation

@Rodrigoue9

@Rodrigoue9 Rodrigoue9 commented Oct 3, 2026 •

Copy link
Copy Markdown

Summary

What was wrong

External services and integrating contracts need an authentic on-chain reference to the current chain-time (ledger sequence number). Previously, VeroContract did not expose a public getter for the ledger sequence, forcing external integrations to query the Stellar RPC directly or duplicate chain-state queries.

What was done & Alternatives Considered

This pull request introduces a lightweight, public read-only getter pub fn get_ledger(env: Env) -> u32 on the core contract interface that returns env.ledger().sequence().

  • Alternative considered: Exposing ledger timestamp (env.ledger().timestamp()) instead of or alongside sequence. Rejected because Issue feat: add public getter for current ledger sequence #15 specifically requests sequence number, which is discrete and monotonic across Stellar consensus ledgers.
  • Alternative considered: Implementing as a standalone module function in src/lib.rs. Rejected because external smart contracts and off-chain RPC clients invoke Soroban contracts through the #[contractimpl] interface; placing the method in src/contracts/proxy_entry/entry_config.rs makes it an exposed entrypoint on VeroContract and VeroContractClient.

What to look at

  • Reviewers should verify that get_ledger intentionally does NOT gate on circuit_breaker::require_not_paused(&env) or require contract initialization. This ensures external observers and oracle monitors can query chain sequence even during emergency pauses or prior to initialization.

How verified

  • Added comprehensive unit/integration test in tests/init.rs verifying default sequence, mocked advances, post-initialization consistency, and availability during emergency pause.
  • Ran full test suite (216 tests passed).
  • Checked formatting and clippy (cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D clippy::all).

Related Issue

Closes #15

Changes Made

  • Contract Entrypoint (src/contracts/proxy_entry/entry_config.rs):
    • Implemented pub fn get_ledger(env: Env) -> u32 returning env.ledger().sequence().
    • Added doc comments explaining read-only permissionless semantics.
  • Unit & Integration Tests (tests/init.rs):
    • Added test_get_ledger_sequence to verify sequence reflection against default environment, mocked sequence advances (100, 500, 1000, 10000), across contract initialization, and confirmed readability remains unblocked even when the contract is paused.

Testing Performed

  • Ran cargo test --test init: 8/8 tests passed.
  • Ran full test suite across the workspace: 216 tests passed.
  • Ran cargo fmt --all -- --check: formatting 100% compliant.
  • Ran cargo clippy --workspace --all-targets -- -D clippy::all: 0 warnings, 0 errors.

Checklist

  • I have linked the related issue with Closes #15.
  • I have tested my changes locally.
  • I have run cargo fmt --check.
  • I have run cargo clippy -- -D warnings where applicable.
  • I have updated relevant documentation.

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.

feat: add public getter for current ledger sequence

1 participant