Skip to content

Payment Monitor System #467

@clostao

Description

@clostao

In high level for buying credits the user will create a Transfer transaction, using the extrinsic hash will create an invoice, and the submit the transaction. The invoice would expire if the payment is not received within a number of blocks. When the invoice is marked as 'paid' their subscription will be updated with the additional credits.

Implementation details

  • Core design
    • A user requests the API for conversation rate between $AI3 and credits (measured in bytes).
    • Through our frontend, when the transaction is created an Invoice is automatically created including some data for enabling the transaction watcher find the extrinsic.
    • A user submits the balance.Transfer transaction with a selected amount targeting a number of upload credits.

Note: Probably this could be implemented in @autonomys/auto-drive to ease this integration

  • Invoice creation

    • Create Invoice with fields:
      • invoiceId, userPublicId, productId, numCredits
      • extrinsic_hash, last_seen_block, for tracking the extrinsic (last_seen_block would help during re-orgs)
      • status (pending/paid/expired), createdAt, expiresAt
    • UI instructs the user to transfer the exact amount from payerAddress to the treasury address on the specified chain.
  • Finality and event listening

    • Subscribe to finalised blocks; scan balances.Transfer where dest == TREASURY_ADDRESS.
    • Match events to invoices using (from == payerAddress) AND (amount == expectedAmountPlanck).
    • Accept only on finalised blocks (or finalised + X confirmations as configured).
  • Operations and safety

    • Automatic expiry and clean-up of unpaid invoices.
    • Wrap payment with enhanced observability tools.
  • Processing flow

    • On finalized match (dest == TREASURY_ADDRESS) && (extrinsic_hash = invoice.extrinsic_hash):
      • Begin DB transaction.
      • Verify invoice.status == pending and not already processed by (extrinsic_hash) uniqueness.
      • Mark invoice.status = paid, record chain refs.
      • Add service.
      • Commit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions