Merge branch 'master' of github.com:spesmilo/electrum
This commit is contained in:
commit
66ff854d78
|
@ -2119,17 +2119,25 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
return self.tx_from_text(file_content)
|
return self.tx_from_text(file_content)
|
||||||
|
|
||||||
def do_process_from_text(self):
|
def do_process_from_text(self):
|
||||||
|
from electrum.transaction import SerializationError
|
||||||
text = text_dialog(self, _('Input raw transaction'), _("Transaction:"), _("Load transaction"))
|
text = text_dialog(self, _('Input raw transaction'), _("Transaction:"), _("Load transaction"))
|
||||||
if not text:
|
if not text:
|
||||||
return
|
return
|
||||||
|
try:
|
||||||
tx = self.tx_from_text(text)
|
tx = self.tx_from_text(text)
|
||||||
if tx:
|
if tx:
|
||||||
self.show_transaction(tx)
|
self.show_transaction(tx)
|
||||||
|
except SerializationError as e:
|
||||||
|
self.show_critical(_("Electrum was unable to deserialize the transaction:") + "\n" + str(e))
|
||||||
|
|
||||||
def do_process_from_file(self):
|
def do_process_from_file(self):
|
||||||
|
from electrum.transaction import SerializationError
|
||||||
|
try:
|
||||||
tx = self.read_tx_from_file()
|
tx = self.read_tx_from_file()
|
||||||
if tx:
|
if tx:
|
||||||
self.show_transaction(tx)
|
self.show_transaction(tx)
|
||||||
|
except SerializationError as e:
|
||||||
|
self.show_critical(_("Electrum was unable to deserialize the transaction:") + "\n" + str(e))
|
||||||
|
|
||||||
def do_process_from_txid(self):
|
def do_process_from_txid(self):
|
||||||
from electrum import transaction
|
from electrum import transaction
|
||||||
|
|
|
@ -25,7 +25,7 @@ class ElectrumGui:
|
||||||
self.config = config
|
self.config = config
|
||||||
self.network = daemon.network
|
self.network = daemon.network
|
||||||
storage = WalletStorage(config.get_wallet_path())
|
storage = WalletStorage(config.get_wallet_path())
|
||||||
if not storage.file_exists:
|
if not storage.file_exists():
|
||||||
print("Wallet not found. try 'electrum create'")
|
print("Wallet not found. try 'electrum create'")
|
||||||
exit()
|
exit()
|
||||||
if storage.is_encrypted():
|
if storage.is_encrypted():
|
||||||
|
|
|
@ -30,7 +30,7 @@ class TestBCDataStream(unittest.TestCase):
|
||||||
for v in values:
|
for v in values:
|
||||||
self.assertEqual(s.read_compact_size(), v)
|
self.assertEqual(s.read_compact_size(), v)
|
||||||
|
|
||||||
with self.assertRaises(IndexError):
|
with self.assertRaises(transaction.SerializationError):
|
||||||
s.read_compact_size()
|
s.read_compact_size()
|
||||||
|
|
||||||
def test_string(self):
|
def test_string(self):
|
||||||
|
|
|
@ -77,10 +77,7 @@ class BCDataStream(object):
|
||||||
if self.input is None:
|
if self.input is None:
|
||||||
raise SerializationError("call write(bytes) before trying to deserialize")
|
raise SerializationError("call write(bytes) before trying to deserialize")
|
||||||
|
|
||||||
try:
|
|
||||||
length = self.read_compact_size()
|
length = self.read_compact_size()
|
||||||
except IndexError:
|
|
||||||
raise SerializationError("attempt to read past end of buffer")
|
|
||||||
|
|
||||||
return self.read_bytes(length).decode(encoding)
|
return self.read_bytes(length).decode(encoding)
|
||||||
|
|
||||||
|
@ -117,6 +114,7 @@ class BCDataStream(object):
|
||||||
def write_uint64(self, val): return self._write_num('<Q', val)
|
def write_uint64(self, val): return self._write_num('<Q', val)
|
||||||
|
|
||||||
def read_compact_size(self):
|
def read_compact_size(self):
|
||||||
|
try:
|
||||||
size = self.input[self.read_cursor]
|
size = self.input[self.read_cursor]
|
||||||
self.read_cursor += 1
|
self.read_cursor += 1
|
||||||
if size == 253:
|
if size == 253:
|
||||||
|
@ -126,6 +124,8 @@ class BCDataStream(object):
|
||||||
elif size == 255:
|
elif size == 255:
|
||||||
size = self._read_num('<Q')
|
size = self._read_num('<Q')
|
||||||
return size
|
return size
|
||||||
|
except IndexError:
|
||||||
|
raise SerializationError("attempt to read past end of buffer")
|
||||||
|
|
||||||
def write_compact_size(self, size):
|
def write_compact_size(self, size):
|
||||||
if size < 0:
|
if size < 0:
|
||||||
|
@ -143,8 +143,11 @@ class BCDataStream(object):
|
||||||
self._write_num('<Q', size)
|
self._write_num('<Q', size)
|
||||||
|
|
||||||
def _read_num(self, format):
|
def _read_num(self, format):
|
||||||
|
try:
|
||||||
(i,) = struct.unpack_from(format, self.input, self.read_cursor)
|
(i,) = struct.unpack_from(format, self.input, self.read_cursor)
|
||||||
self.read_cursor += struct.calcsize(format)
|
self.read_cursor += struct.calcsize(format)
|
||||||
|
except Exception as e:
|
||||||
|
raise SerializationError(e)
|
||||||
return i
|
return i
|
||||||
|
|
||||||
def _write_num(self, format, num):
|
def _write_num(self, format, num):
|
||||||
|
|
Loading…
Reference in New Issue