feat: preview_payout and get_invoices_by_creator contract functions - #32
Merged
Conversation
### preview_payout(invoice_id, amount) -> Vec<i128> Pure read function that returns exact per-recipient payout amounts for a given payment, using identical proportional + dust logic as _release. Useful for UI payout preview before signing. - Supports Fixed, Percentage, and Tiered split rules - Last recipient always gets the dust remainder (same as _release) - Checked arithmetic throughout (CAP-82 safe) ### get_invoices_by_creator(creator) -> Vec<u64> On-chain creator index: returns all invoice IDs created by a given address. - Updated on every create_invoice, create_batch, and create_recurring call - Stored as Vec<u64> per creator address in persistent storage - TTL extended to ~1 year on every append - Fixes dashboard pagination (no more scanning IDs 1–20) ### Tests Added 10 new tests covering: - Preview payout: proportional, dust handling, percentage rules, single recipient - Creator index: empty state, single/multiple invoices, isolation per creator, batch + recurring inclusion All 34 tests passing. Closes #31
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
Two new read/index functions that close important UX gaps.
preview_payout(invoice_id: u64, amount: i128) -> Vec<i128>Pure read: returns exact per-recipient amounts for a given payment amount.
_release— last recipient gets remainderUse case: Show payers a precise breakdown before they sign the transaction.
get_invoices_by_creator(creator: Address) -> Vec<u64>On-chain creator index: returns all invoice IDs created by a given address.
create_invoice,create_batch,create_recurringcallVec<u64>in persistent storage per creatorUse case: Dashboard pagination. Instead of scanning sequential IDs 1–20, query the creator's full list directly.
Tests
Added 10 new tests:
All 34 tests passing.
Changes
contracts/sharpy/src/lib.rs— added storage key helper, indexing helper, two new public functions, index writes in all three create functionscontracts/sharpy/src/test.rs— 10 new test casesCloses #31