Skip to content

feat(vault): add get_config and get_cycle_claimed_total views - #37

Closed
IG-ABHINAV wants to merge 1 commit into
SplitStream-Labs:mainfrom
IG-ABHINAV:feat/vault-readonly-views
Closed

IG-ABHINAV wants to merge 1 commit into
SplitStream-Labs:mainfrom
IG-ABHINAV:feat/vault-readonly-views

Conversation

@IG-ABHINAV

Copy link
Copy Markdown

Description

The vault stores admin, oracle and token in instance storage, but no read-only function returned them. The per-cycle CycleClaimedTotal entry written by credit_claim was also only reachable through events.

This adds two read-only views, as requested in #30:

  • get_config() -> Option<VaultConfig> returns admin, oracle and token, or None before initialize.
  • get_cycle_claimed_total(cycle_id) -> i128 returns the cumulative claimed amount, or 0 if the cycle has never been claimed.

Both take no auth and do not bump any TTL. VaultConfig is a #[contracttype] struct in types.rs.

Fixes #30

How

The views sit with the existing read-only methods in lib.rs and reuse the storage helpers already used by initialize and credit_claim. docs/contract-reference.md and docs/SUMMARY.md now list 24 public functions (14 state-changing, 10 read-only views).

Non-negotiables checklist

  • Merkle leaf hashing is byte-identical to the frozen format (sha256(contributor.to_xdr(env) ++ amount.to_xdr(env))), or the change is coordinated with splitstream-actions and the golden fixtures.
  • No floats anywhere — all monetary math is integer basis-points.
  • No unwrap() / expect() outside #[cfg(test)] code.
  • Every state-changing function emits an event. (These two functions are read-only and emit no events.)
  • Every persistent-storage write extends TTL in the same call (storage::bump_persistent); every admin-gated call bumps the instance TTL (storage::bump_instance). (These views do not write and do not bump TTL.)
  • Every require_auth() targets the correct role (admin vs oracle vs contributor). (No auth on these views.)
  • Error discriminants are unchanged (they are on-chain ABI).
  • No new unbounded loops over the contributor set (pull-payment preserved).

Verification

  • cargo test --workspace passes cleanly
  • cargo clippy --all-targets -- -D warnings passes cleanly
  • stellar contract build --package splitstream-vault succeeds (not run here; stellar-cli was not used)
  • Details / notes:
cargo test --workspace
# test result: ok. 47 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.50s

cargo test --workspace readonly_views
# test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 44 filtered out; finished in 0.01s
#   get_config_is_none_before_initialize
#   get_config_returns_bound_addresses_after_initialize
#   get_cycle_claimed_total_starts_at_zero_and_increments

cargo clippy --all-targets -- -D warnings
# exit 0

Judgment calls

The historical paragraph in docs/contract-reference.md about the earlier Testnet deployment still describes that revision as 22 functions. I left it unchanged so it stays a record of that deploy; the live function count at the top of the page is 24.

Expose the bound admin, oracle and token as Option<VaultConfig>, and the
per-cycle claimed total, as read-only contract methods with no auth and
no TTL bump.

Fixes SplitStream-Labs#30
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(vault): add get_config() and get_cycle_claimed_total() read-only views

2 participants