store timestamps in verifier
This commit is contained in:
parent
4e070bda57
commit
16a81271e4
|
@ -35,7 +35,7 @@ class WalletVerifier(threading.Thread):
|
||||||
self.transactions = {} # requested verifications (with height sent by the requestor)
|
self.transactions = {} # requested verifications (with height sent by the requestor)
|
||||||
self.interface.register_channel('verifier')
|
self.interface.register_channel('verifier')
|
||||||
|
|
||||||
self.verified_tx = config.get('verified_tx',{}) # height of verified tx
|
self.verified_tx = config.get('verified_tx2',{}) # height, timestamp of verified transactions
|
||||||
self.merkle_roots = config.get('merkle_roots',{}) # hashed by me
|
self.merkle_roots = config.get('merkle_roots',{}) # hashed by me
|
||||||
|
|
||||||
self.targets = config.get('targets',{}) # compute targets
|
self.targets = config.get('targets',{}) # compute targets
|
||||||
|
@ -51,10 +51,20 @@ class WalletVerifier(threading.Thread):
|
||||||
""" return the number of confirmations of a monitored transaction. """
|
""" return the number of confirmations of a monitored transaction. """
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if tx in self.transactions.keys():
|
if tx in self.transactions.keys():
|
||||||
return (self.local_height - self.verified_tx[tx] + 1) if tx in self.verified_tx else -1
|
if tx in self.verified_tx:
|
||||||
|
height, timestamp = self.verified_tx[tx]
|
||||||
|
conf = (self.local_height - height + 1)
|
||||||
|
else:
|
||||||
|
conf = -1
|
||||||
else:
|
else:
|
||||||
#print "verifier: tx not in list", tx
|
#print "verifier: tx not in list", tx
|
||||||
return 0
|
conf = 0
|
||||||
|
|
||||||
|
if conf <= 0:
|
||||||
|
timestamp = None
|
||||||
|
|
||||||
|
return conf, timestamp
|
||||||
|
|
||||||
|
|
||||||
def add(self, tx_hash, tx_height):
|
def add(self, tx_hash, tx_height):
|
||||||
""" add a transaction to the list of monitored transactions. """
|
""" add a transaction to the list of monitored transactions. """
|
||||||
|
@ -167,9 +177,11 @@ class WalletVerifier(threading.Thread):
|
||||||
if not header: return
|
if not header: return
|
||||||
assert header.get('merkle_root') == self.merkle_roots[tx_hash]
|
assert header.get('merkle_root') == self.merkle_roots[tx_hash]
|
||||||
# we passed all the tests
|
# we passed all the tests
|
||||||
self.verified_tx[tx_hash] = tx_height
|
header = self.read_header(tx_height)
|
||||||
|
timestamp = header.get('timestamp')
|
||||||
|
self.verified_tx[tx_hash] = (tx_height, timestamp)
|
||||||
print_error("verified %s"%tx_hash)
|
print_error("verified %s"%tx_hash)
|
||||||
self.config.set_key('verified_tx', self.verified_tx, True)
|
self.config.set_key('verified_tx2', self.verified_tx, True)
|
||||||
self.interface.trigger_callback('updated')
|
self.interface.trigger_callback('updated')
|
||||||
|
|
||||||
|
|
||||||
|
@ -225,7 +237,8 @@ class WalletVerifier(threading.Thread):
|
||||||
# this can be caused by a reorg.
|
# this can be caused by a reorg.
|
||||||
print_error("verify header failed"+ repr(header))
|
print_error("verify header failed"+ repr(header))
|
||||||
# undo verifications
|
# undo verifications
|
||||||
for tx_hash, tx_height in self.verified_tx.items():
|
for tx_hash, item in self.verified_tx.items():
|
||||||
|
tx_height, timestamp = item
|
||||||
if tx_height >= height:
|
if tx_height >= height:
|
||||||
print_error("redoing", tx_hash)
|
print_error("redoing", tx_hash)
|
||||||
self.verified_tx.pop(tx_hash)
|
self.verified_tx.pop(tx_hash)
|
||||||
|
@ -368,10 +381,3 @@ class WalletVerifier(threading.Thread):
|
||||||
new_bits = c + MM * i
|
new_bits = c + MM * i
|
||||||
return new_bits, new_target
|
return new_bits, new_target
|
||||||
|
|
||||||
def get_timestamp(self, tx_height):
|
|
||||||
if tx_height>0:
|
|
||||||
header = self.read_header(tx_height)
|
|
||||||
if header:
|
|
||||||
return header.get('timestamp')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -430,9 +430,9 @@ class Wallet:
|
||||||
if not tx_hash: return ''
|
if not tx_hash: return ''
|
||||||
tx = self.transactions.get(tx_hash)
|
tx = self.transactions.get(tx_hash)
|
||||||
is_mine, v, fee = self.get_tx_value(tx_hash)
|
is_mine, v, fee = self.get_tx_value(tx_hash)
|
||||||
conf = self.verifier.get_confirmations(tx_hash)
|
conf, timestamp = self.verifier.get_confirmations(tx_hash)
|
||||||
timestamp = tx.get('timestamp')
|
|
||||||
if conf and timestamp:
|
if conf:
|
||||||
time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
|
time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
|
||||||
else:
|
else:
|
||||||
time_str = 'pending'
|
time_str = 'pending'
|
||||||
|
@ -683,7 +683,7 @@ class Wallet:
|
||||||
def get_tx_history(self):
|
def get_tx_history(self):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
history = self.transactions.values()
|
history = self.transactions.values()
|
||||||
history.sort(key = lambda x: x.get('timestamp') if x.get('timestamp') else 1e12)
|
history.sort(key = lambda x: x.get('height') if x.get('height') else 1e12)
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
balance = 0
|
balance = 0
|
||||||
|
@ -699,8 +699,7 @@ class Wallet:
|
||||||
balance = c + u - balance
|
balance = c + u - balance
|
||||||
for tx in history:
|
for tx in history:
|
||||||
tx_hash = tx['tx_hash']
|
tx_hash = tx['tx_hash']
|
||||||
timestamp = tx.get('timestamp')
|
conf, timestamp = self.verifier.get_confirmations(tx_hash) if self.verifier else None
|
||||||
conf = self.verifier.get_confirmations(tx_hash) if self.verifier else None
|
|
||||||
is_mine, value, fee = self.get_tx_value(tx_hash)
|
is_mine, value, fee = self.get_tx_value(tx_hash)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
balance += value
|
balance += value
|
||||||
|
@ -1042,11 +1041,6 @@ class Wallet:
|
||||||
if tx_height>0:
|
if tx_height>0:
|
||||||
self.verifier.add(tx_hash, tx_height)
|
self.verifier.add(tx_hash, tx_height)
|
||||||
|
|
||||||
# set the timestamp for transactions that need it
|
|
||||||
if tx and not tx.get('timestamp'):
|
|
||||||
timestamp = self.verifier.get_timestamp(tx_height)
|
|
||||||
self.set_tx_timestamp(tx_hash, timestamp)
|
|
||||||
|
|
||||||
# review transactions that are in the history
|
# review transactions that are in the history
|
||||||
for addr, hist in self.history.items():
|
for addr, hist in self.history.items():
|
||||||
if hist == ['*']: continue
|
if hist == ['*']: continue
|
||||||
|
@ -1062,13 +1056,6 @@ class Wallet:
|
||||||
tx['height'] = tx_height
|
tx['height'] = tx_height
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def set_tx_timestamp(self, tx_hash, timestamp):
|
|
||||||
with self.lock:
|
|
||||||
self.transactions[tx_hash]['timestamp'] = timestamp
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def is_addr_in_tx(self, addr, tx):
|
def is_addr_in_tx(self, addr, tx):
|
||||||
found = False
|
found = False
|
||||||
for txin in tx.get('inputs'):
|
for txin in tx.get('inputs'):
|
||||||
|
@ -1300,10 +1287,6 @@ class WalletSynchronizer(threading.Thread):
|
||||||
if self.wallet.transactions.get(tx_hash) is None:
|
if self.wallet.transactions.get(tx_hash) is None:
|
||||||
if (tx_hash, tx_height) not in requested_tx and (tx_hash, tx_height) not in missing_tx:
|
if (tx_hash, tx_height) not in requested_tx and (tx_hash, tx_height) not in missing_tx:
|
||||||
missing_tx.append( (tx_hash, tx_height) )
|
missing_tx.append( (tx_hash, tx_height) )
|
||||||
else:
|
|
||||||
if self.wallet.verifier:
|
|
||||||
timestamp = self.wallet.verifier.get_timestamp(tx_height)
|
|
||||||
self.wallet.set_tx_timestamp(tx_hash, timestamp)
|
|
||||||
|
|
||||||
elif method == 'blockchain.transaction.get':
|
elif method == 'blockchain.transaction.get':
|
||||||
tx_hash = params[0]
|
tx_hash = params[0]
|
||||||
|
@ -1339,6 +1322,5 @@ class WalletSynchronizer(threading.Thread):
|
||||||
d = deserialize.parse_Transaction(vds)
|
d = deserialize.parse_Transaction(vds)
|
||||||
d['height'] = tx_height
|
d['height'] = tx_height
|
||||||
d['tx_hash'] = tx_hash
|
d['tx_hash'] = tx_hash
|
||||||
if self.wallet.verifier: d['timestamp'] = self.wallet.verifier.get_timestamp(tx_height)
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue