pik / pypayd

a small daemon for processing bitcoin payments
MIT License
5 stars 4 forks source link

i really does not know why it was working before #4

Closed ser closed 9 years ago

ser commented 9 years ago

Now it does not work at all. The problem is that many of config.py values are being parsed incorrectly, and we have for example:

requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionRefusedError(111, 'Connection refused'))

I had to change line in src/interfaces/insight.py from: if config.LOCAL_BLOCKCHAIN: to if config.LOCAL_BLOCKCHAIN == True:

And it is just beginning, most of values are treated as string, and we have for example:

DB loaded: paypayd_testnet.db
Testing Blockchain connection {'startTs': 1437806621545, 'endTs': 1437806629345, 'blockChainHeight': 508874, 'type': 'from RPC calls', 'status': 'finished', 'height': 508874, 'syncPercentage': '100.000', 'error': None}
Payment Handler loaded, starting auto-poller..
API Started on 127.0.0.1:3080
Traceback (most recent call last):
  File "pypayd.py", line 134, in <module>
    api_serv.serve_forever(payment_handler, threaded=False)
  File "/tmp/pypayd/src/api.py", line 23, in serve_forever
    self._run(payment_handler)
  File "/tmp/pypayd/src/api.py", line 101, in _run
    self.server.start()
  File "/usr/lib/python3.4/site-packages/cherrypy/wsgiserver/wsgiserver3.py", line 1639, in start
    self.bind(af, socktype, proto)
  File "/usr/lib/python3.4/site-packages/cherrypy/wsgiserver/wsgiserver3.py", line 1707, in bind
    self.socket.bind(self.bind_addr)
TypeError: an integer is required (got type str)

because self.server = wsgiserver.CherryPyWSGIServer((config.RPC_HOST, config.RPC_PORT), d) config.RPC is a string, and cherrypy expects and integer.

When I fix few next problem, I am getting finally:

print(response)

{'error': {'data': {'args': ["unsupported operand type(s) for -: 'float' and 'str'"], 'type': 'TypeError', 'message': "unsupported operand type(s) for -: 'float' and 'str'"}, 'message': 'Invalid params', 'code': -32602}, 'jsonrpc': '2.0', 'id': 0}

which killed my enthusiasm with fixing attempts :(

I am not able to enumerate all errors, but all of them are related to values being strings, not floats or integers. Is it related to new python Python 3.4.3 (default, Mar 25 2015, 17:13:50)?

How to fix it, as currently pypayd does not work at all :( Please help :)

pik commented 9 years ago

Ah, I'm guessing you were using the textfile for the config values and they were not getting parsed correctly. I don't remember now whether ConfigObject was supposed to do this for us but this wouldn't have happened if I had bothered to add unit tests for it.

It should be fixed with: https://github.com/pik/pypayd/commit/aca85f19342ad5035872442d6222de18c3a292bd

If it's not - let me know.

ser commented 9 years ago

Nearly works, two more problems in config

1)

configobj.ConfigObjError: Parsing failed with several errors.
First error at line 39.

line 39 is:

STATE = {"last_order_updates": {"order_id":None, "timestamp": None}}

2)

configobj.DuplicateError: Duplicate keyword name at line 40.

and indeed, DB = None is two times there.

ser commented 9 years ago

And more.

I am not sure if I am doing it properly, but I copy config.py do pypayd.conf, adding [Default] on the top and running pypayd:

$ pypayd --server --testnet wallet --from-file payment_wallet.txt --decrypt-pw PlePle
Loading config settings...
Error handling config file field DEFAULT_KEYPATH, 0/0/1
Error handling config file field DEFAULT_TICKER, insight
Error handling config file field DEFAULT_CURRENCY, EUR
Error handling config file field DEFAULT_WALLET_FILE, wallet.txt
Error handling config file field DEFAULT_WALLET_PASSWORD, foobar
Error handling config file field DEFAULT_DB, pypayd.db
Error handling config file field DEFAULT_TESTNET_DB, paypayd_testnet.db
Error handling config file field RPC_HOST, 127.0.0.1
Error handling config file field BLOCKCHAIN_CONNECT, http://localhost:3001
Error handling config file field BLOCKCHAIN_SERVICE, insight
Error handling config file field LEAF_POLL_LIFE, ORDER_LIFE*2
Error handling config file field MAX_LOG_SIZE, 16*1024*1024
Error handling config file field DATA_DIR, 
Error handling config file field RPC_USER, user
Error handling config file field RPC_PASSWORD, password
Wallet loaded: tpubD6NzVbkrYhZ4Wd7mrkT4sRtV69mJWukWtMxXQjH7mrHAqRCbg8UDi4vUKo8PfR8iLtF2nzAoASLo7eEBC1kQ3x8mHKSLhd3nUAsusqQhuWq
Keypath: 0/0/1
/home/ser/.local/share/pypayd paypayd_testnet.db 

DB loaded: paypayd_testnet.db
Testing Blockchain connection {'error': None, 'type': 'from RPC calls', 'blockChainHeight': 508918, 'startTs': 1437840126281, 'height': 508918, 'syncPercentage': '100.000', 'status': 'finished', 'endTs': 1437840126644}
Payment Handler loaded, starting auto-poller..
API Started on 127.0.0.1:3080
Current block is 509036 polling 1 active addresses
calling insight api for address info moKpo8xQGajDgpBVjnfBomMNWsVB3PnZfR
Current block is 509036 polling 1 active addresses
calling insight api for address info moKpo8xQGajDgpBVjnfBomMNWsVB3PnZfR

Why those above config values are incorrect?

pik commented 9 years ago

Oh yeah don't copy that ^_^ (e.g. STATE is internal to config), I should probably clarify some of that. Just over-write the things you want to over-write in pypayd.conf. The presedence order is:

config.py
pypayd.conf
commandline args
ser commented 9 years ago

still problems, the pypayd.conf content is now:

[Default]
DEFAULT_TICKER = 'bitstamp'
DEFAULT_CURRENCY = 'EUR'
DEFAULT_WALLET_FILE = 'payment_wallet.txt'
DEFAULT_WALLET_PASSWORD = "PlePle"
GEN_NEW = True
#delay between requests to the blockchain service for new transactions
POLLING_DELAY = 10
UPDATE_ON_CONFIRM = 2 #can also take a list, such as [6, 20, 100]

and i get:

Error handling config file field DEFAULT_TICKER, bitstamp
Error handling config file field DEFAULT_CURRENCY, EUR
Error handling config file field DEFAULT_WALLET_FILE, payment_wallet.txt
Error handling config file field DEFAULT_WALLET_PASSWORD, PlePle
pik commented 9 years ago

Yeah sorry about that - can you try again with the commit I just pushed?

ser commented 9 years ago

Yup, now it is parsed properly, cheers :+1:

But there is another issue, the currency. Am I able to specify an other currency than USD?

API Exception: {'type': 'KeyError', 'message': "'EUR'", 'args': ('EUR',)}
Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/jsonrpc/manager.py", line 108, in _get_responses
    result = method(*request.args, **request.kwargs)
  File "/usr/share/pypayd/src/api.py", line 39, in create_order
    ret = payment_handler.createOrder(amount, currency, item_number, order_id, gen_new)
  File "/usr/share/pypayd/src/payments.py", line 181, in createOrder
    btc_price = str(ticker.getPriceInBTC(amount, currency=currency))
  File "/usr/share/pypayd/src/priceinfo.py", line 48, in getPriceInBTC
    btc_price = D(str(self.getPrice(currency=currency, ticker=ticker)))
  File "/usr/share/pypayd/src/priceinfo.py", line 40, in getPrice
    btc_price, last_updated = self.tickers[ticker][currency.upper()]()
KeyError: 'EUR'
pik commented 9 years ago

@ser

It was planned but I never got around to testing the other ones =/

I've made some adjustments so coindesk ticker should work with any currency they support now (i've only tested 'EUR' and 'GBP' so far though). I'll try and find some time later this week to add the missing tests for this and a guide to adding your own priceinfo ticker.

ser commented 9 years ago

Hi Alex, it's fantastic, I can read your recent commit and see how it is done. I think I will be able to add other currencies by my own if I need it.

Thanks again, now pypayd service is ready for the client deployment, which will be GPL and I hope that it will be a nice complimentary use case for pypayd.

Cheers!