Python API

Here you can find the API of some of the important classes and methods of the µRaiden server 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.

Channel manager handles channel state changes on a low (blockchain) level.

class microraiden.channel_manager.manager.ChannelManager(web3, channel_manager_contract, token_contract, private_key, state_filename=None, n_confirmations=1)[source]

Manages channels from the receiver’s point of view.

channels
channels_to_dict()[source]

Export all channels as a dictionary.

check_contract_version()[source]

Compare version of the contract to the version of the library. Only major and minor version is used in the comparison.

close_channel(sender, open_block_number)[source]

Close and settle a channel. Params:

sender (str): sender address open_block_number (int): block the channel was open in
close_pending_channels()[source]

Close all channels that are in CLOSE_PENDING state. This state happens if the receiver’s eth balance is not enough to

close channel on-chain.
event_channel_close_requested(sender, open_block_number, balance, settle_timeout)[source]

Notify the channel manager that a the closing of a channel has been requested. Params:

settle_timeout (int): settle timeout in blocks
event_channel_opened(sender, open_block_number, deposit)[source]

Notify the channel manager of a new confirmed channel opening.

event_channel_settled(sender, open_block_number)[source]

Notify the channel manager that a channel has been settled.

event_channel_topup(sender, open_block_number, txhash, added_deposit)[source]

Notify the channel manager that the deposit of a channel has been topped up.

force_close_channel(sender, open_block_number)[source]

Forcibly remove a channel from our channel state

get_eth_balance()[source]

Get eth balance of the receiver

get_liquid_balance()[source]

Get the balance of the receiver in the token contract (not locked in channels).

get_locked_balance()[source]

Get the balance in all channels combined.

get_token_address()[source]
node_online()[source]
pending_channels
register_payment(sender, open_block_number, balance, signature)[source]

Register a payment. Method will try to reconstruct (verify) balance update data with a signature sent by the client. If verification is succesfull, an internal payment state is updated. :type sender: str :param sender: sender of the balance proof :type sender: str :type open_block_number: int :param open_block_number: block the channel was opened in :type open_block_number: int :type balance: int :param balance: updated balance :type balance: int :type signature: str :param signature: balance proof to verify :type signature: str

reset_unconfirmed()[source]

Forget all unconfirmed channels and topups to allow for a clean resync.

set_head(unconfirmed_head_number, unconfirmed_head_hash, confirmed_head_number, confirmed_head_hash)[source]

Set the block number up to which all events have been registered.

sign_close(sender, open_block_number, balance)[source]

Sign an agreement for a channel closing. :returns: a signature that can be used client-side to close

the channel by directly calling contract’s close method on-chain.
Return type:channel close signature (str)
stop()[source]
unconfirmed_channels
unconfirmed_channels_to_dict()[source]

Export all unconfirmed channels as a dictionary.

unconfirmed_event_channel_opened(sender, open_block_number, deposit)[source]

Notify the channel manager of a new channel opening that has not been confirmed yet.

unconfirmed_event_channel_topup(sender, open_block_number, txhash, added_deposit)[source]

Notify the channel manager of a topup with not enough confirmations yet.

verify_balance_proof(sender, open_block_number, balance, signature)[source]

Verify that a balance proof is valid and return the sender.

This method just verifies if the balance proof is valid - no state update is performed.

Returns:Channel, if it exists
wait_sync()[source]
class microraiden.channel_manager.channel.Channel(receiver, sender, deposit, open_block_number)[source]
__init__(receiver, sender, deposit, open_block_number)[source]

A channel between two parties.

Parameters:
  • receiver (str) – receiver address
  • sender (str) – sender address
  • deposit (int) – channel deposit
  • open_block_number (int) – block the channel was created in
classmethod from_dict(state)[source]
is_closed

Returns – bool: True if channel is closed

Return type:bool
to_dict()[source]
Returns:Channel object serialized as a dict
Return type:dict
unconfirmed_deposit

Returns – int: sum of all deposits, including unconfirmed ones

class microraiden.channel_manager.channel.ChannelState[source]

An enumeration.

CLOSED = 1
CLOSE_PENDING = 2
OPEN = 0
UNDEFINED = 100
class microraiden.proxy.paywalled_proxy.PaywalledProxy(channel_manager, flask_app=None, paywall_html_dir=None, paywall_js_dir=None)[source]
add_paywalled_resource(cls, url, price=None, *args, **kwargs)[source]
static gevent_error_handler(context, exc_info)[source]
join()[source]

Block until server greenlet/Proxy stops

run(host='localhost', port=5000, debug=False, ssl_context=None)[source]

Start the proxy/WSGI server

stop()[source]