-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandalone.py
104 lines (78 loc) · 2.65 KB
/
standalone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Standalone version simple electrum client.
# compatible: Electrum==3.3.8. please download it from official releases.
# Please set log address and texts you want to upload
log_address = "tb1..."
text_to_upload = set(open("texts.txt").read().split('\n'))
import os
import sys
import asyncio
import time
from electrum.simple_config import SimpleConfig
from electrum import constants
from electrum.daemon import Daemon
from electrum.storage import WalletStorage
from electrum.wallet import Wallet, create_new_wallet
from electrum.commands import Commands, known_commands
from electrum.network import filter_protocol, Network
from electrum.util import create_and_start_event_loop, log_exceptions
from electrum.simple_config import SimpleConfig
# use ~/.electrum/testnet as datadir
config = SimpleConfig({"testnet": True, "fee_per_kb": 10000, "dynamic_fees": False})
# set testnet magic bytes
constants.set_testnet()
# set up daemon
daemon = Daemon(config, listen_jsonrpc=False)
network = daemon.network
# get wallet on disk
wallet_dir = os.path.dirname(config.get_wallet_path())
print("Wallet dir: "+ wallet_dir)
wallet_path = os.path.join(wallet_dir, "wallet_lib")
if not os.path.exists(wallet_path):
create_new_wallet(path=wallet_path, segwit=True)
# open wallet
storage = WalletStorage(wallet_path)
wallet = Wallet(storage)
wallet.start_network(network)
# set up commands
commands = Commands(config, wallet=wallet, network=network)
def create_func(key):
def f(*args):
return commands._run(key, args, lambda: "")
return f
command_set = {}
for k in known_commands.keys():
command_set[k] = create_func(k)
import elm
import el
getaddresshistory = command_set['getaddresshistory']
gettransaction = command_set['gettransaction']
getbalance = command_set['getbalance']
import random
def wait_until_confirmed():
while "unconfirmed" in getbalance():
print("wait until confirm: " + str(getbalance()))
time.sleep(10)
# wait_until_confirmed()
for text in text_to_upload:
time.sleep(10)
print(getbalance())
data_uploaded = set()
history = getaddresshistory(log_address)
for h in history:
txid = h['tx_hash']
tx = gettransaction(txid)
(_, tx_parsed) = el.getTransaction(bytes.fromhex(tx['hex']))
try:
data = elm.elm_getdata(tx_parsed)
data_uploaded.add(data)
except Exception as e:
print("Parse Error: " + str(e))
if text.encode() in data_uploaded:
continue
print(text)
current_target = text
try:
elm.elm_sig(command_set, current_target, log_address)
except Exception as e:
print(e)
print("finished!")