__init__.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (c) 2010 Witchspace <witchspace81@gmail.com>
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights
  6. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. # copies of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. #
  10. # The above copyright notice and this permission notice shall be included in
  11. # all copies or substantial portions of the Software.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. # THE SOFTWARE.
  20. """
  21. bitcoin-python - Easy-to-use Bitcoin API client
  22. """
  23. def connect_to_local(filename=None):
  24. """
  25. Connect to default bitcoin instance owned by this user, on this machine.
  26. Returns a :class:`~mmgen.rpc.connection.BitcoinConnection` object.
  27. Arguments:
  28. - `filename`: Path to a configuration file in a non-standard location (optional)
  29. """
  30. from mmgen.rpc.connection import BitcoinConnection
  31. from mmgen.rpc.config import read_default_config
  32. cfg = read_default_config(filename)
  33. port = int(cfg.get('rpcport', '18332' if cfg.get('testnet') else '8332'))
  34. rcpuser = cfg.get('rpcuser', '')
  35. return BitcoinConnection(rcpuser, cfg['rpcpassword'], 'localhost', port)
  36. def connect_to_remote(user,password,host='localhost',port=8332,use_https=False):
  37. """
  38. Connect to remote or alternative local bitcoin client instance.
  39. Returns a :class:`~mmgen.rpc.connection.BitcoinConnection` object.
  40. """
  41. from mmgen.rpc.connection import BitcoinConnection
  42. return BitcoinConnection(user, password, host, port, use_https)