bitcoincash.electrum

Everything dealing with an Electrum RPC server is found in the core subpackage.

electrum

class bitcoincash.electrum.Electrum(loop=None)[source]

Bases: bitcoincash.electrum.client.StratumClient

Setup state needed to handle req/resp from a single Stratum server. Requires a transport (TransportABC) object to do the communication.

client

class bitcoincash.electrum.client.StratumClient(loop=None)[source]

Bases: object

Setup state needed to handle req/resp from a single Stratum server. Requires a transport (TransportABC) object to do the communication.

RPC(method, *params)[source]

Perform a remote command.

Expects a method name, which look like:

blockchain.address.get_balance

Returns a future which will you should await for the result from the server. Failures are returned as exceptions.

close()[source]
connect(server_info=None, proto_code=None, *, use_tor=False, disable_cert_verify=False, proxy=None, short_term=False)[source]

Start connection process. Destination must be specified in a ServerInfo() record (first arg).

subscribe(method, *params)[source]

Perform a remote command which will stream events/data to us.

Expects a method name, which look like:
server.peers.subscribe

Returns a tuple: (Future, asyncio.Queue). The future will have the result of the initial call, and the queue will receive additional responses as they happen.

constants

bitcoincash.electrum.constants.DEFAULT_SERVER = 'bitcoincash.network'

If server info is not provided, default to this server.

bitcoincash.electrum.constants.PROTOCOL_CODES = {'g': 'Websocket', 'h': 'HTTP (plaintext)', 's': 'SSL', 't': 'TCP (plaintext)'}

Which protocol is used. Usually paired with port number.

exc

exception bitcoincash.electrum.exc.ElectrumErrorResponse[source]

Bases: RuntimeError

protocol

class bitcoincash.electrum.protocol.StratumProtocol[source]

Bases: asyncio.protocols.Protocol

buf = b''
client = None
close()[source]
closed = False
connection_lost(exc)[source]

Called when the connection is lost or closed.

The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed).

connection_made(transport)[source]

Called when a connection is made.

The argument is the transport representing the pipe connection. To receive data, wait for data_received() calls. When the connection is closed, connection_lost() is called.

data_received(data)[source]

Called when some data is received.

The argument is a bytes object.

send_data(message)[source]

Given an object, encode as JSON and transmit to the server.

transport = None

svr_info

class bitcoincash.electrum.svr_info.KnownServers[source]

Bases: dict

Store a list of known servers and their port numbers, etc.

  • can add single entries
  • can read from a CSV for seeding/bootstrap
  • can read from IRC channel to find current hosts

We are a dictionary, with key being the hostname (in lowercase) of the server.

add_peer_response(response_list)[source]
add_single(hostname, ports, nickname=None, **kws)[source]

Explicitly add a single entry. Hostname is a FQDN and ports is either a single int (assumed to be TCP port) or Electrum protocol/port number specification with spaces in between.

dump()[source]
from_json(fname)[source]

Read contents of a CSV containing a list of servers.

save_json(fname='servers.json')[source]

Write out to a CSV file.

select(**kws)[source]

Find all servers with indicated protocol support. Shuffled.

Filter by TOR support, and pruning level.

class bitcoincash.electrum.svr_info.ServerInfo(nickname_or_dict, hostname=None, ports=None, version=None, pruning_limit=None, ip_addr=None)[source]

Bases: dict

Information to be stored on a server. Originally based on IRC data published to a channel.

FIELDS = ['nickname', 'hostname', 'ports', 'version', 'pruning_limit']
classmethod from_default()[source]
classmethod from_dict(d)[source]
classmethod from_response(response_list)[source]
get_port(for_protocol)[source]

Return (hostname, port number, ssl) pair for the protocol. Assuming only one port per host.

hostname
is_onion
protocols
pruning_limit
select(protocol='s', is_onion=None, min_prune=0)[source]