new spec and conversion

This commit is contained in:
ThomasV 2012-03-30 10:48:32 +02:00
parent 5e512754d3
commit d0dd8c847a
4 changed files with 28 additions and 14 deletions

View File

@ -1075,7 +1075,7 @@ class ElectrumWindow:
n = 0 n = 0
h = self.wallet.history.get(address,[]) h = self.wallet.history.get(address,[])
for item in h: for item in h:
if not item['is_in'] : n=n+1 if not item['is_input'] : n=n+1
tx = "None" if n==0 else "%d"%n tx = "None" if n==0 else "%d"%n
self.recv_list.append((address, label, tx )) self.recv_list.append((address, label, tx ))
@ -1103,7 +1103,7 @@ class ElectrumWindow:
tx_hash = tx['tx_hash'] tx_hash = tx['tx_hash']
if tx['height']: if tx['height']:
conf = self.wallet.blocks - tx['height'] + 1 conf = self.wallet.blocks - tx['height'] + 1
time_str = datetime.datetime.fromtimestamp( tx['nTime']).isoformat(' ')[:-3] time_str = datetime.datetime.fromtimestamp( tx['timestamp']).isoformat(' ')[:-3]
conf_icon = gtk.STOCK_APPLY conf_icon = gtk.STOCK_APPLY
else: else:
conf = 0 conf = 0

View File

@ -237,7 +237,7 @@ class ElectrumWindow(QMainWindow):
if tx['height']: if tx['height']:
conf = self.wallet.blocks - tx['height'] + 1 conf = self.wallet.blocks - tx['height'] + 1
time_str = datetime.datetime.fromtimestamp( tx['nTime']).isoformat(' ')[:-3] time_str = datetime.datetime.fromtimestamp( tx['timestamp']).isoformat(' ')[:-3]
else: else:
conf = 0 conf = 0
time_str = 'pending' time_str = 'pending'
@ -310,7 +310,7 @@ class ElectrumWindow(QMainWindow):
tx_hash = tx['tx_hash'] tx_hash = tx['tx_hash']
if tx['height']: if tx['height']:
conf = self.wallet.blocks - tx['height'] + 1 conf = self.wallet.blocks - tx['height'] + 1
time_str = datetime.datetime.fromtimestamp( tx['nTime']).isoformat(' ')[:-3] time_str = datetime.datetime.fromtimestamp( tx['timestamp']).isoformat(' ')[:-3]
icon = QIcon(":icons/confirmed.png") icon = QIcon(":icons/confirmed.png")
else: else:
conf = 0 conf = 0
@ -574,7 +574,7 @@ class ElectrumWindow(QMainWindow):
n = 0 n = 0
h = self.wallet.history.get(address,[]) h = self.wallet.history.get(address,[])
for item in h: for item in h:
if not item['is_in'] : n=n+1 if not item['is_input'] : n=n+1
tx = "None" if n==0 else "%d"%n tx = "None" if n==0 else "%d"%n
item = QTreeWidgetItem( [ address, label, tx] ) item = QTreeWidgetItem( [ address, label, tx] )
item.setFont(0, QFont('monospace')) item.setFont(0, QFont('monospace'))

View File

@ -24,6 +24,15 @@ DEFAULT_TIMEOUT = 5
DEFAULT_SERVERS = ['electrum.bitcoins.sk','ecdsa.org','electrum.novit.ro'] # list of default servers DEFAULT_SERVERS = ['electrum.bitcoins.sk','ecdsa.org','electrum.novit.ro'] # list of default servers
def old_to_new(s):
s = s.replace("'blk_hash'", "'block_hash'")
s = s.replace("'pos'", "'index'")
s = s.replace("'nTime'", "'timestamp'")
s = s.replace("'is_in'", "'is_input'")
s = s.replace("'raw_scriptPubKey'","'raw_output_script'")
return s
class Interface: class Interface:
def __init__(self, host, port): def __init__(self, host, port):
self.host = host self.host = host
@ -57,7 +66,7 @@ class Interface:
method = c.get('method',None) method = c.get('method',None)
if not method: if not method:
return return
if error: if error:
print "received error:", c, method, params print "received error:", c, method, params
else: else:
@ -117,7 +126,7 @@ class PollingInterface(Interface):
def get_history(self, address): def get_history(self, address):
self.send([('address.get_history', [address] )]) self.send([('blockchain.address.get_history', [address] )])
def poll(self): def poll(self):
self.send([('session.poll', [])]) self.send([('session.poll', [])])
@ -200,6 +209,9 @@ class NativeInterface(PollingInterface):
self.rtime = time.time() - t1 self.rtime = time.time() - t1
self.is_connected = True self.is_connected = True
if cmd == 'h':
out = old_to_new(out)
if cmd in[ 'peers','h','poll']: if cmd in[ 'peers','h','poll']:
out = ast.literal_eval( out ) out = ast.literal_eval( out )
@ -215,7 +227,6 @@ class NativeInterface(PollingInterface):
class HttpInterface(PollingInterface): class HttpInterface(PollingInterface):
def start(self): def start(self):
@ -302,6 +313,7 @@ class AsynchronousInterface(Interface):
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
self.is_connected = False self.is_connected = False
# push None so that the getting thread exits its loop
self.responses.put(None) self.responses.put(None)
def send(self, messages): def send(self, messages):
@ -314,7 +326,7 @@ class AsynchronousInterface(Interface):
self.s.send( out ) self.s.send( out )
def get_history(self, addr): def get_history(self, addr):
self.send([('address.get_history', [addr])]) self.send([('blockchain.address.get_history', [addr])])
self.addresses_waiting_for_history.append(addr) self.addresses_waiting_for_history.append(addr)
def start(self): def start(self):

View File

@ -560,6 +560,7 @@ class Wallet:
f.close() f.close()
except: except:
return return
data = interface.old_to_new(data)
try: try:
d = ast.literal_eval( data ) d = ast.literal_eval( data )
self.seed_version = d.get('seed_version') self.seed_version = d.get('seed_version')
@ -631,16 +632,16 @@ class Wallet:
h = self.history.get(addr) h = self.history.get(addr)
if h is None: continue if h is None: continue
for item in h: for item in h:
if item.get('raw_scriptPubKey'): if item.get('raw_output_script'):
coins.append( (addr,item)) coins.append( (addr,item))
coins = sorted( coins, key = lambda x: x[1]['nTime'] ) coins = sorted( coins, key = lambda x: x[1]['timestamp'] )
inputs = [] inputs = []
for c in coins: for c in coins:
addr, item = c addr, item = c
v = item.get('value') v = item.get('value')
total += v total += v
inputs.append((addr, v, item['tx_hash'], item['pos'], item['raw_scriptPubKey'], None, None) ) inputs.append((addr, v, item['tx_hash'], item['index'], item['raw_output_script'], None, None) )
fee = self.fee*len(inputs) if fixed_fee is None else fixed_fee fee = self.fee*len(inputs) if fixed_fee is None else fixed_fee
if total >= amount + fee: break if total >= amount + fee: break
else: else:
@ -705,7 +706,7 @@ class Wallet:
def get_tx_history(self): def get_tx_history(self):
lines = self.tx_history.values() lines = self.tx_history.values()
lines = sorted(lines, key=operator.itemgetter("nTime")) lines = sorted(lines, key=operator.itemgetter("timestamp"))
return lines return lines
def update_tx_history(self): def update_tx_history(self):
@ -722,7 +723,7 @@ class Wallet:
else: else:
line['value'] += tx['value'] line['value'] += tx['value']
if line['height'] == 0: if line['height'] == 0:
line['nTime'] = 1e12 line['timestamp'] = 1e12
self.update_tx_labels() self.update_tx_labels()
def update_tx_labels(self): def update_tx_labels(self):
@ -996,6 +997,7 @@ class Wallet:
response = self.interface.responses.get(True,100000000000) # workaround so that it can be keyboard interrupted response = self.interface.responses.get(True,100000000000) # workaround so that it can be keyboard interrupted
self.handle_response(response) self.handle_response(response)
def start_interface(self): def start_interface(self):
if self.protocol == 'n': if self.protocol == 'n':
InterfaceClass = NativeInterface InterfaceClass = NativeInterface