Skip to content

refactor(common): consolidate duplicated primary-admin lookup - #602

Open
Hollujay wants to merge 2 commits into
Betta-Pay:mainfrom
Hollujay:fix/553-consolidate-read-admin
Open

refactor(common): consolidate duplicated primary-admin lookup#602
Hollujay wants to merge 2 commits into
Betta-Pay:mainfrom
Hollujay:fix/553-consolidate-read-admin

Conversation

@Hollujay

Copy link
Copy Markdown
Contributor

Summary

  • bettapay_common::storage::read_admin and settlement_contract's local read_admin both existed to answer "what is the first/primary admin," but with incompatible storage backends — the common one read a never-written CommonDataKey::Admin singular Address, while settlement (and governance) actually store the admin role as a multisig Vec<Address> and pull get(0) for single-address contexts.
  • Added bettapay_common::storage::primary_admin(admins: &Vec<Address>) -> Option<Address> as the one shared implementation of that "first entry" semantic.
  • Routed settlement_contract::storage::read_admin and the two governance call sites that pull the primary admin off a storage-read Vec<Address> (execute_recovery, transfer_admin) through the new helper.
  • Left signer-list .get(0).unwrap() call sites untouched — those extract the acting caller from a caller-supplied signer list, a different concern from reading the stored admin.

Usage audit

  • settlement_contract/src/storage.rs::read_admin — now calls storage::primary_admin.
  • governance_contract/src/lib.rs::execute_recovery — now calls storage::primary_admin.
  • governance_contract/src/lib.rs::transfer_admin — now calls storage::primary_admin for old_admin.

Test plan

  • cargo test --workspace — all 33 governance + 16 settlement + 2 new bettapay_common unit tests pass
  • cargo clippy --workspace --all-targets — clean
  • Added bettapay_common::storage::tests::primary_admin_returns_first_entry / primary_admin_returns_none_for_empty_list

Closes #553

Hollujay and others added 2 commits August 19, 2026 19:59
Both bettapay_common's dead single-admin path and settlement/governance's
inline `admins.get(0).unwrap()` reimplemented the same "first entry of the
stored multisig admin list" semantics. Add storage::primary_admin as the
one shared implementation and route settlement's read_admin and
governance's stored-admin lookups through it.

Closes Betta-Pay#553
@Hollujay

Copy link
Copy Markdown
Contributor Author

Kindly review PR for merging @therealjhay

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.

bettapay_common read_admin helper and contract-level read_admin duplicate logic

1 participant