[WIP] feat: replace accounting service with MPP (Machine Payments Protocol)#326
Draft
[WIP] feat: replace accounting service with MPP (Machine Payments Protocol)#326
Conversation
Replace the old external accounting service with MPP/Tempo blockchain payments across Hub backend, aggregator, frontend, and TypeScript SDK. Backend: - New wallet endpoints: create, import, update, balance, transactions, pay - Tempo blockchain queries via Web3 (balance + transaction history) - wallet_address + wallet_private_key on UserModel (private key excluded from all API response schemas) - Structured error codes in /pay: INSUFFICIENT_BALANCE, BLOCKCHAIN_TIMEOUT, INVALID_CHALLENGE, CHALLENGE_TOO_LARGE - Duplicate wallet creation guard - Removed: accounting_client.py, accounting endpoints, accounting config, accounting exceptions, accounting registration flow Aggregator: - 402 payment handler: aggregator gets 402 from Syft Space → calls Hub /wallet/pay → retries with X-Payment header - Shared mpp_payment.py helper for data_source and model clients - user_token replaces transaction_tokens in ChatRequest - payment_failed status for clear error propagation Frontend: - WalletProvider context replaces AccountingProvider - Wallet settings tab (create/import/manage wallet) - Balance indicator with "Set up wallet" nudge - Transaction display with wallet address truncation - Removed: accounting context, hooks, queries, types SDK (TypeScript): - AccountingResource rewritten with wallet methods - Chat flow sends user_token instead of transaction_tokens - getTransactionTokens() deprecated (no-op)
When the aggregator can't reach a Syft Space endpoint, show the URL that failed and suggest checking the public URL in Settings.
- Clear wallet_private_key when updating address via PUT /wallet
- Fix frontend sending {address} instead of {wallet_address}
- Fix transaction direction by comparing against wallet address
- Add TODOs for NATS tunnel MPP and PAT auth gaps
- Removed address-only update endpoint (no use case without private key) - Removed UpdateWalletAddressRequest schema, frontend method, SDK method - "Change Wallet" UI replaced with "Import Different Wallet" - Transaction direction now compares wallet addresses only (no email) - walletAddress is required prop on TransactionItem/TransactionList
- Remove unused transaction_token param from aggregator clients - Run ruff format on wallet.py and exceptions.py - Remove eslint-disable comment from wallet-context.tsx - Update backend-test CI matrix from [3.10, 3.11, 3.12] to [3.12, 3.13]
- Format aggregator model.py with ruff - Add mypy override for mpp.* (uses Python 3.12+ type syntax) - Remove test_get_accounting_credentials (endpoint was deleted)
6410137 to
0c8ef2e
Compare
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.
Summary
Replaces the old external accounting service with MPP (Machine Payments Protocol) using the Tempo blockchain. Changes span Hub backend, aggregator, frontend, and TypeScript SDK.
Backend
/api/v1/wallet/*endpoints: create, import, update, balance, transactions, paytempo_utils.py)wallet_address+wallet_private_keyon UserModelwallet_private_keyexcluded from all API response schemas/pay:INSUFFICIENT_BALANCE,BLOCKCHAIN_TIMEOUT,INVALID_CHALLENGE,PAYMENT_FAILEDaccounting_client.py, accounting endpoints, accounting config, accounting exceptions, accounting registration flowAggregator
/wallet/pay→ retry withX-Paymentmpp_payment.pyhelperuser_tokenreplacestransaction_tokensinChatRequestpayment_failedstatus with specific error messagesFrontend
WalletProviderreplacesAccountingProviderTypeScript SDK
AccountingResourcerewritten with wallet methodsuser_tokeninstead oftransaction_tokensTODOs
/payendpoint, aggregator 402 retry, SDK chat flow.sdk/python/still has old accounting methods.sdk/golang/still has old accounting methods./payendpoint — Per-user rate limiting to prevent runaway 402 payment loops when wallet has insufficient funds.VerificationErrorfrom MPP SDK, so "insufficient funds" becomes a generic 500 instead of a meaningful error (Syft Space side fix).Test plan
/api/v1/accounting/*endpoints return 404/api/v1/wallet/*endpoints workwallet_private_keynot in any API response