refactor(contract): move shared request and auth plumbing into api/common.rs - #4148
refactor(contract): move shared request and auth plumbing into api/common.rs#4148gilcu3 wants to merge 2 commits into
Conversation
Pull request overviewPart 2/12 of the #1962 contract-refactor series. It carves the request/auth plumbing that had accumulated in Changes:
Reviewed changesPer-file summary
FindingsNo blocking issues. Things I checked that hold up:
Non-blocking (nits, follow-ups, suggestions):
✅ Approved |
There was a problem hiding this comment.
I won't lie, Claude helped me confirm this is a mechanical refactor. Only these changes aren't mechanical (caught by Claude), but they look good:
- Visibility widened from private to
pub(crate)on the moved items, which the move requires and which changes nothing externally- Doc-comment-only edits: intra-doc links rewritten to full paths (
crate::state::ProtocolContractState::...) so they resolve from the new module, and one added clause onMINIMUM_SIGN_REQUEST_DEPOSIT("also charged for foreign-transaction verification")- Import shuffling in
lib.rs(drops now-unusedGasWeightandRequestError, imports the moved items fromapi::common) and the new file's own imports, module doc line, impl-block/test-module scaffolding, and closing braces
kevindeforth
left a comment
There was a problem hiding this comment.
I would suggest to split this into even more files.
| /// Transfers `amount` to `account_id` via a detached promise; no-op when zero. | ||
| pub(crate) fn refund_to(account_id: &AccountId, amount: NearToken) { | ||
| if amount > NearToken::from_near(0) { | ||
| log!("refund {amount} to {account_id}"); | ||
| Promise::new(account_id.clone()).transfer(amount).detach(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Hmm, I think it wouldn't be bad to have maybe one file where we track all the promises that this contract spawns (e.g. promises.rs).
This method and enqueue_yield_request kind of belong together in that sense.
There was a problem hiding this comment.
Unfortunately we have many more methods using promises than this two, so it would not be very uniform to have them being located there. Leaving here for now, we could think later if we want to do some promise unification
Part 2/12 of #1962