Skip to content

feat: preview_payout and get_invoices_by_creator contract functions - #32

Merged
MarcusDavidG merged 1 commit into
mainfrom
feat/preview-payout-creator-index
Aug 10, 2026
Merged

feat: preview_payout and get_invoices_by_creator contract functions#32
MarcusDavidG merged 1 commit into
mainfrom
feat/preview-payout-creator-index

Conversation

@MarcusDavidG

Copy link
Copy Markdown
Contributor

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.

  • Uses identical proportional + dust logic as _release — last recipient gets remainder
  • Supports Fixed, Percentage, and Tiered split rules
  • Checked arithmetic throughout (CAP-82)
  • No state modification — safe to call from anywhere

Use 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.

  • Appended on every create_invoice, create_batch, create_recurring call
  • Stored as Vec<u64> in persistent storage per creator
  • TTL extended to ~1 year on every write

Use case: Dashboard pagination. Instead of scanning sequential IDs 1–20, query the creator's full list directly.

Tests

Added 10 new tests:

  • Preview: proportional split, dust handling, percentage rules, single recipient
  • Creator index: empty state, single/multiple invoices, isolation, batch + recurring inclusion

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 functions
  • contracts/sharpy/src/test.rs — 10 new test cases

Closes #31

### 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
@MarcusDavidG
MarcusDavidG merged commit 3e28765 into main Aug 10, 2026
1 check failed
@MarcusDavidG
MarcusDavidG deleted the feat/preview-payout-creator-index branch August 10, 2026 11:35
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.

Add preview_payout and get_invoices_by_creator contract functions

1 participant