1
0

create a class for transaction dialog

This commit is contained in:
ThomasV
2013-09-14 21:07:54 +02:00
parent 27977e6eb0
commit d51a8d0f25
9 changed files with 257 additions and 149 deletions

View File

@@ -8,6 +8,7 @@ from interface import Interface
from simple_config import SimpleConfig
import bitcoin
import account
import transaction
from transaction import Transaction
from plugins import BasePlugin
from mnemonic import mn_encode as mnemonic_encode

View File

@@ -247,7 +247,7 @@ class Commands:
def mktx(self, to_address, amount, fee = None, change_addr = None, domain = None):
tx = self._mktx([(to_address, amount)], fee, change_addr, domain)
return tx.as_dict()
return tx
def mksendmanytx(self, outputs, fee = None, change_addr = None, domain = None):
tx = self._mktx(outputs, fee, change_addr, domain)

View File

@@ -449,7 +449,7 @@ class Interface(threading.Thread):
def synchronous_get(self, requests, timeout=100000000):
# todo: use generators, unanswered_requests should be a list of arrays...
q = Queue.Queue()
queue = Queue.Queue()
ids = self.send(requests, lambda i,r: queue.put(r))
id2 = ids[:]
res = {}

View File

@@ -174,6 +174,12 @@ class Network(threading.Thread):
def is_running(self):
with self.lock: return self.running
def retrieve_transaction(self, tx_hash, tx_height=0):
import transaction
r = self.interface.synchronous_get([ ('blockchain.transaction.get',[tx_hash, tx_height]) ])[0]
return transaction.Transaction(r)
def parse_servers(self, result):
""" parse servers list into dict format"""

View File

@@ -379,6 +379,13 @@ class Transaction:
self.input_info = None
self.is_complete = True
def __repr__(self):
return "Transaction('"+self.raw+"')"
def __str__(self):
return self.raw
@classmethod
def from_io(klass, inputs, outputs):
raw = klass.serialize(inputs, outputs, for_sig = -1) # for_sig=-1 means do not sign
@@ -390,12 +397,13 @@ class Transaction:
for i in self.inputs:
e = { 'txid':i['tx_hash'], 'vout':i['index'], 'scriptPubKey':i.get('raw_output_script') }
extras.append(e)
# fixme: simplify this
i['prevout_hash'] = i['tx_hash']
i['prevout_n'] = i['index']
self.input_info = extras
return self
def __str__(self):
return self.raw
@classmethod
def multisig_script(klass, public_keys, num=None):
n = len(public_keys)

View File

@@ -24,7 +24,10 @@ def print_msg(*args):
def print_json(obj):
import json
s = json.dumps(obj,sort_keys = True, indent = 4)
try:
s = json.dumps(obj,sort_keys = True, indent = 4)
except TypeError:
s = repr(obj)
sys.stdout.write(s + "\n")
sys.stdout.flush()