Skip to content

Commit

Permalink
Added marker classes for transactions (raiden-network#1950)
Browse files Browse the repository at this point in the history
  • Loading branch information
hackaugusto committed Jul 30, 2018
1 parent 2f1b0bc commit b7ddd46
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
8 changes: 8 additions & 0 deletions raiden/transfer/architecture.py
Expand Up @@ -86,6 +86,14 @@ def __init__(self, recipient, queue_name, message_identifier):
self.message_identifier = message_identifier


class ContractSendEvent(Event):
pass


class ContractReceiveStateChange(StateChange):
pass


class StateManager:
""" The mutable storage for the application state, this storage can do
state transitions by applying the StateChanges to the current State.
Expand Down
11 changes: 6 additions & 5 deletions raiden/transfer/events.py
@@ -1,5 +1,6 @@
from raiden.constants import UINT256_MAX
from raiden.transfer.architecture import (
ContractSendEvent,
Event,
SendMessageEvent,
)
Expand All @@ -8,7 +9,7 @@
# pylint: disable=too-many-arguments,too-few-public-methods


class ContractSendChannelClose(Event):
class ContractSendChannelClose(ContractSendEvent):
""" Event emitted to close the netting channel.
This event is used when a node needs to prepare the channel to unlock
on-chain.
Expand Down Expand Up @@ -43,7 +44,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractSendChannelSettle(Event):
class ContractSendChannelSettle(ContractSendEvent):
""" Event emitted if the netting channel must be settled. """

def __init__(
Expand Down Expand Up @@ -103,7 +104,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractSendChannelUpdateTransfer(Event):
class ContractSendChannelUpdateTransfer(ContractSendEvent):
""" Event emitted if the netting channel balance proof must be updated. """

def __init__(self, channel_identifier, token_network_identifier, balance_proof):
Expand Down Expand Up @@ -132,7 +133,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractSendChannelBatchUnlock(Event):
class ContractSendChannelBatchUnlock(ContractSendEvent):
""" Event emitted when the lock must be claimed on-chain. """

def __init__(self, token_network_identifier, channel_identifier, merkle_treee_leaves):
Expand All @@ -159,7 +160,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractSendSecretReveal(Event):
class ContractSendSecretReveal(ContractSendEvent):
""" Event emitted when the lock must be claimed on-chain. """

def __init__(self, secret: typing.Secret):
Expand Down
18 changes: 11 additions & 7 deletions raiden/transfer/state.py
Expand Up @@ -85,13 +85,14 @@ class ChainState(State):
"""

__slots__ = (
'queueids_to_queues',
'pseudo_random_generator',
'block_number',
'chain_id',
'identifiers_to_paymentnetworks',
'nodeaddresses_to_networkstates',
'payment_mapping',
'chain_id',
'pending_transactions',
'pseudo_random_generator',
'queueids_to_queues',
)

def __init__(
Expand All @@ -106,13 +107,14 @@ def __init__(
if not isinstance(chain_id, typing.T_ChainID):
raise ValueError('chain_id must be of ChainID type')

self.pseudo_random_generator = pseudo_random_generator
self.block_number = block_number
self.chain_id = chain_id
self.queueids_to_queues = dict()
self.identifiers_to_paymentnetworks = dict()
self.nodeaddresses_to_networkstates = dict()
self.payment_mapping = PaymentMappingState()
self.pending_transactions = list()
self.pseudo_random_generator = pseudo_random_generator
self.queueids_to_queues = dict()

def __repr__(self):
return '<ChainState block:{} networks:{} qty_transfers:{} chain_id:{}>'.format(
Expand Down Expand Up @@ -849,8 +851,10 @@ def __eq__(self, other):
self.contract_balance == other.contract_balance and
self.secrethashes_to_lockedlocks == other.secrethashes_to_lockedlocks and
self.secrethashes_to_unlockedlocks == other.secrethashes_to_unlockedlocks and
(self.secrethashes_to_onchain_unlockedlocks ==
other.secrethashes_to_onchain_unlockedlocks) and
(
self.secrethashes_to_onchain_unlockedlocks ==
other.secrethashes_to_onchain_unlockedlocks
) and
self.merkletree == other.merkletree and
self.balance_proof == other.balance_proof
)
Expand Down
33 changes: 18 additions & 15 deletions raiden/transfer/state_change.py
@@ -1,5 +1,8 @@
# pylint: disable=too-few-public-methods,too-many-arguments,too-many-instance-attributes
from raiden.transfer.architecture import StateChange
from raiden.transfer.architecture import (
ContractReceiveStateChange,
StateChange,
)
from raiden.transfer.state import (
BalanceProofSignedState,
NettingChannelState,
Expand Down Expand Up @@ -151,7 +154,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractReceiveChannelNew(StateChange):
class ContractReceiveChannelNew(ContractReceiveStateChange):
""" A new channel was created and this node IS a participant. """

def __init__(
Expand Down Expand Up @@ -179,7 +182,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractReceiveChannelClosed(StateChange):
class ContractReceiveChannelClosed(ContractReceiveStateChange):
""" A channel to which this node IS a participant was closed. """

def __init__(
Expand Down Expand Up @@ -294,7 +297,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractReceiveChannelNewBalance(StateChange):
class ContractReceiveChannelNewBalance(ContractReceiveStateChange):
""" A channel to which this node IS a participant had a deposit. """

def __init__(
Expand Down Expand Up @@ -328,7 +331,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractReceiveChannelSettled(StateChange):
class ContractReceiveChannelSettled(ContractReceiveStateChange):
""" A channel to which this node IS a participant was settled. """

def __init__(
Expand Down Expand Up @@ -410,7 +413,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractReceiveNewPaymentNetwork(StateChange):
class ContractReceiveNewPaymentNetwork(ContractReceiveStateChange):
""" Registers a new payment network.
A payment network corresponds to a registry smart contract.
"""
Expand All @@ -436,7 +439,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractReceiveNewTokenNetwork(StateChange):
class ContractReceiveNewTokenNetwork(ContractReceiveStateChange):
""" A new token was registered with the payment network. """

def __init__(
Expand Down Expand Up @@ -467,14 +470,14 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractReceiveSecretReveal(StateChange):
class ContractReceiveSecretReveal(ContractReceiveStateChange):
""" A new secret was registered with the SecretRegistry contract. """

def __init__(
self,
secret_registry_address: typing.SecretRegistryAddress,
secrethash: typing.SecretHash,
secret: typing.Secret,
self,
secret_registry_address: typing.SecretRegistryAddress,
secrethash: typing.SecretHash,
secret: typing.Secret,
):
if not isinstance(secret_registry_address, typing.T_SecretRegistryAddress):
raise ValueError('secret_registry_address must be of type SecretRegistryAddress')
Expand Down Expand Up @@ -506,7 +509,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractReceiveChannelBatchUnlock(StateChange):
class ContractReceiveChannelBatchUnlock(ContractReceiveStateChange):
""" All the locks were claimed via the blockchain.
Used when all the hash time locks were unlocked and a log ChannelUnlocked is emitted
Expand Down Expand Up @@ -572,7 +575,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractReceiveNewRoute(StateChange):
class ContractReceiveNewRoute(ContractReceiveStateChange):
""" New channel was created and this node is NOT a participant. """

def __init__(self, participant1: typing.Address, participant2: typing.Address):
Expand Down Expand Up @@ -602,7 +605,7 @@ def __ne__(self, other):
return not self.__eq__(other)


class ContractReceiveRouteNew(StateChange):
class ContractReceiveRouteNew(ContractReceiveStateChange):
""" New channel was created and this node is NOT a participant. """

def __init__(
Expand Down

0 comments on commit b7ddd46

Please sign in to comment.