|
@ -28,18 +28,19 @@ class SPV(ThreadJob): |
|
|
def __init__(self, network, wallet): |
|
|
def __init__(self, network, wallet): |
|
|
self.wallet = wallet |
|
|
self.wallet = wallet |
|
|
self.network = network |
|
|
self.network = network |
|
|
self.merkle_roots = {} # hashed by me |
|
|
# Keyed by tx hash. Value is None if the merkle branch was |
|
|
self.requested_merkle = set() |
|
|
# requested, and the merkle root once it has been verified |
|
|
|
|
|
self.merkle_roots = {} |
|
|
|
|
|
|
|
|
def run(self): |
|
|
def run(self): |
|
|
unverified = self.wallet.get_unverified_txs() |
|
|
unverified = self.wallet.get_unverified_txs() |
|
|
for (tx_hash, tx_height) in unverified: |
|
|
for (tx_hash, tx_height) in unverified: |
|
|
if tx_hash not in self.merkle_roots and tx_hash not in self.requested_merkle: |
|
|
if tx_hash not in self.merkle_roots: |
|
|
request = ('blockchain.transaction.get_merkle', |
|
|
request = ('blockchain.transaction.get_merkle', |
|
|
[tx_hash, tx_height]) |
|
|
[tx_hash, tx_height]) |
|
|
if self.network.send([request], self.merkle_response): |
|
|
if self.network.send([request], self.merkle_response): |
|
|
self.print_error('requested merkle', tx_hash) |
|
|
self.print_error('requested merkle', tx_hash) |
|
|
self.requested_merkle.add(tx_hash) |
|
|
self.merkle_roots[tx_hash] = None |
|
|
|
|
|
|
|
|
def merkle_response(self, r): |
|
|
def merkle_response(self, r): |
|
|
if r.get('error'): |
|
|
if r.get('error'): |
|
|