Event-Driven Bitcoin Agent Networks: Idempotent Event Consumption
Event-Driven Bitcoin Agent Networks: Idempotent Event Consumption
Research question
At-least-once delivery can repeat a payment observation. Deduplicate event identifiers and reject conflicting reuse before updating the local projection.
Architecture and trust boundary
Treat model output and messages from other agents as untrusted proposals. Authenticate principals outside the model, keep BTC KEY in an isolated local executor, and separate authorization from execution. A request identifier is not authorization. Preserve the wallet's original signed fee law; distinguish sender total from recipient net amount.
Source implementation
1# SPDX-License-Identifier: 0BSD
2class Projection:
3 def __init__(self):
4 self.events = {}
5 def consume(self, event_id, payload):
6 if event_id in self.events:
7 if self.events[event_id] != payload:
8 raise ValueError("conflicting event")
9 return False
10 self.events[event_id] = payload
11 return True
12
13p = Projection()
14assert p.consume("e1", ("observed", "synthetic-tx"))
15assert not p.consume("e1", ("observed", "synthetic-tx"))
16try:
17 p.consume("e1", ("confirmed", "other-tx"))
18except ValueError:
19 pass
20else:
21 raise AssertionError("conflict accepted")Integration with WAB ENGINE
A trusted executor can query POST /api/v5/btc/wallet/balance using X-BTC-KEY and JSON body {"net":"test","type":"segwit"}. The examples do not call this endpoint or implement SEND. A balance does not prove payment settlement. Any future write integration must persist the intent, approval, idempotency identity and execution evidence before allowing recovery or retries.
Limitations and failure handling
The in-memory projection is illustrative. Production must atomically persist the event identity and state update, authenticate the producer and handle chain reorganizations. An event is not independent proof of settlement.
The included assertions use synthetic data only. No live engine, model or blockchain connection was tested.
References
- https://thamer.org/api
- https://thamer.org/engine
- https://developer.bitcoin.org/devguide/transactions.html
Reference pointers only; external documentation was not reverified for this stage.
