forked from etotheipi/BitcoinArmory
-
Notifications
You must be signed in to change notification settings - Fork 11
/
connector.py
61 lines (45 loc) · 1.62 KB
/
connector.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
from twisted.internet.protocol import Protocol, ClientFactory
from twisted.internet.defer import Deferred
from twisted.internet import reactor
from armoryengine import *
btcNetFactory = None
class ConMain:
def __init__(self):
self.wallets = []
self.do_not_broadcast = False
def addWallet(self, wallet):
self.wallets.append(wallet)
def broadcastTransaction(self, tx):
if not self.do_not_broadcast:
btcNetFactory.sendTx(tx)
TheBDM.addNewZeroConfTx(tx.serialize(), long(RightNow()), True)
for w in self.wallets:
TheBDM.rescanWalletZeroConf(w.cppWallet)
def init():
engine_set_main(ConMain())
BDM_LoadBlockchainFile()
mempoolfile = os.path.join(ARMORY_HOME_DIR,'mempool.bin')
TheBDM.enableZeroConf(mempoolfile)
def register_wallet(wlt):
get_main().addWallet(wlt)
TheBDM.registerWallet( wlt.cppWallet )
def lost():
print "lost"
def made_connect():
print "made connect"
def newtx(tx):
print "got new tx:"
tx.pprint()
def run(run_after_handshake=None):
global btcNetFactory
def after_handshake(proto):
print "after handshake"
if run_after_handshake:
run_after_handshake()
btcNetFactory = ArmoryClientFactory(def_handshake=after_handshake,
func_madeConnect=made_connect,
func_newTx=newtx,
func_loseConnect=lost)
reactor.callWhenRunning(reactor.connectTCP, '127.0.0.1', BITCOIN_PORT, \
btcNetFactory)
reactor.run()