fix: repair corrupted admin.rs allowlist/timelock functions, fix script shebangs - #719
Merged
Merged
Conversation
…pt shebangs admin.rs had multiple functions interleaved from a bad merge, leaving the file unparseable: - set_token_allowlist_enabled had no closing brace; its body fell through into get_allowed_tokens. Restored to persist DataKey::TokenAllowlistEnabled and emit allowlist_toggled. - get_treasury returned read_treasury(&env) with no closing brace before queue_set_fee_collector began. Added the missing brace. - is_action_paused's body was replaced mid-function by fee-collector-setting logic; the real is_action_paused tail was orphaned further down. Restored is_action_paused to its own body and reconstructed the missing set_fee_collector(env, new_collector) direct admin function (matching test_set_fee_collector.rs / test_auth_matrix.rs expectations: admin-gated via admin.require_auth(), rejects the zero address, emits emit_fee_collector_updated). - add_allowed_token read/returned DataKey::ResolverStrict as a bool instead of persisting to DataKey::TokenAllowlist and returning Result<(), _>. Fixed to push the token into the Vec<Address> allowlist and return Ok(()). - remove_allowed_token had an empty body that fell straight into cancel_timelock_op's code; that code actually removed a token from DataKey::TokenAllowlist (referencing a `token` param cancel_timelock_op doesn't have) so it has been moved into remove_allowed_token. - cancel_timelock_op now does real timelock cancellation: reads the queued DataKey::TimelockOp(operation) proposal via storage::read_timelock_proposal, removes it via storage::remove_timelock_proposal, and emits emit_timelock_cancelled with the original proposer. - Removed duplicate is_token_allowlist_enabled, get_allowed_tokens (a Map<Address,bool>-based copy inconsistent with the Vec<Address> storage format used by add/remove_allowed_token and their queue_/execute_ counterparts), and get_platform_fee_bps definitions that the same bad merge left behind, which would otherwise be duplicate-definition errors. build.sh and scripts/deploy.sh used the non-portable #!/bin/bash shebang; switched both to #!/usr/bin/env bash to match the other 8 scripts in the repo and work on systems without /bin/bash (NixOS, BSDs, etc). Fixes JSE-ORG#711 Fixes JSE-ORG#710 Fixes JSE-ORG#622
|
@david87131 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
contracts/escrow/src/admin.rswas corrupted by a bad merge (introduced in #702): several new functions were added with their opening signature but no body/closing brace, causing their doc-comment + signature to be immediately followed by the next function'spub fn, and in a couple of cases an unrelated function's leftover body ended up glued onto the wrong signature. The result does not compile.What was wrong, and how each piece was repaired
set_token_allowlist_enabled(admin.rs corrupted — set_token_allowlist_enabled has no closing brace, functions overlapping #710): had no closing brace — its auth-check body fell straight intoget_allowed_tokens. Restored so it persistsDataKey::TokenAllowlistEnabledand emitsallowlist_toggled, with its own closing brace.get_treasury(admin.rs corrupted — set_token_allowlist_enabled has no closing brace, functions overlapping #710): returnedread_treasury(&env)but had no closing brace before the// 7. SetFeeCollectorblock started. Added the missing}.is_action_paused: its body was overwritten mid-function by fee-collector-setting logic (.set(&DataKey::FeeCollector, ...)/Ok(())), while the real tail ofis_action_paused(.get(&DataKey::ActionPaused(action)).unwrap_or(false)) was orphaned several lines below, itself followed by a doc comment forget_arbitration_fee. Restoredis_action_pausedto a single, complete body, and reconstructed the missingset_fee_collector(env, new_collector)direct admin function from the fragments — signature/behavior verified againsttest_set_fee_collector.rsandtest_auth_matrix.rs::set_fee_collector_requires_admin_auth, which expect it to take onlynew_collector(nocallerparam), gate viaadmin.require_auth(), reject the zero address withInvalidAddress, and emitemit_fee_collector_updated.add_allowed_token(admin.rs corrupted — remove_allowed_token body replaced with cancel_timelock_op logic #711): its final expression readDataKey::ResolverStrictand returned abool, notResult<(), ContractError>. Fixed to push the token into theVec<Address>stored atDataKey::TokenAllowlistand returnOk(()), matching the pattern used byexecute_add_allowed_token.remove_allowed_token(admin.rs corrupted — remove_allowed_token body replaced with cancel_timelock_op logic #711): had an empty body that fell straight into what was labeledcancel_timelock_op. That body actually implemented "readTokenAllowlist, check membership, remove, emittoken_allowlist_updated(token, false)" and referenced atokenvariablecancel_timelock_opnever declared — clear evidence it belonged toremove_allowed_token. Moved that logic intoremove_allowed_token(rewritten againstVec<Address>to matchadd_allowed_token/execute_add_allowed_token/execute_remove_allowed_token's storage format instead of theMap<Address,bool>it was using).cancel_timelock_op(admin.rs corrupted — remove_allowed_token body replaced with cancel_timelock_op logic #711): now implements real timelock cancellation using the existingDataKey::TimelockOp(u32)key (the same keyqueue_timelock_op/execute_timelock_opalready use): loads the queued proposal viastorage::read_timelock_proposal, returnsContractError::InvalidStateif nothing is queued for thatoperation, removes it viastorage::remove_timelock_proposal, and emitsemit_timelock_cancelled(env, operation, proposal.proposer, caller).Removed duplicate definitions the same bad merge left behind, which are duplicate-item compile errors once the file is otherwise fixed:
is_token_allowlist_enabled,get_allowed_tokensthat readDataKey::TokenAllowlistas aMap<Address, bool>and returned.keys()— inconsistent with theVec<Address>format used everywhere else (add_allowed_token,remove_allowed_token,queue_add_allowed_token/execute_add_allowed_token,queue_remove_allowed_token/execute_remove_allowed_token); kept theVec<Address>-based copy for consistency,get_platform_fee_bps.Shebangs (Fix shebang portability in build.sh and scripts/deploy.sh #622):
build.shandscripts/deploy.shused#!/bin/bash(a fixed path that doesn't exist on NixOS/BSDs/some custom setups). Changed both to#!/usr/bin/env bash, matching the other 8 scripts in the repo.Out of scope (found, not touched)
While verifying, I found
contracts/escrow/src/instructions.rs(and a related duplicateContractError::InvalidMulticallArgvariant inerrors.rs) has its own, unrelated pre-existing corruption from the same bad merge — a duplicated/misplacedmulticallsignature and a matching missing brace — which currently blockscargo build --libfor the whole crate independent of anything in this PR. That's a separate, larger repair and not part of issues #710/#711/#622, so I left it alone. I verifiedadmin.rsitself compiles cleanly by temporarily patching just thatinstructions.rsline locally (not committed): with that one-line local patch,cargo build --libsucceeds with zero errors or warnings originating fromadmin.rs. On the actual committed tree,cargo build --libfails only insideinstructions.rs— no errors referenceadmin.rs.Test plan
cargo build --libfromcontracts/escrow/— no errors or warnings fromadmin.rs(confirmed via a local, uncommitted probe-patch of the unrelatedinstructions.rsissue; the committed tree's sole compile error is ininstructions.rs, pre-existing and out of scope)bash -n build.sh— passesbash -n scripts/deploy.sh— passesadmin.rsagainst theTimelockOperation/DataKeyenums and the existingqueue_/execute_timelocked variants to confirm house style (auth pattern, error handling, event emission) is matchedFixes #711
Fixes #710
Fixes #622