Python API

Here you can find the API of some of the important classes and methods of the µRaiden M2M-client framework. This documentation is auto-generated from the docstrings and type-hints in the source code, so if you have further questions please consult the source-code first.

class microraiden.client.client.Client(private_key=None, key_password_path=None, channel_manager_address=None, web3=None)[source]
__init__(private_key=None, key_password_path=None, channel_manager_address=None, web3=None)[source]
Parameters:
  • private_key (Optional[str]) –
  • key_password_path (Optional[str]) –
  • channel_manager_address (Optional[str]) –
  • web3 (Optional[Web3]) –
Return type:

None

get_open_channels(receiver=None)[source]

Returns all open channels to the given receiver. If no receiver is specified, all open channels are returned.

Return type:List[Channel]
get_suitable_channel(receiver, value, initial_deposit=<function Client.<lambda>>, topup_deposit=<function Client.<lambda>>)[source]

Searches stored channels for one that can sustain the given transfer value. If none is found, a possibly open channel is topped up using the topup callable to determine its topup value. If both attempts fail, a new channel is created based on the initial deposit callable. Note: In the realistic case that only one channel is opened per (sender,receiver) pair, this method usually performs like this: 1. Directly return open channel if sufficiently funded. 2. Topup existing open channel if insufficiently funded. 3. Create new channel if no open channel exists. If topping up or creating fails, this method returns None. Channels are topped up just enough so that their remaining capacity equals topup_deposit(value).

Return type:Channel
open_channel(receiver_address, deposit)[source]

Open a channel with a receiver and deposit

Attempts to open a new channel to the receiver with the given deposit. Blocks until the creation transaction is found in a pending block or timeout is reached.

Parameters:
  • receiver_address (str) – the partner with whom the channel should be opened
  • deposit (int) – the initial deposit for the channel (Should be > 0)
Return type:

Optional[Channel]

Returns:

The opened channel, if successful. Otherwise None

sync_channels()[source]

Merges locally available channel information, including their current balance signatures, with channel information available on the blockchain to make up for local data loss. Naturally, balance signatures cannot be recovered from the blockchain.

class microraiden.client.channel.Channel(core, sender, receiver, block, deposit=0, balance=0, state=<State.open: 1>, on_settle=<function Channel.<lambda>>)[source]
class State[source]

An enumeration.

closed = 3
open = 1
settling = 2
balance
balance_sig
close(balance=None)[source]

Attempts to request close on a channel. An explicit balance can be given to override the locally stored balance signature. Blocks until a confirmation event is received or timeout.

close_cooperatively(closing_sig)[source]

Attempts to close the channel immediately by providing a hash of the channel’s balance proof signed by the receiver. This signature must correspond to the balance proof stored in the passed channel state.

create_transfer(value)[source]

Updates the given channel’s balance and balance signature with the new value. The signature is returned and stored in the channel state.

is_suitable(value)[source]
is_valid()[source]
Return type:bool
key
Return type:bytes
settle()[source]

Attempts to settle a channel that has passed its settlement period. If a channel cannot be settled yet, the call is ignored with a warning. Blocks until a confirmation event is received or timeout.

sign()[source]
topup(deposit)[source]

Attempts to increase the deposit in an existing channel. Block until confirmation.

update_balance(value)[source]
class microraiden.client.session.Session(client=None, endpoint_url=None, retry_interval=5, initial_deposit=<function Session.<lambda>>, topup_deposit=<function Session.<lambda>>, close_channel_on_exit=False, **client_kwargs)[source]
close()[source]

Closes all adapters and as such the session

close_channel(endpoint_url=None)[source]
on_cooperative_close_denied(response=None)[source]
on_exit(method, url, response, **kwargs)[source]
on_http_error(method, url, response, **kwargs)[source]
Return type:bool
on_http_response(method, url, response, **kwargs)[source]

Called whenever server returns a reply. Return False to abort current request.

Return type:bool
on_init(method, url, **kwargs)[source]
on_insufficient_confirmations(method, url, response, **kwargs)[source]
Return type:bool
on_invalid_amount(method, url, response, **kwargs)[source]
Return type:bool
on_invalid_balance_proof(method, url, response, **kwargs)[source]
Return type:bool
on_invalid_contract_address(method, url, response, **kwargs)[source]
Return type:bool
on_nonexisting_channel(method, url, response, **kwargs)[source]
Return type:bool
on_payment_requested(method, url, response, **kwargs)[source]
Return type:bool
on_success(method, url, response, **kwargs)[source]
Return type:bool
request(method, url, **kwargs)[source]

Constructs a Request, prepares it and sends it. Returns Response object.

Parameters:
  • method (str) – method for the new Request object.
  • url (str) – URL for the new Request object.
  • params – (optional) Dictionary or bytes to be sent in the query string for the Request.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • json – (optional) json to send in the body of the Request.
  • headers – (optional) Dictionary of HTTP Headers to send with the Request.
  • cookies – (optional) Dict or CookieJar object to send with the Request.
  • files – (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.
  • auth – (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth.
  • timeout (float or tuple) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.
  • allow_redirects (bool) – (optional) Set to True by default.
  • proxies – (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy.
  • stream – (optional) whether to immediately download the response content. Defaults to False.
  • verify – (optional) Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to True.
  • cert – (optional) if String, path to ssl client cert file (.pem). If Tuple, (‘cert’, ‘key’) pair.
Return type:

requests.Response

class microraiden.client.context.Context(private_key, web3, channel_manager_address)[source]