Skip to content

Commit

Permalink
Cleanup and more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
doc-hex committed Jun 20, 2016
1 parent 294255b commit b091cc2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
__pycache__
ENV
pp
dist
build
connectrum.egg-info
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
# Connectrum
Connectrum
----------

## Stratum (electrum-server) Client Protocol library
Stratum (electrum-server) Client Protocol library
=================================================

Uses python3 to be a client to the Electrum server network. It makes heavy use of
`asyncio` module and newer Python 3.5 keywords such as `await` and `async`.

This is meant to be a mostly-clean room implementation, but it isn't.

For non-server applications, you can probably find all you need
already in the standard Electrum code and command line.

## Features
Python 3.5 is absolutely required for this code. It will never work
on earlier versions of Python.


- connect via Tor
Features
========

- can connect via Tor, SSL, proxied or directly
- filter lists of peers by protocol, `.onion` name
- manage lists of Electrum servers in simple JSON files.
- fully asynchronous design, so can connect to multiple at once
- a number of nearly-useful examples provided

## Setup
Examples
========

In `examples` you will find a number little example programs.

virtualenv -p python3 ENV
(activate ENV)
pip install -r requirements.txt
cd examples
python3 explore.py
- `cli.py` send single commands, plan is to make this an interactive REPL
- `subscribe.py` stream changes/events for an address or blocks.
- `explorer.py` implements a simplistic block explorer website
- `spider.py` find all Electrum servers recursively, read/write results to JSON


## TODO List
TODO List
=========

- be more robust about failed servers, reconnect and handle it.
- connect to a few (3?) servers and compare top block and response times; pick best
- some sort of persistant server list that can be updated as we run
- type checking of parameters sent to server (maybe)?
- lots of test code
- an example that finds servers that do SSL with self-signed certificate
- an example that fingerprints servers to learn what codebase they use
- some bitcoin-specific code that all clients would need; like block header to hash
8 changes: 6 additions & 2 deletions examples/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#! /usr/bin/env python3
#
# Provide and interactive command line for sending commands to an Electrum server.
# Provide an interactive command line for sending
# commands to an Electrum server.
#
# TODO: finish this with interactive readline
#
import sys, asyncio, argparse, json
from connectrum.client import StratumClient
Expand All @@ -27,6 +30,8 @@ async def interact(conn, svr, connector, method, args, verbose=False):
motd = await conn.RPC('server.banner')
print("\n---\n%s\n---" % motd)

# XXX TODO do a simple REPL here

if method:
print("\nMethod: %s" % method)

Expand All @@ -40,7 +45,6 @@ async def interact(conn, svr, connector, method, args, verbose=False):
print(e)

conn.close()



def main():
Expand Down
7 changes: 5 additions & 2 deletions examples/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ def main():
help='Port number to override default for protocol')
parser.add_argument('--tor', default=False, action="store_true",
help='Use local Tor proxy to connect')
parser.add_argument('--debug', default=False, action="store_true",
help='Enable debug output from connectrum library')

args = parser.parse_args()

import logging
logging.getLogger('connectrum').setLevel(logging.DEBUG)
if args.debug:
import logging
logging.getLogger('connectrum').setLevel(logging.DEBUG)

# convert to our datastruct about servers.
svr = ServerInfo(args.server, args.server,
Expand Down

0 comments on commit b091cc2

Please sign in to comment.