feat: add invoice event replay and contract-wide emergency withdrawal#257
Open
Idaonoli wants to merge 1 commit into
Open
feat: add invoice event replay and contract-wide emergency withdrawal#257Idaonoli wants to merge 1 commit into
Idaonoli wants to merge 1 commit into
Conversation
…drawal (Stellar-split#233) Resolves two issues and cleans up pre-existing compilation errors introduced by earlier PRs that left duplicate struct fields and function definitions throughout the codebase. Issue Stellar-split#232 — Invoice payment event replay for indexer recovery: - Add replay_invoice_events(invoice_id) to lib.rs. Callable by anyone, pure read+emit with no state mutation. Re-emits invoice_created, one payment_received per historical payment in order, and the terminal status event (invoice_released / invoice_refunded) when the invoice is no longer Pending. All replayed events carry a fourth `replay` topic so indexers can distinguish them from live events and avoid double-counting. - Add replay_invoice_created, replay_payment_received, replay_invoice_released, replay_invoice_refunded to events.rs. Issue Stellar-split#233 — Contract-wide emergency withdrawal: - Add EmergencyWithdraw(Address, Address) variant to TimelockAction. - Add request_emergency_withdraw(admin, token, destination) to lib.rs. Requires SuperAdmin auth and the contract to already be paused. Queues a timelocked action and returns the action_id. - Handle EmergencyWithdraw in execute_action with a mandatory 7-day minimum delay independent of the configured timelock_secs, plus a check that the contract is still paused at execution time. Transfers the full token balance to destination and emits emergency_withdrawal_executed (token, destination, amount). - Add emergency_withdrawal_executed to events.rs. Pre-existing compilation fixes: - types.rs: remove duplicate fields (min_funding_amount, priorities, admin_frozen) from Invoice struct; add missing creation_timestamp and min_payment_increment to InvoiceExt2 so they round-trip through storage; wire external_prerequisite through Invoice split/assemble/ from_legacy; add EmergencyWithdraw to TimelockAction. - events.rs: remove eight duplicate function definitions that were added by a prior PR alongside the originals. - lib.rs: remove duplicate SHARD_COUNT constant, two spurious require_admin definitions, duplicate admin_frozen assignment in clone_invoice, and update all InvoiceExt2 default literals to include creation_timestamp/min_payment_increment. - test.rs: add missing external_prerequisite: None to invoice_options. Tests added: - test_replay_invoice_events_pending: verifies 2 replay events emitted for a pending invoice (created + 1 payment). - test_replay_invoice_events_released: verifies 4 replay events for a fully-funded and released invoice (created + 2 payments + released). - test_emergency_withdraw_blocked_when_unpaused: confirms request panics when contract is not paused. - test_emergency_withdraw_blocked_before_7_days: confirms execute panics when called before the 7-day delay elapses. - test_emergency_withdraw_succeeds_after_7_days: confirms full balance is transferred to destination after pause + 7-day delay.
|
@Idaonoli 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.
Summary
Implements two new contract features and resolves pre-existing compilation errors that had accumulated across recent PRs.
closes #232 — Invoice payment event replay for indexer recovery
replay_invoice_events(invoice_id)is a pure read+emit function callable by anyone. It re-emits the full historical event sequence for an invoice so an offline indexer can resync from a single call:invoice_created(replay) eventpayment_received(replay) event per entry ininvoice.payments, in original orderinvoice_releasedorinvoice_refunded, replay) when the invoice is no longer Pendingreplaytopic so indexers can distinguish them from live events and skip double-counting.closes #233 — Contract-wide emergency withdrawal
EmergencyWithdraw(Address, Address)added toTimelockAction.request_emergency_withdraw(admin, token, destination)— requires SuperAdmin auth and the contract to already be paused. Queues the withdrawal in the existing timelock system and returns theaction_id.execute_actionhandles the new variant with two additional guards beyond the normal timelock check:timelock_secs)destinationand emitsemergency_withdrawal_executed(token, destination, amount).Pre-existing compilation fixes
Several earlier PRs left the codebase in a non-compiling state. These are fixed minimally as a prerequisite:
types.rs: removed duplicatemin_funding_amount,priorities, andadmin_frozenfields fromInvoice; added missingcreation_timestampandmin_payment_incrementtoInvoiceExt2so they round-trip through storage; wiredexternal_prerequisitethroughInvoice::split,Invoice::assemble, andInvoice::from_legacy.events.rs: removed eight duplicate function definitions (each function appeared twice with slightly different event symbol names).lib.rs: removed a duplicateSHARD_COUNTconstant, two redundantrequire_adminfunction definitions, a duplicateadmin_frozenfield assignment inclone_invoice, and updated all bareInvoiceExt2default literals to include the new fields.test.rs: added missingexternal_prerequisite: Noneto theinvoice_optionshelper.Test plan
test_replay_invoice_events_pending— confirms 2 replay events for a Pending invoice (created + 1 payment, no terminal event)test_replay_invoice_events_released— confirms 4 replay events for a Released invoice (created + 2 payments + released)test_emergency_withdraw_blocked_when_unpaused— request panics when contract is activetest_emergency_withdraw_blocked_before_7_days— execute panics before the 7-day delay elapsestest_emergency_withdraw_succeeds_after_7_days— full balance transferred to destination after pause + 7-day delay, balance verified on both sidescargo clippypasses with zero warningsCloses #232
Closes #233
Closes #234
Closes #235