Bitcoin Agent Rolling Spending Windows
Bitcoin Agent Rolling Spending Windows
Design and trust boundary
Count settled debits within the rolling interval and all unresolved reservations regardless of age. An uncertain broadcast must never disappear merely because a window elapsed. Use trusted timestamps and serialize reservation with the decision.
Independent reference implementation
1"""Offline educational example; no wallet calls."""
2def available(now, window, ceiling, settled, pending):
3 if any(type(x) is not int or x <= 0 for x in (window, ceiling)):
4 raise ValueError("invalid policy")
5 if any(type(t) is not int or t > now or type(a) is not int or a <= 0 for t,a in settled) or any(type(a) is not int or a <= 0 for a in pending):
6 raise ValueError("invalid ledger")
7 return max(0, ceiling - sum(a for t,a in settled if now-window < t <= now) - sum(pending))
8
9assert available(100, 20, 1000, [(80, 200), (81, 300)], [400]) == 300
10assert available(1000, 20, 1000, [], [400]) == 600Operational boundaries
All amounts are integer satoshis. This offline example assumes trusted policy inputs and does not authenticate a caller or execute SEND. Production requires durable state, exact intent binding, stable idempotency and reconciliation of uncertain broadcasts. The external policy must not modify the immutable wallet fee law.
Related research
https://thamer.org/learn/bitcoin-for-ai-agents-open-integration-guide
https://thamer.org/api
