feat: Clone Factory, Registry, Metadata Hash & Event Sequence Numbers - #549
Open
Sundriveauto wants to merge 5 commits into
Open
feat: Clone Factory, Registry, Metadata Hash & Event Sequence Numbers#549Sundriveauto wants to merge 5 commits into
Sundriveauto wants to merge 5 commits into
Conversation
…contract deployment Implement a clone factory pattern in contracts/factory/ that deploys minimal-proxy clones pointing to a single canonical WASM blob. - deploy_invoice_contract(creator, wasm_hash, salt, init_args) using env.deployer().with_current_contract(salt) - Reject duplicate salts per creator - Emit ContractDeployed(creator, contract_address) event - Per-creator deploy limit (10k) to prevent DoS - Registration in DeployedContracts(creator) persistent storage - Added to workspace Cargo.toml as new member Issue: Clone Factory Pattern
Create contracts/registry/ as a new workspace member that maintains a searchable map from creator address to their list of deployed split contract addresses. - register(creator, contract) appends to creator's list - get_contracts(creator) returns all registered addresses - Duplicate registrations for same contract address rejected - Per-creator limit (5k) to bound storage and prevent DoS - ContractRegistered(creator, contract) event emitted - is_registered(creator, contract) query helper Issue: Registry Contract
Store a 32-byte hash (IPFS CID / SHA-256) with each invoice so clients can retrieve extended details without inflating on-chain storage. - Add metadata_hash: Option<BytesN<32>> to InvoiceCore struct - Add field to Invoice struct and invoice assembly/disassembly - Populate metadata_hash in load_invoice from persistent storage - create_invoice already accepts and stores optional 32-byte hash - get_invoice now returns the metadata_hash field via InvoiceCore - update_metadata_hash rejects updates on Finalised/Cancelled invoices - MetadataHashUpdated event already emitted on successful update Issue: Metadata Hash
Each emitted event now carries a monotonically increasing event_seq field to allow indexers to detect and discard duplicates. - Add next_seq(env, invoice_id) helper using storage::temporary - Counter resets automatically between transactions - Sequence is scoped per invoice (independent counters) - Event data tuples append event_seq as the last field - Key invoice-scoped events updated: invoice_created, payment_received, payment_committed, milestone_released, surplus_claimed, invoice_released, invoice_refunded, condition_verified, invoice_expired, recipient_whitelisted, recipient_removed_from_whitelist, payer_refunded, recipient_added, split_adjusted, recipients_rebalanced, invoice_archived Issue: Event Sequence Numbers
feat: Clone Factory, Registry, Metadata Hash & Event Sequence Numbers
|
@Sundriveauto 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.
Closes #494
Closes #495
Closes #496
Closes #497
Summary
This PR implements four features to improve StellarSplit's contract deployment, discovery, storage efficiency, and event reliability.
1. Clone Factory Pattern (
contracts/factory/)Deploying a fresh WASM instance per invoice is gas-intensive. A clone factory pattern deploys minimal-proxy clones pointing to a single canonical WASM blob.
deploy_invoice_contract(creator, wasm_hash, salt, init_args)usingenv.deployer().with_current_contract(salt)ContractDeployed(creator, contract_address)event emittedCargo.tomlupdated with new member2. Registry Contract (
contracts/registry/)An on-chain index of all deployed split contract instances for frontend discovery.
register(creator, contract)appends contract to creator's listget_contracts(creator)returns all registered addressesContractRegistered(creator, contract)event emittedis_registered()andget_contract_count()query helpers3. Metadata Hash (InvoiceCore)
Storing full invoice descriptions on-chain is expensive. A 32-byte hash (IPFS CID / SHA-256) is now stored with each invoice.
metadata_hash: Option<BytesN<32>>added toInvoiceCoreandInvoicestructscreate_invoiceviaInvoiceOptions2get_invoicereturns the metadata_hash fieldupdate_metadata_hashrejects updates on Finalised/Cancelled invoices (creator-only)MetadataHashUpdatedevent emitted on every successful update4. Event Sequence Numbers
Under certain conditions the same event could be emitted multiple times, confusing indexers. Each event now carries a monotonically increasing sequence number.
event_seq: u64field appended to all invoice-scoped event data tuplesstorage::temporary— resets between transactionsnext_seq()helper computes the next value atomicallyinvoice_created,payment_received,invoice_released,invoice_refunded, and moreCI Checks
All CI checks target:
cargo build --target wasm32-unknown-unknowncargo testcargo clippy