Repository: spesmilo/electrum

Issue:
[linux-debian] btchip "Invalid literal for Decimal"
when I try to send I get this error:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/Electrum-2.3.2-py2.7.egg/electrum_gui/qt/util.py", line 37, in run
    self.result = self.run_task()
  File "/usr/local/lib/python2.7/dist-packages/Electrum-2.3.2-py2.7.egg/electrum_gui/qt/main_window.py", line 1113, in sign_thread
    self.wallet.sign_transaction(tx, password)
  File "/usr/local/lib/python2.7/dist-packages/Electrum-2.3.2-py2.7.egg/electrum_plugins/btchipwallet.py", line 341, in sign_transaction
    raise BaseException(tx.error)
BaseException: Invalid literal for Decimal: '0,0001'



Discussion:
@btchip this is for you

![errore-electrum](https://cloud.githubusercontent.com/assets/925909/8311848/6be18fe4-19d9-11e5-8b81-a98004066388.png)

ok, that sounds like a locale problem. I'll try to reproduce it to see what's causing it.

maybe have a look at format_satoshis_plain in util.py

Debian 8 Jessie released, clean and newly installed. Chose KDE as a graphical interface.
Italian language chosen and followed as written in the pastebin (written by me to keep track): http://pastebin.com/Fc8TDPC5

could be worth a try, @ziomik can you try to replace all occurrences of format_satoshis by format_satoshis_plain in plugins/btchipwallet.py and retry ?

I made the requested change and now it works. was born a new problem that is displayed after inserting the keycard (obviously correct)

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/Electrum-2.3.2-py2.7.egg/electrum_gui/qt/util.py", line 37, in run
    self.result = self.run_task()
  File "/usr/local/lib/python2.7/dist-packages/Electrum-2.3.2-py2.7.egg/electrum_gui/qt/main_window.py", line 1113, in sign_thread
    self.wallet.sign_transaction(tx, password)
  File "/usr/local/lib/python2.7/dist-packages/Electrum-2.3.2-py2.7.egg/electrum_plugins/btchipwallet.py", line 341, in sign_transaction
    raise BaseException(tx.error)
BaseException: Could not connect to your BTChip dongle. Please verify access permissions, PIN, or unplug the dongle and plug it again
![errore-electrum1](https://cloud.githubusercontent.com/assets/925909/8315029/d59d8b54-19ed-11e5-99c7-a31cccc742cf.png)
Tried several times

Are you using it in Ledger Wallet mode (paired with an external printed keycard) or in HW.1 mode (where you need to insert it / remove it again to read the PIN) ? 

I am using a HW.1. I tried to pull it out and put it when I asked the first pin but I got this error:

![errore-electrum2](https://cloud.githubusercontent.com/assets/925909/8315266/b54a9368-19ef-11e5-92e6-c5c069d5c55a.png)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/Electrum-2.3.2-py2.7.egg/electrum_gui/qt/util.py", line 37, in run
    self.result = self.run_task()
  File "/usr/local/lib/python2.7/dist-packages/Electrum-2.3.2-py2.7.egg/electrum_gui/qt/main_window.py", line 1113, in sign_thread
    self.wallet.sign_transaction(tx, password)
  File "/usr/local/lib/python2.7/dist-packages/Electrum-2.3.2-py2.7.egg/electrum_plugins/btchipwallet.py", line 341, in sign_transaction
    raise BaseException(tx.error)
BaseException: Exception : Invalid status 6a80

ok, have you used it once with the Ledger Wallet Chrome application or is it an "old" HW.1 bought before Ledger was selling them ? 

If it's an old HW.1, the sequence to sign is the following 
- Remove it 
- Insert it again on the same computer / different program or different computer where it can type
- Read the second factor string and 2FA code
- Plug it back into the first computer (or remove it, insert it again) 
- Enter this 2FA code

And if it's a HW.1 paired with Ledger Wallet Chrome application you don't need to remove it, you can directly enter the Security Card matching characters. 

It is a HW.1 purchased from a few weeks. firmware 1.0.1
It works great with ledgerwallet in paring with my smartphone.
I have, perhaps, remove the paring to use the same wallet of electrum?

No, you don't have to remove the pairing. Electrum should prompt you to match the security card, not to remove / insert again the chip. If that's what you see, I'll try to modify something that you can test.

All right. I look forward to some changes. thanks
Edit: I Specific data are requested card security. The error I am told at the end of data entry


Resolving patch:
diff --git a/plugins/btchipwallet.py b/plugins/btchipwallet.py
--- a/plugins/btchipwallet.py
+++ b/plugins/btchipwallet.py
@@ -16,7 +16,7 @@
 from electrum.transaction import deserialize
 from electrum.wallet import BIP32_HD_Wallet, BIP32_Wallet
 
-from electrum.util import format_satoshis
+from electrum.util import format_satoshis_plain
 import hashlib
 
 try:
@@ -396,8 +396,8 @@ def sign_transaction(self, tx, password):
             while inputIndex < len(inputs):
                 self.get_client().startUntrustedTransaction(firstTransaction, inputIndex, 
                 trustedInputs, redeemScripts[inputIndex])
-                outputData = self.get_client().finalizeInput(output, format_satoshis(outputAmount), 
-                format_satoshis(self.get_tx_fee(tx)), changePath, bytearray(rawTx.decode('hex')))
+                outputData = self.get_client().finalizeInput(output, format_satoshis_plain(outputAmount), 
+                format_satoshis_plain(self.get_tx_fee(tx)), changePath, bytearray(rawTx.decode('hex')))
                 if firstTransaction:
                     transactionOutput = outputData['outputData']
                 if outputData['confirmationNeeded']:                
@@ -430,9 +430,9 @@ def sign_transaction(self, tx, password):
                         if not confirmed:
                             raise Exception('Aborted by user')                                            
                         pin = pin.encode()
-                    self.client.bad = True
-                    self.device_checked = False
-                    self.get_client(True)
+                        self.client.bad = True
+                        self.device_checked = False
+                        self.get_client(True)
                     waitDialog.start("Signing ...")
                 else:
                     # Sign input with the provided PIN


Test patch: