|
@ -26,7 +26,7 @@ from bitcoin import * |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TxVerifier(util.DaemonThread): |
|
|
class SPV(util.DaemonThread): |
|
|
""" Simple Payment Verification """ |
|
|
""" Simple Payment Verification """ |
|
|
|
|
|
|
|
|
def __init__(self, network, storage): |
|
|
def __init__(self, network, storage): |
|
@ -95,7 +95,7 @@ class TxVerifier(util.DaemonThread): |
|
|
continue |
|
|
continue |
|
|
if self.merkle_roots.get(tx_hash) is None and tx_hash not in requested_merkle: |
|
|
if self.merkle_roots.get(tx_hash) is None and tx_hash not in requested_merkle: |
|
|
if self.network.send([ ('blockchain.transaction.get_merkle',[tx_hash, tx_height]) ], self.queue.put): |
|
|
if self.network.send([ ('blockchain.transaction.get_merkle',[tx_hash, tx_height]) ], self.queue.put): |
|
|
print_error('requesting merkle', tx_hash) |
|
|
self.print_error('requesting merkle', tx_hash) |
|
|
requested_merkle.append(tx_hash) |
|
|
requested_merkle.append(tx_hash) |
|
|
try: |
|
|
try: |
|
|
r = self.queue.get(timeout=0.1) |
|
|
r = self.queue.get(timeout=0.1) |
|
@ -105,7 +105,7 @@ class TxVerifier(util.DaemonThread): |
|
|
continue |
|
|
continue |
|
|
|
|
|
|
|
|
if r.get('error'): |
|
|
if r.get('error'): |
|
|
print_error('Verifier received an error:', r) |
|
|
self.print_error('Verifier received an error:', r) |
|
|
continue |
|
|
continue |
|
|
|
|
|
|
|
|
# 3. handle response |
|
|
# 3. handle response |
|
@ -127,7 +127,7 @@ class TxVerifier(util.DaemonThread): |
|
|
header = self.network.get_header(tx_height) |
|
|
header = self.network.get_header(tx_height) |
|
|
if not header: return |
|
|
if not header: return |
|
|
if header.get('merkle_root') != merkle_root: |
|
|
if header.get('merkle_root') != merkle_root: |
|
|
print_error("merkle verification failed for", tx_hash) |
|
|
self.print_error("merkle verification failed for", tx_hash) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
# we passed all the tests |
|
|
# we passed all the tests |
|
@ -135,7 +135,7 @@ class TxVerifier(util.DaemonThread): |
|
|
timestamp = header.get('timestamp') |
|
|
timestamp = header.get('timestamp') |
|
|
with self.lock: |
|
|
with self.lock: |
|
|
self.verified_tx[tx_hash] = (tx_height, timestamp, pos) |
|
|
self.verified_tx[tx_hash] = (tx_height, timestamp, pos) |
|
|
print_error("verified %s"%tx_hash) |
|
|
self.print_error("verified %s"%tx_hash) |
|
|
self.storage.put('verified_tx3', self.verified_tx, True) |
|
|
self.storage.put('verified_tx3', self.verified_tx, True) |
|
|
self.network.trigger_callback('updated') |
|
|
self.network.trigger_callback('updated') |
|
|
|
|
|
|
|
@ -155,7 +155,7 @@ class TxVerifier(util.DaemonThread): |
|
|
for tx_hash, item in items: |
|
|
for tx_hash, item in items: |
|
|
tx_height, timestamp, pos = item |
|
|
tx_height, timestamp, pos = item |
|
|
if tx_height >= height: |
|
|
if tx_height >= height: |
|
|
print_error("redoing", tx_hash) |
|
|
self.print_error("redoing", tx_hash) |
|
|
with self.lock: |
|
|
with self.lock: |
|
|
self.verified_tx.pop(tx_hash) |
|
|
self.verified_tx.pop(tx_hash) |
|
|
if tx_hash in self.merkle_roots: |
|
|
if tx_hash in self.merkle_roots: |
|
|