THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

How to Track Bitcoin Donations Without Double Counting

permalink THAMER
#bitcoin#donations#python#website

Donation totals should be derived from verified transaction outputs rather than page visits or payment claims.

Implementation approach

Consume trusted chain observations keyed by network, txid and output index. Match the destination to the donation address. Recompute confirmed totals after reorg updates; this example assumes an ordered trusted observation stream and does not query Bitcoin Core. Unconfirmed amounts are not final.

Source code

Python · 20 lines
1import re
2
3class Tracker:
4    def __init__(self, network, address):
5        self.network, self.address, self.outputs = network,address,{}
6    def observe(self, network, txid, vout, address, sats, confirmations):
7        if network != self.network or address != self.address: return False
8        if not re.fullmatch('[0-9a-f]{64}',txid) or type(vout) is not int or vout < 0 or type(sats) is not int or sats <= 0 or type(confirmations) is not int:
9            raise ValueError('invalid observation')
10        key=(network,txid,vout)
11        if key in self.outputs and self.outputs[key][0] != sats: raise ValueError('output conflict')
12        self.outputs[key]=(sats,confirmations)
13        return True
14    def total(self):
15        return sum(s for s,c in self.outputs.values() if c >= 1)
16
17if __name__ == '__main__':
18    t=Tracker('test','fixture'); args=('test','a'*64,0,'fixture',500)
19    t.observe(*args,1); t.observe(*args,1); assert t.total()==500
20    t.observe(*args,0); assert t.total()==0

Local validation

Run stage23-donation-tracking.py with Python 3. Fixtures are not valid Bitcoin addresses. This is an educational example, not a production donation service. No SEND operation is included.

Related documentation

https://thamer.org/api

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects