From 45828e675f539d952b8b126dc853f7cc5feb2a5d Mon Sep 17 00:00:00 2001 From: hannes Date: Wed, 6 May 2026 13:36:42 +0000 Subject: [PATCH] initial commit --- main.py | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..0ca6552 --- /dev/null +++ b/main.py @@ -0,0 +1,104 @@ +#!pip install bitcoin +!pip install cryptos +from cryptos import * +#from bitcoin import * + +import requests, json, sqlite3, time + +c = Bitcoin(testnet=False) + +######################################################################### +# Alle Wallets aus der DB Laden und in ein set umwandeln +######################################################################### + +conn = sqlite3.connect('datenbank.db') +cursor = conn.cursor() +select_query = "SELECT id, pw, priv, pub, addr FROM buche" +cursor.execute(select_query) +results = cursor.fetchall() +conn.commit() +conn.close() +print(len(results)) + +seta = set() +for i in results: + seta.add(i[4]) +print(len(seta)) + + +######################################################################### +# Transaktion erstellen +######################################################################### + +def maketx(wallet, fee=0): + + inputs = json.loads(requests.get("http://192.168.178.225:5001/api/guthaben/" + wallet["addr"]).text) + + inputs = inputs["utxos"] + value = 0 + for i in inputs: + value += i["value"] + i["address"]=wallet["addr"] + + fee = int(value * 0.4) + + outs = [{'value': value-fee, 'address': "1KHzkdXjQiUEiME1w7UKfdTmZGSeVVBGEJ"}] +# outs = [{'value': value-225, 'address': "19yXEybUuNgKAreD23mCseKJ3iL8PhQazf"}] + print(inputs) + + tx = c.mktx(inputs,outs) + tx2 = c.signall(tx, wallet["priv"]) + tx3 = serialize(tx2) + + response = requests.post( + "http://192.168.178.225:5001/api/sendtx", + json={"hex": tx3} + ) + + print(response.json()) + +######################################################################### +# Wallet Daten laden +######################################################################### + +def getwallet(addr): + conn = sqlite3.connect('datenbank.db') + cursor = conn.cursor() + sql = "SELECT * FROM buche WHERE addr = ?;" + cursor.execute(sql, (addr,)) + + # 4. Alle Ergebnisse abrufen + ergebnisse = cursor.fetchall() + conn.close() + wallet = {"pw":ergebnisse[0][1],"priv":ergebnisse[0][2],"pub":ergebnisse[0][3],"addr":ergebnisse[0][4]} + return wallet + +######################################################################### +# Neue Blocks auf Transaktionen prüfen +######################################################################### + +last_block = 0 +while True: + current_block = json.loads(requests.get("http://192.168.178.225:5001/api/blockhoehe").text)["blockhoehe"] + if not last_block == current_block: + setb = set() + last_block = current_block + print(f"neuer Block {str(current_block)}") + block = json.loads(requests.get("http://192.168.178.225:5001/api/block/" + str(current_block)).text) + + for tx in block["block"]["tx"]: + for out in tx["vout"]: + try: + setb.add(out["scriptPubKey"]["address"]) + except: + pass + setc = seta & setb + + if len(setc)>0: + for w in setc: + print(w) + if not w == "1EGk65oe8au7VUkvf3qapFKvE9LJzMW6go": + maketx(getwallet(w)) + else: + pass + time.sleep(0.5) \ No newline at end of file