mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 11:28:14 +00:00
Reworked TransactionType (again)
This commit is contained in:
parent
96966309d3
commit
1d46bd70a9
@ -491,11 +491,10 @@ class ProtocolMixin(object):
|
||||
|
||||
# If there's some part of signed transaction, let's add it
|
||||
if res.HasField('serialized') and res.serialized.HasField('serialized_tx'):
|
||||
print "!!! RECEIVED PART OF SERIALIED TX (%d BYTES)" % len(res.serialized.serialized_tx)
|
||||
print "RECEIVED PART OF SERIALIED TX (%d BYTES)" % len(res.serialized.serialized_tx)
|
||||
serialized_tx += res.serialized.serialized_tx
|
||||
|
||||
if res.HasField('serialized') and res.serialized.HasField('signature_index'):
|
||||
print "!!! SIGNED INPUT", res.serialized.signature_index
|
||||
signatures[res.serialized.signature_index] = res.serialized.signature
|
||||
|
||||
if res.request_type == types.TXFINISHED:
|
||||
@ -506,27 +505,24 @@ class ProtocolMixin(object):
|
||||
current_tx = txes[res.details.tx_hash]
|
||||
|
||||
if res.request_type == types.TXMETA:
|
||||
print "REQUESTING META OF", binascii.hexlify(res.details.tx_hash)
|
||||
msg = types.TransactionType()
|
||||
msg.version = current_tx.version
|
||||
msg.lock_time = current_tx.lock_time
|
||||
msg.inputs_count = len(current_tx.inputs)
|
||||
msg.inputs_cnt = len(current_tx.inputs)
|
||||
if res.details.tx_hash:
|
||||
msg.outputs_count = len(current_tx.bin_outputs)
|
||||
msg.outputs_cnt = len(current_tx.bin_outputs)
|
||||
else:
|
||||
msg.outputs_count = len(current_tx.outputs)
|
||||
msg.outputs_cnt = len(current_tx.outputs)
|
||||
res = self.call(proto.TxAck(tx=msg))
|
||||
continue
|
||||
|
||||
elif res.request_type == types.TXINPUT:
|
||||
print "REQUESTING INPUT", res.details.request_index, "OF", binascii.hexlify(res.details.tx_hash)
|
||||
msg = types.TransactionType()
|
||||
msg.inputs.extend([current_tx.inputs[res.details.request_index], ])
|
||||
res = self.call(proto.TxAck(tx=msg))
|
||||
continue
|
||||
|
||||
elif res.request_type == types.TXOUTPUT:
|
||||
print "REQUESTING OUTOUT", res.details.request_index, "OF", binascii.hexlify(res.details.tx_hash)
|
||||
msg = types.TransactionType()
|
||||
if res.details.tx_hash:
|
||||
msg.bin_outputs.extend([current_tx.bin_outputs[res.details.request_index], ])
|
||||
@ -686,82 +682,3 @@ class TrezorClientDebug(ProtocolMixin, TextUIMixin, DebugWireMixin, BaseClient):
|
||||
|
||||
class TrezorDebugClient(ProtocolMixin, DebugLinkMixin, DebugWireMixin, BaseClient):
|
||||
pass
|
||||
|
||||
'''
|
||||
def _sign_tx(self, coin_name, inputs, outputs):
|
||||
''
|
||||
inputs: list of TxInput
|
||||
outputs: list of TxOutput
|
||||
|
||||
proto.TxInput(index=0,
|
||||
address_n=0,
|
||||
amount=0,
|
||||
prev_hash='',
|
||||
prev_index=0,
|
||||
#script_sig=
|
||||
)
|
||||
proto.TxOutput(index=0,
|
||||
address='1Bitkey',
|
||||
#address_n=[],
|
||||
amount=100000000,
|
||||
script_type=proto.PAYTOADDRESS,
|
||||
#script_args=
|
||||
)
|
||||
''
|
||||
|
||||
start = time.time()
|
||||
|
||||
try:
|
||||
self.transport.session_begin()
|
||||
|
||||
# Prepare and send initial message
|
||||
tx = proto.SignTx()
|
||||
tx.inputs_count = len(inputs)
|
||||
tx.outputs_count = len(outputs)
|
||||
res = self.call(tx)
|
||||
|
||||
# Prepare structure for signatures
|
||||
signatures = [None]*len(inputs)
|
||||
serialized_tx = ''
|
||||
|
||||
counter = 0
|
||||
while True:
|
||||
counter += 1
|
||||
|
||||
if isinstance(res, proto.Failure):
|
||||
raise CallException("Signing failed")
|
||||
|
||||
if not isinstance(res, proto.TxRequest):
|
||||
raise CallException("Unexpected message")
|
||||
|
||||
# If there's some part of signed transaction, let's add it
|
||||
if res.serialized_tx:
|
||||
print "!!! RECEIVED PART OF SERIALIED TX (%d BYTES)" % len(res.serialized_tx)
|
||||
serialized_tx += res.serialized_tx
|
||||
|
||||
if res.signed_index >= 0 and res.signature:
|
||||
print "!!! SIGNED INPUT", res.signed_index
|
||||
signatures[res.signed_index] = res.signature
|
||||
|
||||
if res.request_index < 0:
|
||||
# Device didn't ask for more information, finish workflow
|
||||
break
|
||||
|
||||
# Device asked for one more information, let's process it.
|
||||
if res.request_type == types.TXOUTPUT:
|
||||
res = self.call(outputs[res.request_index])
|
||||
continue
|
||||
|
||||
elif res.request_type == types.TXINPUT:
|
||||
print "REQUESTING", res.request_index
|
||||
res = self.call(inputs[res.request_index])
|
||||
continue
|
||||
|
||||
finally:
|
||||
self.transport.session_end()
|
||||
|
||||
print "SIGNED IN %.03f SECONDS, CALLED %d MESSAGES, %d BYTES" % \
|
||||
(time.time() - start, counter, len(serialized_tx))
|
||||
|
||||
return (signatures, serialized_tx)
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user