mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-03 03:11:17 +00:00
monkeypatching: text formatting of protobuf messages
This commit is contained in:
parent
fe0e409e77
commit
366a7aa07d
@ -6,6 +6,7 @@ import trezorlib.messages_pb2 as proto
|
|||||||
import trezorlib.types_pb2 as proto_types
|
import trezorlib.types_pb2 as proto_types
|
||||||
|
|
||||||
class TestSignTx(common.TrezorTest):
|
class TestSignTx(common.TrezorTest):
|
||||||
|
|
||||||
def test_simplesigntx(self):
|
def test_simplesigntx(self):
|
||||||
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
|
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
|
||||||
# input 0: 0.0039 BTC
|
# input 0: 0.0039 BTC
|
||||||
@ -22,7 +23,6 @@ class TestSignTx(common.TrezorTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
tx = self.client.simple_sign_tx('Bitcoin', [inp1, ], [out1, ])
|
tx = self.client.simple_sign_tx('Bitcoin', [inp1, ], [out1, ])
|
||||||
# print binascii.hexlify(tx.serialized_tx)
|
|
||||||
self.assertEqual(binascii.hexlify(tx.serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000')
|
self.assertEqual(binascii.hexlify(tx.serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000')
|
||||||
|
|
||||||
def test_estimate_size(self):
|
def test_estimate_size(self):
|
||||||
|
16
trezorlib/client.py
Normal file → Executable file
16
trezorlib/client.py
Normal file → Executable file
@ -9,6 +9,22 @@ import messages_pb2 as proto
|
|||||||
import types_pb2 as types
|
import types_pb2 as types
|
||||||
from api_blockchain import BlockchainApi
|
from api_blockchain import BlockchainApi
|
||||||
|
|
||||||
|
# === start monkeypatching: text formatting of protobuf messages
|
||||||
|
import google.protobuf.text_format
|
||||||
|
import google.protobuf.descriptor
|
||||||
|
|
||||||
|
_oldPrintFieldValue = google.protobuf.text_format.PrintFieldValue
|
||||||
|
|
||||||
|
def _customPrintFieldValue(field, value, out, indent=0, as_utf8=False, as_one_line=False):
|
||||||
|
if field.cpp_type == google.protobuf.descriptor.FieldDescriptor.CPPTYPE_STRING:
|
||||||
|
if str(field.GetOptions()).strip() == '[binary]:': # binary option set
|
||||||
|
_oldPrintFieldValue(field, 'hex(%s)' % binascii.hexlify(value), out, indent, as_utf8, as_one_line)
|
||||||
|
else:
|
||||||
|
_oldPrintFieldValue(field, value, out, indent, as_utf8, as_one_line)
|
||||||
|
|
||||||
|
google.protobuf.text_format.PrintFieldValue = _customPrintFieldValue
|
||||||
|
# === end of monkeypatching
|
||||||
|
|
||||||
def show_message(message):
|
def show_message(message):
|
||||||
print "MESSAGE FROM DEVICE:", message
|
print "MESSAGE FROM DEVICE:", message
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user