Skip to content

Implement invoice clone SDK method with optimistic UI state, rollback, and clone chain resolver #183

@Kingsman-99

Description

@Kingsman-99

Description

Build a full cloneInvoice SDK feature that includes: submitting the clone contract call, optimistic local state update, automatic rollback on failure, and a resolveCloneChain method that fetches the full lineage of cloned invoices.

Acceptance Criteria

  • StellarSplitClient.cloneInvoice(sourceId: string, overrides: CloneOverrides): Promise<string> — submits the clone_invoice contract call and returns the new invoice ID
  • CloneOverrides TypeScript type mirrors the contract struct: newDeadline?: number, newAmounts?: bigint[], newRecipients?: string[], newOverflowBehavior?: OverflowBehavior
  • On submission failure, any optimistic cache entry written during the call must be rolled back
  • resolveCloneChain(invoiceId: string): Promise<Invoice[]> — recursively fetches parent invoices via parent_invoice_id from get_invoice_ext until root is reached; returns array ordered root→leaf
  • resolveCloneChain must handle cycles defensively (max depth 10, throws "clone chain depth exceeded")
  • Both methods exported from src/index.ts with full TypeScript types
  • cloneInvoice uses the existing retry logic from src/client.ts
  • Tests cover: successful clone, failed clone with rollback verification, chain resolution with 3-deep lineage, cycle detection

Context

  • Contract call pattern is in src/client.ts — follow pay() as reference for retry + submission
  • src/types.ts needs CloneOverrides and updated InvoiceExt with parentInvoiceId and cloneDepth
  • Cache rollback pattern should follow any existing cache invalidation in src/cache.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgrantfoxIssue for GrantFox program

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions