a2a-Market Compute Ledger
Build and operate the compute ledger module for RealMarket A2A runtime.
Current status: scaffold-first skill for early registration. Keep APIs stable, add production logic incrementally.
Scope
- - Own
ComputeAccount domain object, balance snapshots, and immutable transaction journal. - Support reserve/freeze before negotiation and final debit after order confirmation.
- Emit billing events to event bus for reputation, websocket push, and finance logs.
Suggested Project Layout
- - INLINECODE1
- INLINECODE2
- INLINECODE3
- INLINECODE4
Minimum Contracts (MVP P0)
- 1.
freeze(account_id, amount, reason) returns hold id and expiry. - INLINECODE6 converts hold to settled charge.
- INLINECODE7 unlocks unused balance.
- INLINECODE8 returns ordered journal records.
Event Mapping
- - On hold created: emit
INTENT_CREATED + billing extension payload. - On charge captured: emit
ORDER_CREATED and settlement payload. - On charge finalized: emit
PAYMENT_SUCCEEDED.
Guardrails
- - Use integer minor units for money; avoid float math.
- Enforce idempotency key on every mutating operation.
- Keep journal append-only; never rewrite posted entries.
Implementation Backlog
- - Add double-entry validation rules.
- Add monthly statement export and audit tooling.
Runtime Implementation
- - Status: implemented in local runtime package.
- Primary code paths:
- INLINECODE12
- Validation: covered by
runtime/tests and npm test in runtime/.
技能名称: a2a-market-compute-ledger
详细描述:
a2a市场计算账本
为RealMarket A2A运行时构建并运行计算账本模块。
当前状态:用于早期注册的脚手架优先技能。保持API稳定,逐步添加生产逻辑。
范围
- - 拥有ComputeAccount领域对象、余额快照和不可变交易日志。
- 支持协商前的预留/冻结以及订单确认后的最终扣款。
- 将计费事件发送到事件总线,用于信誉、WebSocket推送和财务日志。
建议项目结构
- - app/domain/entities/computeaccount.py
- app/application/services/billingservice.py
- app/infrastructure/db/ledgerrepository.py
- app/infrastructure/tasks/reconcileledger.py
最小合约(MVP P0)
- 1. freeze(accountid, amount, reason) 返回持有ID和过期时间。
- capturehold(holdid, orderid) 将持有转换为已结算费用。
- releasehold(holdid) 解锁未使用的余额。
- listledgerentries(accountid, fromts, to_ts) 返回有序的日志记录。
事件映射
- - 创建持有时:发出INTENTCREATED及计费扩展负载。
- 捕获费用时:发出ORDERCREATED及结算负载。
- 费用最终确定时:发出PAYMENT_SUCCEEDED。
防护措施
- - 使用整数最小单位表示金额;避免浮点运算。
- 对每个变更操作强制执行幂等键。
- 保持日志仅追加;绝不重写已发布的条目。
实施待办事项
- - 添加复式记账验证规则。
- 添加月度报表导出和审计工具。
运行时实现
- - 状态:已在本地运行时包中实现。
- 主要代码路径:
- runtime/src/domain/compute-ledger.js
- 验证:由runtime/tests和runtime/中的npm test覆盖。