-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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
Invoiceis automatically created including some data for enabling the transaction watcher find the extrinsic. - A user submits the
balance.Transfertransaction 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
Invoicewith fields:invoiceId,userPublicId,productId,numCreditsextrinsic_hash,last_seen_block, for tracking the extrinsic (last_seen_blockwould help during re-orgs)status(pending/paid/expired),createdAt,expiresAt
- UI instructs the user to transfer the exact amount from
payerAddressto the treasury address on the specified chain.
- Create
-
Finality and event listening
- Subscribe to finalised blocks; scan
balances.Transferwheredest == TREASURY_ADDRESS. - Match events to invoices using
(from == payerAddress) AND (amount == expectedAmountPlanck). - Accept only on finalised blocks (or finalised + X confirmations as configured).
- Subscribe to finalised blocks; scan
-
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 == pendingand not already processed by(extrinsic_hash)uniqueness. - Mark
invoice.status = paid, record chain refs. - Add service.
- Commit.
- On finalized match
Metadata
Metadata
Assignees
Labels
No labels