Skip to content

feat: implement atomic batch invoice minting for SMEs#342

Open
CodedMumu wants to merge 1 commit into
OpenLedger-Foundation:mainfrom
CodedMumu:feature/sme-batch-invoice-minting
Open

feat: implement atomic batch invoice minting for SMEs#342
CodedMumu wants to merge 1 commit into
OpenLedger-Foundation:mainfrom
CodedMumu:feature/sme-batch-invoice-minting

Conversation

@CodedMumu

Copy link
Copy Markdown
Contributor

Adds mint_invoices_batch(sme, Vec) -> Vec to invoice_nft, allowing SMEs to tokenize a backlog of receivables in a single transaction with all-or-nothing semantics.

Implementation details:

  • BatchInvoiceInput contracttype struct with the same fields as mint_invoice (debtor_hash, amount, currency, due_date, ipfs_cid, risk_score, notes)
  • Phase 1 validates ALL entries before any storage write — any invalid entry aborts the entire batch (atomic-abort)
  • Phase 2 mints each invoice, reusing the same per-invoice logic as mint_invoice (validation, Invoice struct construction, TTL bump, invoice_created event)
  • Single require_auth() covers the whole batch (gas-efficient)
  • NextId advanced atomically after all mints succeed

Tests (contracts/tests/src/lib.rs):

  • test_batch_mint_success: 3 valid invoices → IDs [1,2,3], all Created
  • test_batch_mint_atomic_abort_on_invalid_input: zero-amount entry aborts; next_id stays at 1
  • test_batch_mint_invalid_risk_score_aborts: risk_score 101 aborts

Closes #271

Adds mint_invoices_batch(sme, Vec<BatchInvoiceInput>) -> Vec<u64> to
invoice_nft, allowing SMEs to tokenize a backlog of receivables in a
single transaction with all-or-nothing semantics.

Implementation details:
- BatchInvoiceInput contracttype struct with the same fields as
  mint_invoice (debtor_hash, amount, currency, due_date, ipfs_cid,
  risk_score, notes)
- Phase 1 validates ALL entries before any storage write — any
  invalid entry aborts the entire batch (atomic-abort)
- Phase 2 mints each invoice, reusing the same per-invoice logic as
  mint_invoice (validation, Invoice struct construction, TTL bump,
  invoice_created event)
- Single require_auth() covers the whole batch (gas-efficient)
- NextId advanced atomically after all mints succeed

Tests (contracts/tests/src/lib.rs):
- test_batch_mint_success: 3 valid invoices → IDs [1,2,3], all Created
- test_batch_mint_atomic_abort_on_invalid_input: zero-amount entry
  aborts; next_id stays at 1
- test_batch_mint_invalid_risk_score_aborts: risk_score 101 aborts

Closes #
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@CodedMumu 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! 🚀

Learn more about application limits

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.

Implement SME batch invoice minting

1 participant