recompile pb, adjust TransactionType constructors

pull/25/head
Pavol Rusnak 10 years ago
parent 8f870c54ed
commit 51b9d4e177

@ -0,0 +1,161 @@
'''
def test_signtx(self):
expected_tx = '01000000012de70f7d6ffed0db70f8882f3fca90db9bb09f0e99bce27468c23d3c994fcd56' \
'010000008b4830450221009b985e14d53cfeed3496846db6ddaa77a0206138d0df4c2ccd3b' \
'759e91bae3e1022004c76e10f99ccac8ced761719181a96bae25a74829eab3ecb8f29eb07f' \
'e18f7e01410436ae8595f03a7324d1d1482ede8560a4508c767fbc662559482d5759b32209' \
'a62964699995f6e018cfbeb7a71a66d4c64fa38875d79ead0a9ac66f59c1c8b3a3ffffffff' \
'0250c30000000000001976a91444ce5c6789b0bb0e8a9ab9a4769fe181cb274c4688aca086' \
'0100000000001976a9149e03078026388661b197129a43f0f64f88379ce688ac00000000'
inp1 = proto.TxInput(index=0,
address_n=[1, 0],
amount=200000, # 0.002 BTC
prev_hash=binascii.unhexlify('56cd4f993c3dc26874e2bc990e9fb09bdb90ca3f2f88f870dbd0fe6f7d0fe72d'),
prev_index=1,
#script_sig=
)
out1 = proto.TxOutput(index=0,
address='1GnnT11aZeH6QZCtT7EjCvRF3EXHoY3owE',
address_n=[0, 1],
amount=50000, # 0.0005 BTC
script_type=proto.PAYTOADDRESS,
#script_args=
)
out2 = proto.TxOutput(index=1,
address='1FQVPnjrbkPWeA8poUoEnX9U3n9DyhAVtv',
#address_n=[],
amount=100000, # 0.001 BTC
script_type=proto.PAYTOADDRESS,
#script_args=
)
print binascii.hexlify(self.client.sign_tx([inp1], [out1, out2])[1])
'''
'''
def test_workflow(self):
inp1 = proto.TxInput(index=0,
address_n=[1,0],
amount=100000000,
prev_hash='prevhash1234354346543456543654',
prev_index=11,
)
inp2 = proto.TxInput(index=1,
address_n=[2,0],
amount=100000000,
prev_hash='prevhash2222254346543456543654',
prev_index=11,
)
out1 = proto.TxOutput(index=0,
address='1BitkeyP2nDd5oa647AjvBbbwST54W5Zmx',
amount=100000000,
script_type=proto.PAYTOADDRESS,
)
out2 = proto.TxOutput(index=1,
address='1BitkeyP2nDd5oa647AjvBbbwST54W5Zmx',
#address_n=[],
amount=100000000,
script_type=proto.PAYTOADDRESS,
#script_args=
)
serialized = ''
# Prepare and send initial message
tx = proto.SignTx()
tx.algo = proto.ELECTRUM
tx.random = self.client._get_local_entropy()
tx.inputs_count = 2
tx.outputs_count = 2
res = self.client.call(tx)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXINPUT)
self.assertEqual(res.request_index, 0)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
# FIRST SIGNATURE
res = self.client.call(inp1)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXINPUT)
self.assertEqual(res.request_index, 1)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.client.call(inp2)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 0)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.client.call(out1)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 1)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.client.call(out2)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXINPUT)
self.assertEqual(res.request_index, 0)
self.assertNotEqual(res.signature, '')
self.assertNotEqual(res.serialized_tx, '')
serialized += res.serialized_tx
# SECOND SIGNATURE
res = self.client.call(inp1)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXINPUT)
self.assertEqual(res.request_index, 1)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.client.call(inp2)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 0)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.client.call(out1)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 1)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.client.call(out2)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 0)
self.assertNotEqual(res.signature, '')
self.assertNotEqual(res.serialized_tx, '')
serialized += res.serialized_tx
# FINALIZING OUTPUTS
res = self.client.call(out1)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 1)
self.assertEqual(res.signature, '')
self.assertNotEqual(res.serialized_tx, '')
serialized += res.serialized_tx
res = self.client.call(out2)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, -1)
self.assertEqual(res.signature, '')
self.assertNotEqual(res.serialized_tx, '')
serialized += res.serialized_tx
print binascii.hexlify(serialized)
'''

File diff suppressed because one or more lines are too long

@ -150,7 +150,7 @@ class TestProtectionLevels(common.TrezorTest):
proto.PassphraseRequest(),
proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
proto.TxRequest(request_index=-1)])
proto.TxRequest(finished=True)])
self.client.simple_sign_tx('Bitcoin', [inp1, ], [out1, ])
# def test_firmware_erase(self):

@ -30,7 +30,7 @@ class BlockchainApi(object):
def get_tx(self, txhash):
# Build protobuf transaction structure from blockchain.info
d = self._raw_tx(txhash)
t = proto_types.TransactionType()
t = proto_types.TransactionType(version = 1, lock_time = 0)
for inp in d['inputs']:
di = self._raw_tx(inp['prev_out']['tx_index'])

File diff suppressed because one or more lines are too long

@ -15,7 +15,7 @@ import google.protobuf.descriptor_pb2
DESCRIPTOR = _descriptor.FileDescriptor(
name='types.proto',
package='',
serialized_pb='\n\x0btypes.proto\x1a google/protobuf/descriptor.proto\"\x80\x01\n\nHDNodeType\x12\r\n\x05\x64\x65pth\x18\x01 \x02(\r\x12\x13\n\x0b\x66ingerprint\x18\x02 \x02(\r\x12\x11\n\tchild_num\x18\x03 \x02(\r\x12\x12\n\nchain_code\x18\x04 \x02(\x0c\x12\x13\n\x0bprivate_key\x18\x05 \x01(\x0c\x12\x12\n\npublic_key\x18\x06 \x01(\x0c\"]\n\x08\x43oinType\x12\x11\n\tcoin_name\x18\x01 \x01(\t\x12\x15\n\rcoin_shortcut\x18\x02 \x01(\t\x12\x14\n\x0c\x61\x64\x64ress_type\x18\x03 \x01(\r\x12\x11\n\tmaxfee_kb\x18\x04 \x01(\x04\"y\n\x0bTxInputType\x12\x11\n\taddress_n\x18\x01 \x03(\r\x12\x11\n\tprev_hash\x18\x02 \x02(\x0c\x12\x12\n\nprev_index\x18\x03 \x02(\r\x12\x12\n\nscript_sig\x18\x04 \x01(\x0c\x12\x1c\n\x08sequence\x18\x05 \x01(\r:\n4294967295\"y\n\x0cTxOutputType\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\x12\x11\n\taddress_n\x18\x02 \x03(\r\x12\x0e\n\x06\x61mount\x18\x03 \x02(\x04\x12 \n\x0bscript_type\x18\x04 \x02(\x0e\x32\x0b.ScriptType\x12\x13\n\x0bscript_args\x18\x05 \x03(\x0c\"8\n\x0fTxOutputBinType\x12\x0e\n\x06\x61mount\x18\x01 \x02(\x04\x12\x15\n\rscript_pubkey\x18\x02 \x02(\x0c\"|\n\x0fTransactionType\x12\x12\n\x07version\x18\x01 \x01(\r:\x01\x31\x12\x1c\n\x06inputs\x18\x02 \x03(\x0b\x32\x0c.TxInputType\x12!\n\x07outputs\x18\x03 \x03(\x0b\x32\x10.TxOutputBinType\x12\x14\n\tlock_time\x18\x04 \x01(\r:\x01\x30*\xcd\x02\n\x0b\x46\x61ilureType\x12\x1d\n\x19\x46\x61ilure_UnexpectedMessage\x10\x01\x12\x1a\n\x16\x46\x61ilure_ButtonExpected\x10\x02\x12\x17\n\x13\x46\x61ilure_SyntaxError\x10\x03\x12\x1b\n\x17\x46\x61ilure_ActionCancelled\x10\x04\x12\x17\n\x13\x46\x61ilure_PinExpected\x10\x05\x12\x18\n\x14\x46\x61ilure_PinCancelled\x10\x06\x12\x16\n\x12\x46\x61ilure_PinInvalid\x10\x07\x12\x1c\n\x18\x46\x61ilure_InvalidSignature\x10\x08\x12\x11\n\rFailure_Other\x10\t\x12\x1a\n\x16\x46\x61ilure_NotEnoughFunds\x10\n\x12\x1a\n\x16\x46\x61ilure_NotInitialized\x10\x0b\x12\x19\n\x15\x46\x61ilure_FirmwareError\x10\x63*3\n\nScriptType\x12\x10\n\x0cPAYTOADDRESS\x10\x00\x12\x13\n\x0fPAYTOSCRIPTHASH\x10\x01*(\n\x0bRequestType\x12\x0b\n\x07TXINPUT\x10\x00\x12\x0c\n\x08TXOUTPUT\x10\x01*\x86\x02\n\x11\x42uttonRequestType\x12\x17\n\x13\x42uttonRequest_Other\x10\x01\x12\"\n\x1e\x42uttonRequest_FeeOverThreshold\x10\x02\x12\x1f\n\x1b\x42uttonRequest_ConfirmOutput\x10\x03\x12\x1d\n\x19\x42uttonRequest_ResetDevice\x10\x04\x12\x1d\n\x19\x42uttonRequest_ConfirmWord\x10\x05\x12\x1c\n\x18\x42uttonRequest_WipeDevice\x10\x06\x12\x1d\n\x19\x42uttonRequest_ProtectCall\x10\x07\x12\x18\n\x14\x42uttonRequest_SignTx\x10\x08*\x7f\n\x14PinMatrixRequestType\x12 \n\x1cPinMatrixRequestType_Current\x10\x01\x12!\n\x1dPinMatrixRequestType_NewFirst\x10\x02\x12\"\n\x1ePinMatrixRequestType_NewSecond\x10\x03:4\n\x07wire_in\x12!.google.protobuf.EnumValueOptions\x18\xd2\x86\x03 \x01(\x08:5\n\x08wire_out\x12!.google.protobuf.EnumValueOptions\x18\xd3\x86\x03 \x01(\x08::\n\rwire_debug_in\x12!.google.protobuf.EnumValueOptions\x18\xd4\x86\x03 \x01(\x08:;\n\x0ewire_debug_out\x12!.google.protobuf.EnumValueOptions\x18\xd5\x86\x03 \x01(\x08\x42\x36\n(org.multibit.hd.hardware.trezor.protobufB\nTrezorType')
serialized_pb='\n\x0btypes.proto\x1a google/protobuf/descriptor.proto\"\x80\x01\n\nHDNodeType\x12\r\n\x05\x64\x65pth\x18\x01 \x02(\r\x12\x13\n\x0b\x66ingerprint\x18\x02 \x02(\r\x12\x11\n\tchild_num\x18\x03 \x02(\r\x12\x12\n\nchain_code\x18\x04 \x02(\x0c\x12\x13\n\x0bprivate_key\x18\x05 \x01(\x0c\x12\x12\n\npublic_key\x18\x06 \x01(\x0c\"]\n\x08\x43oinType\x12\x11\n\tcoin_name\x18\x01 \x01(\t\x12\x15\n\rcoin_shortcut\x18\x02 \x01(\t\x12\x14\n\x0c\x61\x64\x64ress_type\x18\x03 \x01(\r\x12\x11\n\tmaxfee_kb\x18\x04 \x01(\x04\"y\n\x0bTxInputType\x12\x11\n\taddress_n\x18\x01 \x03(\r\x12\x11\n\tprev_hash\x18\x02 \x02(\x0c\x12\x12\n\nprev_index\x18\x03 \x02(\r\x12\x12\n\nscript_sig\x18\x04 \x01(\x0c\x12\x1c\n\x08sequence\x18\x05 \x01(\r:\n4294967295\"y\n\x0cTxOutputType\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\x12\x11\n\taddress_n\x18\x02 \x03(\r\x12\x0e\n\x06\x61mount\x18\x03 \x02(\x04\x12 \n\x0bscript_type\x18\x04 \x02(\x0e\x32\x0b.ScriptType\x12\x13\n\x0bscript_args\x18\x05 \x03(\x0c\"8\n\x0fTxOutputBinType\x12\x0e\n\x06\x61mount\x18\x01 \x02(\x04\x12\x15\n\rscript_pubkey\x18\x02 \x02(\x0c\"\x9a\x01\n\x0fTransactionType\x12\x0f\n\x07version\x18\x01 \x01(\r\x12\x1c\n\x06inputs\x18\x02 \x03(\x0b\x32\x0c.TxInputType\x12!\n\x07outputs\x18\x03 \x03(\x0b\x32\x10.TxOutputBinType\x12\"\n\x0bour_outputs\x18\x04 \x03(\x0b\x32\r.TxOutputType\x12\x11\n\tlock_time\x18\x05 \x01(\r*\xcd\x02\n\x0b\x46\x61ilureType\x12\x1d\n\x19\x46\x61ilure_UnexpectedMessage\x10\x01\x12\x1a\n\x16\x46\x61ilure_ButtonExpected\x10\x02\x12\x17\n\x13\x46\x61ilure_SyntaxError\x10\x03\x12\x1b\n\x17\x46\x61ilure_ActionCancelled\x10\x04\x12\x17\n\x13\x46\x61ilure_PinExpected\x10\x05\x12\x18\n\x14\x46\x61ilure_PinCancelled\x10\x06\x12\x16\n\x12\x46\x61ilure_PinInvalid\x10\x07\x12\x1c\n\x18\x46\x61ilure_InvalidSignature\x10\x08\x12\x11\n\rFailure_Other\x10\t\x12\x1a\n\x16\x46\x61ilure_NotEnoughFunds\x10\n\x12\x1a\n\x16\x46\x61ilure_NotInitialized\x10\x0b\x12\x19\n\x15\x46\x61ilure_FirmwareError\x10\x63*3\n\nScriptType\x12\x10\n\x0cPAYTOADDRESS\x10\x00\x12\x13\n\x0fPAYTOSCRIPTHASH\x10\x01*4\n\x0bRequestType\x12\x0b\n\x07TXINPUT\x10\x00\x12\x0c\n\x08TXOUTPUT\x10\x01\x12\n\n\x06TXMETA\x10\x02*\x86\x02\n\x11\x42uttonRequestType\x12\x17\n\x13\x42uttonRequest_Other\x10\x01\x12\"\n\x1e\x42uttonRequest_FeeOverThreshold\x10\x02\x12\x1f\n\x1b\x42uttonRequest_ConfirmOutput\x10\x03\x12\x1d\n\x19\x42uttonRequest_ResetDevice\x10\x04\x12\x1d\n\x19\x42uttonRequest_ConfirmWord\x10\x05\x12\x1c\n\x18\x42uttonRequest_WipeDevice\x10\x06\x12\x1d\n\x19\x42uttonRequest_ProtectCall\x10\x07\x12\x18\n\x14\x42uttonRequest_SignTx\x10\x08*\x7f\n\x14PinMatrixRequestType\x12 \n\x1cPinMatrixRequestType_Current\x10\x01\x12!\n\x1dPinMatrixRequestType_NewFirst\x10\x02\x12\"\n\x1ePinMatrixRequestType_NewSecond\x10\x03:4\n\x07wire_in\x12!.google.protobuf.EnumValueOptions\x18\xd2\x86\x03 \x01(\x08:5\n\x08wire_out\x12!.google.protobuf.EnumValueOptions\x18\xd3\x86\x03 \x01(\x08::\n\rwire_debug_in\x12!.google.protobuf.EnumValueOptions\x18\xd4\x86\x03 \x01(\x08:;\n\x0ewire_debug_out\x12!.google.protobuf.EnumValueOptions\x18\xd5\x86\x03 \x01(\x08\x42\x36\n(org.multibit.hd.hardware.trezor.protobufB\nTrezorType')
_FAILURETYPE = _descriptor.EnumDescriptor(
name='FailureType',
@ -74,8 +74,8 @@ _FAILURETYPE = _descriptor.EnumDescriptor(
],
containing_type=None,
options=None,
serialized_start=706,
serialized_end=1039,
serialized_start=737,
serialized_end=1070,
)
FailureType = enum_type_wrapper.EnumTypeWrapper(_FAILURETYPE)
@ -96,8 +96,8 @@ _SCRIPTTYPE = _descriptor.EnumDescriptor(
],
containing_type=None,
options=None,
serialized_start=1041,
serialized_end=1092,
serialized_start=1072,
serialized_end=1123,
)
ScriptType = enum_type_wrapper.EnumTypeWrapper(_SCRIPTTYPE)
@ -115,11 +115,15 @@ _REQUESTTYPE = _descriptor.EnumDescriptor(
name='TXOUTPUT', index=1, number=1,
options=None,
type=None),
_descriptor.EnumValueDescriptor(
name='TXMETA', index=2, number=2,
options=None,
type=None),
],
containing_type=None,
options=None,
serialized_start=1094,
serialized_end=1134,
serialized_start=1125,
serialized_end=1177,
)
RequestType = enum_type_wrapper.EnumTypeWrapper(_REQUESTTYPE)
@ -164,8 +168,8 @@ _BUTTONREQUESTTYPE = _descriptor.EnumDescriptor(
],
containing_type=None,
options=None,
serialized_start=1137,
serialized_end=1399,
serialized_start=1180,
serialized_end=1442,
)
ButtonRequestType = enum_type_wrapper.EnumTypeWrapper(_BUTTONREQUESTTYPE)
@ -190,8 +194,8 @@ _PINMATRIXREQUESTTYPE = _descriptor.EnumDescriptor(
],
containing_type=None,
options=None,
serialized_start=1401,
serialized_end=1528,
serialized_start=1444,
serialized_end=1571,
)
PinMatrixRequestType = enum_type_wrapper.EnumTypeWrapper(_PINMATRIXREQUESTTYPE)
@ -211,6 +215,7 @@ PAYTOADDRESS = 0
PAYTOSCRIPTHASH = 1
TXINPUT = 0
TXOUTPUT = 1
TXMETA = 2
ButtonRequest_Other = 1
ButtonRequest_FeeOverThreshold = 2
ButtonRequest_ConfirmOutput = 3
@ -526,7 +531,7 @@ _TRANSACTIONTYPE = _descriptor.Descriptor(
_descriptor.FieldDescriptor(
name='version', full_name='TransactionType.version', index=0,
number=1, type=13, cpp_type=3, label=1,
has_default_value=True, default_value=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
@ -545,9 +550,16 @@ _TRANSACTIONTYPE = _descriptor.Descriptor(
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='lock_time', full_name='TransactionType.lock_time', index=3,
number=4, type=13, cpp_type=3, label=1,
has_default_value=True, default_value=0,
name='our_outputs', full_name='TransactionType.our_outputs', index=3,
number=4, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='lock_time', full_name='TransactionType.lock_time', index=4,
number=5, type=13, cpp_type=3, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
@ -560,13 +572,14 @@ _TRANSACTIONTYPE = _descriptor.Descriptor(
options=None,
is_extendable=False,
extension_ranges=[],
serialized_start=579,
serialized_end=703,
serialized_start=580,
serialized_end=734,
)
_TXOUTPUTTYPE.fields_by_name['script_type'].enum_type = _SCRIPTTYPE
_TRANSACTIONTYPE.fields_by_name['inputs'].message_type = _TXINPUTTYPE
_TRANSACTIONTYPE.fields_by_name['outputs'].message_type = _TXOUTPUTBINTYPE
_TRANSACTIONTYPE.fields_by_name['our_outputs'].message_type = _TXOUTPUTTYPE
DESCRIPTOR.message_types_by_name['HDNodeType'] = _HDNODETYPE
DESCRIPTOR.message_types_by_name['CoinType'] = _COINTYPE
DESCRIPTOR.message_types_by_name['TxInputType'] = _TXINPUTTYPE

Loading…
Cancel
Save