mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-30 09:11:07 +00:00
Merge branch 'master' of github.com:trezor/python-trezor
This commit is contained in:
commit
c47065fb11
@ -57,7 +57,7 @@ How to install (Windows)
|
|||||||
|
|
||||||
How to install (Debian-Ubuntu)
|
How to install (Debian-Ubuntu)
|
||||||
------------------------------
|
------------------------------
|
||||||
* sudo apt-get install python-dev python-setuptools cython libusb-1.0-0-dev libudev-dev
|
* sudo apt-get install python-dev python-setuptools cython libusb-1.0-0-dev libudev-dev git
|
||||||
* git clone https://github.com/trezor/python-trezor.git
|
* git clone https://github.com/trezor/python-trezor.git
|
||||||
* cd python-trezor
|
* cd python-trezor
|
||||||
* python setup.py install (or develop)
|
* python setup.py install (or develop)
|
||||||
|
@ -7,7 +7,7 @@ import mapping
|
|||||||
from transport import Transport
|
from transport import Transport
|
||||||
import messages_pb2 as proto
|
import messages_pb2 as proto
|
||||||
|
|
||||||
TREZORD_HOST = 'http://localhost:21324'
|
TREZORD_HOST = 'https://localback.net:21324'
|
||||||
CONFIG_URL = 'https://mytrezor.com/data/plugin/config_signed.bin'
|
CONFIG_URL = 'https://mytrezor.com/data/plugin/config_signed.bin'
|
||||||
|
|
||||||
def get_error(resp):
|
def get_error(resp):
|
||||||
@ -22,11 +22,13 @@ class BridgeTransport(Transport):
|
|||||||
|
|
||||||
config = r.text
|
config = r.text
|
||||||
|
|
||||||
r = requests.post(TREZORD_HOST + '/configure', data=config)
|
self.conn = requests.Session();
|
||||||
|
|
||||||
|
r = self.conn.post(TREZORD_HOST + '/configure', data=config)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise Exception('trezord: Could not configure' + get_error(r))
|
raise Exception('trezord: Could not configure' + get_error(r))
|
||||||
|
|
||||||
r = requests.get(TREZORD_HOST + '/enumerate')
|
r = self.conn.get(TREZORD_HOST + '/enumerate')
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise Exception('trezord: Could not enumerate devices' + get_error(r))
|
raise Exception('trezord: Could not enumerate devices' + get_error(r))
|
||||||
enum = r.json()
|
enum = r.json()
|
||||||
@ -41,14 +43,14 @@ class BridgeTransport(Transport):
|
|||||||
super(BridgeTransport, self).__init__(device, *args, **kwargs)
|
super(BridgeTransport, self).__init__(device, *args, **kwargs)
|
||||||
|
|
||||||
def _open(self):
|
def _open(self):
|
||||||
r = requests.post(TREZORD_HOST + '/acquire/%s' % self.path)
|
r = self.conn.post(TREZORD_HOST + '/acquire/%s' % self.path)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise Exception('trezord: Could not acquire session' + get_error(r))
|
raise Exception('trezord: Could not acquire session' + get_error(r))
|
||||||
resp = r.json()
|
resp = r.json()
|
||||||
self.session = resp['session']
|
self.session = resp['session']
|
||||||
|
|
||||||
def _close(self):
|
def _close(self):
|
||||||
r = requests.post(TREZORD_HOST + '/release/%s' % self.session)
|
r = self.conn.post(TREZORD_HOST + '/release/%s' % self.session)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise Exception('trezord: Could not release session' + get_error(r))
|
raise Exception('trezord: Could not release session' + get_error(r))
|
||||||
else:
|
else:
|
||||||
@ -61,7 +63,7 @@ class BridgeTransport(Transport):
|
|||||||
cls = protobuf_msg.__class__.__name__
|
cls = protobuf_msg.__class__.__name__
|
||||||
msg = protobuf_json.pb2json(protobuf_msg)
|
msg = protobuf_json.pb2json(protobuf_msg)
|
||||||
payload = '{"type": "%s", "message": %s}' % (cls, json.dumps(msg))
|
payload = '{"type": "%s", "message": %s}' % (cls, json.dumps(msg))
|
||||||
r = requests.post(TREZORD_HOST + '/call/%s' % self.session, data=payload)
|
r = self.conn.post(TREZORD_HOST + '/call/%s' % self.session, data=payload)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise Exception('trezord: Could not write message' + get_error(r))
|
raise Exception('trezord: Could not write message' + get_error(r))
|
||||||
else:
|
else:
|
||||||
|
@ -52,12 +52,15 @@ def opcode_serialize(opcode):
|
|||||||
except:
|
except:
|
||||||
raise Exception('Unknown script opcode: %s' % opcode)
|
raise Exception('Unknown script opcode: %s' % opcode)
|
||||||
|
|
||||||
def insight_tx(url):
|
def insight_tx(url, rawdata=False):
|
||||||
|
if not rawdata:
|
||||||
try:
|
try:
|
||||||
f = urllib2.urlopen(url)
|
f = urllib2.urlopen(url)
|
||||||
|
data = json.load(f)
|
||||||
except:
|
except:
|
||||||
raise Exception('URL error: %s' % url)
|
raise Exception('URL error: %s' % url)
|
||||||
data = json.load(f)
|
else:
|
||||||
|
data = url
|
||||||
|
|
||||||
t = proto_types.TransactionType()
|
t = proto_types.TransactionType()
|
||||||
t.version = data['version']
|
t.version = data['version']
|
||||||
@ -81,7 +84,7 @@ def insight_tx(url):
|
|||||||
|
|
||||||
for vout in data['vout']:
|
for vout in data['vout']:
|
||||||
o = t.bin_outputs.add()
|
o = t.bin_outputs.add()
|
||||||
o.amount = int(Decimal(vout['value']) * 100000000)
|
o.amount = int(Decimal(str(vout['value'])) * 100000000)
|
||||||
asm = vout['scriptPubKey']['asm'].split(' ')
|
asm = vout['scriptPubKey']['asm'].split(' ')
|
||||||
asm = [ opcode_serialize(x) for x in asm ]
|
asm = [ opcode_serialize(x) for x in asm ]
|
||||||
o.script_pubkey = ''.join(asm)
|
o.script_pubkey = ''.join(asm)
|
||||||
|
Loading…
Reference in New Issue
Block a user