microraiden.channel_manager package

Submodules

microraiden.channel_manager.blockchain module

class microraiden.channel_manager.blockchain.Blockchain(web3, channel_manager_contract, channel_manager, n_confirmations, sync_chunk_size=100000)[source]

Bases: gevent.greenlet.Greenlet

Class that watches the blockchain and relays events to the channel manager.

insufficient_balance_recover()[source]

Recover from an insufficient balance state by closing all pending channels if possible.

poll_interval = 2
stop()[source]
wait_sync()[source]

Block until event polling is up-to-date with a most recent block of the blockchain

microraiden.channel_manager.channel module

class microraiden.channel_manager.channel.Channel(receiver, sender, deposit, open_block_number)[source]

Bases: object

__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]

Bases: enum.IntEnum

An enumeration.

CLOSED = 1
CLOSE_PENDING = 2
OPEN = 0
UNDEFINED = 100

microraiden.channel_manager.manager module

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]

Bases: gevent.greenlet.Greenlet

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]

microraiden.channel_manager.state module

Off-chain state is saved in a sqlite database.

class microraiden.channel_manager.state.ChannelManagerState(filename)[source]

Bases: object

The part of the channel manager state that needs to persist.

add_channel(channel)[source]

Add or update channel state

channel_exists(sender, open_block_number)[source]

Return true if channel(sender, open_block_number) exists

channels
confirmed_head_hash

The hash of the highest processed block considered to be final.

confirmed_head_number

The number of the highest processed block considered to be final.

contract_address

The address of the channel manager contract.

del_channel(sender, open_block_number)[source]
del_unconfirmed_channels()[source]
get_channel(sender, open_block_number)[source]
get_channel_rowid(sender, open_block_number)[source]
get_channels(confirmed=True)[source]
Parameters:confirmed (bool, optional) – return confirmed channels only. Default is True.
Returns:map of channels, (sender, open_block_number) => Channel
Return type:dict
get_unconfirmed_topups(channel_rowid)[source]
classmethod load(filename, check_permissions=True)[source]

Load a previously stored state.

n_channels

Returns – int: count of all channels, regardless of their state

n_open_channels

Returns – int: count of open channels

network_id

Network the state uses.

pending_channels

Get list of channels in a CLOSE_PENDING state

receiver

The receiver address.

result_to_channel(result)[source]

Helper function to serialize one row of channels table into a channel object

set_channel(channel)[source]

Update channel state

set_channel_state(sender, open_block_number, state)[source]
set_unconfirmed_topups(channel_rowid, topups)[source]
setup_db(network_id, contract_address, receiver)[source]

Initialize an empty database.

unconfirmed_channels
unconfirmed_head_hash

The hash of the highest processed block considered to be not yet final.

unconfirmed_head_number

The number of the highest processed block considered to be not yet final.

update_sync_state(confirmed_head_number=None, confirmed_head_hash=None, unconfirmed_head_number=None, unconfirmed_head_hash=None)[source]

Update block numbers and hashes of confirmed and unconfirmed head.

microraiden.channel_manager.state.dict_factory(cursor, row)[source]

make sqlite result a dict with keys being column names

Module contents