Coder Social home page Coder Social logo

pypayd's Introduction

pypayd

Pypayd is a minimalistic daemon for accepting bitcoin payments. This is meant to be a good alternative if you do not want setup an account with a third-party payment processor. Pypayd provides an API for creating orders and automatically records order fulfillment (payment received) as well as invalid payments.

Pypayd automatically creates receiving addresses from it's own wallet, a wrapper around the pycoin implementation of BIP32. The wallet (can generate addresses from a public or private master-key (note that there is no need to store the private key on the server). It also supports loading keys from mnemonic, byte-string, or encrypted file.

installation

For now the recomended installation method is to use git clone https://github.com/pik/pypayd.git following that cd into the pypayd directory and execute pip install -r pip-requirements.txt, with this you should be good to go (one thing to note is that in some cases APSW may require manual installation).

configuration

You are able to configure pypayd via creating pypayd.conf file. Consult src/config.py for configuration values.

currency exchange rates

Currently there are three sources of live currency exehange rates available:

example usage

Obtain an encrypted-file with a publickey on an offline server from a mnemonic:

python pypayd.py wallet --from-mnemonic "cigarette add choice joke guess process blood freak rise favorite write pen" --mnemonic-type="electrum" --to-file="payment_wallet.txt" --encrypt-pw="foobar"

This will generate a BIP32 wallet from the mnemonic and save only the master public key to an encrypted file. CP the file to your online server. Then run pypayd:

python pypayd.py --server wallet --from-file="payment_wallet.txt" --encrypt-pw="foobar"

Then from your webserver (i.e. to create an order for a payment of 20 usd):

import requests
import json
url = "http://127.0.0.1:3080"
headers = {'content-type': 'application/json'}
payload = {
    "method": "create_order",
    "params": {"amount": 20.0, "qr_code": True},
    "jsonrpc": "2.0",
    "id": 0,
}
response = requests.post( url, data=json.dumps(payload), headers=headers).json()

This will return an automatically created order_id, a price converted to Bitcoin from the DEFAULT_CURRENCY by the DEFAULT_TICKER, a receiving address, as well as a time left on the transaction (note that the timeleft on the transaction is the time-lapse after which a payment received for the order will not be considered valid; it may be preferable to set a longer TX_LIFE then the one displayed to the customer). The full argument list for create_order as follows:

* amount          order amount in native currency
* currency        takes a string such as 'USD', config.DEFAULT_CURRENCY if none
* item_number     specify an item-number to associate  with the order in the database
* order_id        specify an order-id, if one is not given an order-id will be created by hashing other order attributes
* gen_new         generate a new address for the order if True, otherwise uses config settings
* qr_code         generate a qr_code for the corresponding receiving address if True

dependencies

  • Python3
  • See pip-requirements.txt

to do

See the TODO list.

interfaces

Pypayd supports insight-api (run locally or hosted: https://insight.bitpay.com/) and blockr (https://blockr.io/). I'll probably add support for jmcorgan's fork of bitcoin-core with address indexing in the near future. To configure set BLOCKCHAIN_SERVICE to the interface Pypayd should load ("insight" or "blockr") and BLOCKCHAIN_CONNECT to the complete url in the pypayd.conf file.

pypayd's People

Contributors

pik avatar ser avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pypayd's Issues

Wallet generation

Hi,
I'm installing the whole environment from scratch, to be sure everything is clean.

First problem - I'm not able to generate a wallet:

$ python pypayd.py wallet --from-mnemonic "cigarette add choice joke guess process blood freak rise favorite write pen" --mnemonic-type="electrumseed" --to-file="payment_wallet.txt" --encrypt-pw="foobar"
Loading config settings...
Wallet loaded: tpubD6NzVbkrYhZ4X7VCD5BSWE6nkDvU4c1cLDzVZT1RhXEkBYMh2f74RXb76bRfPQcR2EqDDPewP1B1jCFqAUSzqww22qeg9e5Kw9ZPPH61zxF
Keypath: 0/0/1
Traceback (most recent call last):
  File "pypayd.py", line 164, in <module>
    pypay_wallet.toEncryptedFile(password = args.encrypt_pw, file_name = (args.to_file or config.DEFAULT_WALLET_FILE), store_private = args.output_private, force=args.overwrite)
  File "/home/ser/pypayd/src/wallet.py", line 110, in toEncryptedFile
    data = simplecrypt.encrypt(password, json_for_wallet(store_private))
NameError: name 'json_for_wallet' is not defined

i really does not know why it was working before

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 :)

TypeError: unorderable types: list() > int()

Sorry, still some problems. I've produced an invoice, sent money and pypayd is catching an exception here:

https://github.com/pik/pypayd/blob/master/src/payments.py#L131

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/share/pypayd/src/payments.py", line 63, in _run
    self.pollActiveAddresses()
  File "/usr/share/pypayd/src/payments.py", line 103, in pollActiveAddresses
    self.pollAddress(addr)
  File "/usr/share/pypayd/src/payments.py", line 92, in pollAddress
    self.processTxIn(addr, tx)
  File "/usr/share/pypayd/src/payments.py", line 131, in processTxIn
    if len(orders > 1):
TypeError: unorderable types: list() > int()

setup and license

Hi, your software looks very promising, it is nearly exactly what I was planning to write, good I have spotted it before I started.

Three questions:

  1. Do you plan to create a standard setup.py file for installation?
  2. What is the license? AGPL3 would be perfect :-)
  3. Do you use it in any project? If yes, is the code open to have a look?

Cheers!
Serge

SyntaxError: invalid syntax

Hi, after recent changes something got wrong. A fresh installation cloned from github:

$ python pypayd.py 
Traceback (most recent call last):
  File "pypayd.py", line 9, in <module>
    from src import wallet, db, payments, api, config
  File "/opt/pypayd/src/wallet.py", line 69
    def __init__(self, *args, keypath=None, testnet=config.TESTNET,**kwargs): 
                                    ^
SyntaxError: invalid syntax

amount of confirmations when blockr in use is ignored

Hi,
it seems that amount of confirmations from config file is being ignored and pypayd always waits for 6 of them, at least when you use blockr BTC test chain. I am not able to check test insight, as it is broken for several weeks now, which is strange, BTW.

wallet creation issues

Hi, it is not the end of problems :-) Following quick example:

$ python pypayd.py wallet --from-mnemonic "like just love know never want time out there make look eye" --mnemonic-type="electrum" --to-file="payment_wallet.txt" --encrypt-pw="foobar"
usage: pypayd [-h] [-S] [-V] [-v] [--testnet] [--data-dir DATA_DIR]
              [--config-file CONFIG_FILE] [--log-file LOG_FILE]
              [--pid-file PID_FILE] [--rpc-host RPC_HOST]
              [--rpc-port RPC_PORT]
              {wallet} ...
pypayd: error: unrecognized arguments: --mnemonic-type=electrum

and it is not strange, because $ python pypayd.py wallet --help does not offer such a parameter, indeed.

Worse is, that it does not work at all:

$ python pypayd.py wallet --from-mnemonic "like just love know never want time out there make look eye" --to-file="payment_wallet.txt" --encrypt-pw="foobar"
Loading config settings...
['BIP32Node', 'EncodingError', 'Key', 'KeyPath', 'NETCODES', 'PublicPrivateMismatchError', 'PyPayWallet', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'a2b_hashed_base58', 'b2a_hashed_base58', 'config', 'decrypt', 'encrypt', 'from_bytes_32', 'hashlib', 'hmac', 'itertools', 'json', 'mnemonicToEntropy', 'netcode_and_type_for_data', 'os', 'prv32_prefix_for_netcode', 'pub32_prefix_for_netcode', 'public_pair_to_hash160_sec', 'sec_to_public_pair', 'struct', 'subkey_public_pair_chain_code_pair', 'subkey_secret_exponent_chain_code_pair', 'time', 'to_bytes_32'] PPP\m
Traceback (most recent call last):
  File "pypayd.py", line 109, in <module>
    pypay_wallet = wallet.PyPayWallet.fromMnemonic(args.mnemonic)  
AttributeError: 'Namespace' object has no attribute 'mnemonic'  

PS
I have installed mnemonic from pip, is it the correct one, or it is completely unrelated module?

# pip install mnemonic
Collecting mnemonic
  Downloading mnemonic-0.12.tar.gz
Collecting pbkdf2 (from mnemonic)
  Downloading pbkdf2-1.3.tar.gz
Installing collected packages: pbkdf2, mnemonic
  Running setup.py install for pbkdf2
  Running setup.py install for mnemonic
Successfully installed mnemonic-0.12 pbkdf2-1.3

Proposal: swap to HD wallet through bip32utils

Hi Alex,
as I can see you don't have to much time recently to solve wallet-related stuff.

My proposal is to switch pypayd to clearly use HD wallet's xprv and xpub by utilising https://github.com/jmcorgan/bip32utils for wallet generation. It will make pypayd compatible with many LiveNet and TestNet wallets, according to the data from: https://bitcointalk.org/index.php?topic=1000544.0

What do you think about it? If you agree, and find time for the code audit, I think am able to prepare a PR.

Fork of pypayd as pypayd-ng

Hi Alex,
I've decided to fork pypayd and created https://github.com/ser/pypayd-ng

Main changes are related to wallet handling and I swapped apsw for sqlalchemy to allow use of other databases in future.

I've reorganised directories to make PyPi distribution and CI integration.

The only thing which is missing is the main test, which does not work for now - I will be slowly fixing it.

counterwallet for testnet

Hi,
it's not clear for me how to manage my bitcoin saldo in counterwallet or an other wallet.

I'm creating and using a testnet pypayd wallet:

python pypayd.py wallet --from-mnemonic "above written line voice roll mumble alter hello steel dear jump forever" --mnemonic-type="counterwalletseed" --to-file="counterwallet1.pypayd"

but when I open the same seed in https://testnet.counterwallet.io/ - I do not see addresses generated by pypayd (and later paid) and the balance is 0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.