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¶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: |
|
|---|
is_closed¶Returns – bool: True if channel is closed
| Return type: | bool |
|---|
unconfirmed_deposit¶Returns – int: sum of all deposits, including unconfirmed ones
Channel manager handles channel state changes on a low (blockchain) level.
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¶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_liquid_balance()[source]¶Get the balance of the receiver in the token contract (not locked in channels).
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) |
|---|
unconfirmed_channels¶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.
Off-chain state is saved in a sqlite database.
microraiden.channel_manager.state.ChannelManagerState(filename)[source]¶Bases: object
The part of the channel manager state that needs to persist.
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.
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 |
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
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.