1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 17:38:39 +00:00

more python3 compatibility

This commit is contained in:
Pavol Rusnak 2017-06-19 00:00:26 +02:00
parent bf1c580d85
commit e7a56899c6
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 14 additions and 13 deletions

View File

@ -25,11 +25,11 @@ class TestMsgEthereumGetaddress(common.TrezorTest):
def test_ethereum_getaddress(self):
self.setup_mnemonic_nopin_nopassphrase()
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([])), '1d1c328764a41bda0492b66baa30c4a339ff85ef')
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([1])), '437207ca3cf43bf2e47dea0756d736c5df4f597a')
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([0, -1])), 'e5d96dfa07bcf1a3ae43677840c31394258861bf')
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([-9, 0])), 'f68804ac9eca9483ab4241d3e4751590d2c05102')
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([0, 9999999])), '7a6366ecfcaf0d5dcc1539c171696c6cdd1eb8ed')
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([])), b'1d1c328764a41bda0492b66baa30c4a339ff85ef')
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([1])), b'437207ca3cf43bf2e47dea0756d736c5df4f597a')
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([0, -1])), b'e5d96dfa07bcf1a3ae43677840c31394258861bf')
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([-9, 0])), b'f68804ac9eca9483ab4241d3e4751590d2c05102')
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([0, 9999999])), b'7a6366ecfcaf0d5dcc1539c171696c6cdd1eb8ed')
if __name__ == '__main__':
unittest.main()

View File

@ -691,7 +691,7 @@ class ProtocolMixin(object):
tx = msg.transactions.add()
if self.tx_api:
tx.CopyFrom(self.tx_api.get_tx(binascii.hexlify(inp.prev_hash)))
tx.CopyFrom(self.tx_api.get_tx(binascii.hexlify(inp.prev_hash).decode('utf-8')))
else:
raise Exception('TX_API not defined')
known_hashes.append(inp.prev_hash)
@ -716,7 +716,7 @@ class ProtocolMixin(object):
continue
if self.tx_api:
txes[inp.prev_hash] = self.tx_api.get_tx(binascii.hexlify(inp.prev_hash))
txes[inp.prev_hash] = self.tx_api.get_tx(binascii.hexlify(inp.prev_hash).decode('utf-8'))
else:
raise Exception('TX_API not defined')
known_hashes.append(inp.prev_hash)

View File

@ -31,7 +31,7 @@ class TxApi(object):
self.network = network
self.url = url
def fetch_json(self, url, resource, resourceid):
def fetch_json(self, resource, resourceid):
global cache_dir
if cache_dir:
cache_file = '%s/%s_%s_%s.json' % (cache_dir, self.network, resource, resourceid)
@ -41,7 +41,8 @@ class TxApi(object):
except:
pass
try:
r = requests.get('%s%s/%s' % (self.url, resource, resourceid), headers={'User-agent': 'Mozilla/5.0'})
url = '%s%s/%s' % (self.url, resource, resourceid)
r = requests.get(url, headers={'User-agent': 'Mozilla/5.0'})
j = r.json()
except:
raise Exception('URL error: %s' % url)
@ -64,7 +65,7 @@ class TxApiInsight(TxApi):
def get_tx(self, txhash):
data = self.fetch_json(self.url, 'tx', txhash)
data = self.fetch_json('tx', txhash)
t = proto_types.TransactionType()
t.version = data['version']
@ -99,7 +100,7 @@ class TxApiInsight(TxApi):
# we assume cnt < 253, so we can treat varIntLen(cnt) as 1
raise ValueError('Too many joinsplits')
extra_data_len = 1 + joinsplit_cnt * 1802 + 32 + 64
raw = fetch_json(self.url, 'rawtx', txhash)
raw = self.fetch_json('rawtx', txhash)
raw = binascii.unhexlify(raw['rawtx'])
t.extra_data = raw[-extra_data_len:]
@ -110,7 +111,7 @@ class TxApiSmartbit(TxApi):
def get_tx(self, txhash):
data = self.fetch_json(self.url, 'tx', txhash)
data = self.fetch_json('tx', txhash)
data = data['transaction']
@ -144,7 +145,7 @@ class TxApiBlockCypher(TxApi):
def get_tx(self, txhash):
data = self.fetch_json(self.url, 'txs', txhash)
data = self.fetch_json('txs', txhash)
t = proto_types.TransactionType()
t.version = data['ver']