Browse Source

check coinbase maturity (fix #252)

283
thomasv 11 years ago
parent
commit
ca75d3c08a
  1. 8
      lib/wallet.py

8
lib/wallet.py

@ -36,6 +36,8 @@ from account import *
from transaction import Transaction from transaction import Transaction
from plugins import run_hook from plugins import run_hook
COINBASE_MATURITY = 100
# AES encryption # AES encryption
EncodeAES = lambda secret, s: base64.b64encode(aes.encryptData(secret,s)) EncodeAES = lambda secret, s: base64.b64encode(aes.encryptData(secret,s))
DecodeAES = lambda secret, e: aes.decryptData(secret, base64.b64decode(e)) DecodeAES = lambda secret, e: aes.decryptData(secret, base64.b64decode(e))
@ -979,12 +981,14 @@ class Wallet:
for tx_hash, tx_height in h: for tx_hash, tx_height in h:
tx = self.transactions.get(tx_hash) tx = self.transactions.get(tx_hash)
if tx is None: raise BaseException("Wallet not synchronized") if tx is None: raise BaseException("Wallet not synchronized")
is_coinbase = tx.inputs[0].get('prevout_hash') == '0'*64
for output in tx.d.get('outputs'): for output in tx.d.get('outputs'):
if output.get('address') != addr: continue if output.get('address') != addr: continue
key = tx_hash + ":%d" % output.get('prevout_n') key = tx_hash + ":%d" % output.get('prevout_n')
if key in self.spent_outputs: continue if key in self.spent_outputs: continue
output['prevout_hash'] = tx_hash output['prevout_hash'] = tx_hash
output['height'] = tx_height output['height'] = tx_height
output['coinbase'] = is_coinbase
coins.append((tx_height, output)) coins.append((tx_height, output))
# sort by age # sort by age
@ -1024,7 +1028,9 @@ class Wallet:
inputs = [] inputs = []
coins = prioritized_coins + coins coins = prioritized_coins + coins
for item in coins: for item in coins:
if item.get('coinbase') and item.get('height') + COINBASE_MATURITY > self.network.blockchain.height:
continue
addr = item.get('address') addr = item.get('address')
v = item.get('value') v = item.get('value')
total += v total += v

Loading…
Cancel
Save