electrum icon indicating copy to clipboard operation
electrum copied to clipboard

merchant.py list index out of range

Open mauritsvdvijgh opened this issue 11 years ago • 4 comments

electrum/scripts/merchant$ python merchant.py request 0.1 2 120
Traceback (most recent call last):
  File "merchant.py", line 255, in <module>
    ret = send_command(cmd, params)
  File "merchant.py", line 165, in send_command
    out = f(*params)
  File "/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py", line 274, in __call__
    return self.__send(self.__name, args)
  File "/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py", line 225, in _request
    check_for_errors(response)
  File "/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py", line 529, in check_for_errors
    raise ProtocolError((code, message))
jsonrpclib.jsonrpc.ProtocolError: (-32603, u'Server error:   File "/usr/local/lib/python2.7/dist-packages/Electrum-2.0-py2.7.egg/electrum/account.py", line 43, in get_address | IndexError: list index out of range')
starting daemon (PID 1509)
num rows 0
127.0.0.1 - - [10/Dec/2014 22:24:36] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [10/Dec/2014 22:24:47] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [10/Dec/2014 22:25:40] "POST / HTTP/1.1" 200 -

I tried it with 1.9.8 and got to the KeyError: \'0\''), I tried it with 2.0 (github master branch), generating wallets from 2.0 GUI and putting them in the right folder etc.

out = f(*params)
*** ProtocolError: (-32603, u'Server error:   File "/usr/local/lib/python2.7/dist-packages/Electrum-2.0-py2.7.egg/electrum/account.py", line 43, in get_address | IndexError: list index out of range')
params
['0.1', '2', '120', 'password']
(Pdb) num
0

It seems like it returns an empty list, because num was 0 at the time (PDB)

Is this a bug/did I miss something/did I do something stupid? If I don't know the answer to this question should I be adding an issue here at all?

def process_request(amount, confirmations, expires_in, password):
    global num
    if password != my_password:
        return "wrong password"

    try:
        amount = float(amount)
        confirmations = int(confirmations)
        expires_in = float(expires_in)
    except Exception:
        return "incorrect parameters"

    account = wallet.default_account()
    addr = account.get_address(0, num)
    num += 1

    out_queue.put( ('request', (addr, amount, confirmations, expires_in) ))
    return addr

mauritsvdvijgh avatar Dec 10 '14 22:12 mauritsvdvijgh

Found the fix. The wallet generated by the merchant.py script didn't generate any receiving addresses.

After opening it with the 2.0 client it generated 5 addresses. When I started the merchant.py script with the wallet after opening it with the client it worked.

mauritsvdvijgh avatar Dec 18 '14 11:12 mauritsvdvijgh

Reopened.

The merchant.py script doesn't seem to regenerate address. It runs out after a while and then it returns the list index out of range error.

mauritsvdvijgh avatar Dec 19 '14 20:12 mauritsvdvijgh

I get this on windows also:

$ python merchant.py request 0.1 2 120
Traceback (most recent call last):
  File "merchant.py", line 255, in <module>
    ret = send_command(cmd, params)
  File "merchant.py", line 165, in send_command
    out = f(*params)
  File "C:\Python27\lib\site-packages\jsonrpclib\jsonrpc.py", line 274, in __call__
    return self.__send(self.__name, args)
  File "C:\Python27\lib\site-packages\jsonrpclib\jsonrpc.py", line 225, in _request
    check_for_errors(response)
  File "C:\Python27\lib\site-packages\jsonrpclib\jsonrpc.py", line 529, in check_for_errors
    raise ProtocolError((code, message))
jsonrpclib.jsonrpc.ProtocolError: (-32603, u'Server error:   File "C:\\Python27\\lib\\site-packages\\electrum-2.0-py2.7.egg\\electrum\\account.py", line 43, in get_address | IndexError: list index out of range')

I think creating new addresses is done by running the synchronize method on the wallet.

https://github.com/spesmilo/electrum/blob/master/lib/synchronizer.py#L89

After digging deeper, it appears synchronize (for merchant.py) is disabled on purpose:

https://github.com/spesmilo/electrum/blob/master/scripts/merchant/merchant.py#L280

Could someone shed light on why this is done? Add some more docs?

MetaMemoryT avatar Feb 08 '15 18:02 MetaMemoryT

You can generate new address instead if there is no pre-calculated address there.

account = wallet.default_account()
try:
    addr = account.get_address(0, num)
except IndexError:
    # create new address if there is no pre-created addresses
    addr = wallet.create_new_address(account, False)
num += 1

art4melody avatar Feb 11 '15 11:02 art4melody