Skip to content

Commit

Permalink
Add type hints to EventNewBalanceProofReceived
Browse files Browse the repository at this point in the history
  • Loading branch information
konradkonrad committed Feb 13, 2019
1 parent 965c573 commit 7dd2691
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 9 additions & 4 deletions raiden/transfer/mediated_transfer/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from raiden.transfer.architecture import Event, SendMessageEvent
from raiden.transfer.mediated_transfer.state import LockedTransferUnsignedState
from raiden.transfer.state import BalanceProofUnsignedState
from raiden.transfer.state import BalanceProofSignedState, BalanceProofUnsignedState
from raiden.utils import pex, serialization, sha3
from raiden.utils.typing import (
Address,
Expand All @@ -15,8 +15,10 @@
PaymentID,
Secret,
SecretHash,
T_EventNewBalanceProofReceived,
TokenAddress,
TokenAmount,
Type,
)

# According to the smart contracts as of 07/08:
Expand Down Expand Up @@ -565,16 +567,19 @@ def from_dict(cls, data: Dict[str, Any]) -> 'EventUnlockFailed':
class EventNewBalanceProofReceived(Event):
""" Event for newly received balance proofs. Useful for notifying monitoring services. """

def __init__(self, balance_proof):
def __init__(self, balance_proof: BalanceProofSignedState) -> None:
self.balance_proof = balance_proof

def to_dict(self):
def to_dict(self) -> Dict:
return {
'balance_proof': self.balance_proof.to_dict(),
}

@classmethod
def from_dict(cls, data):
def from_dict(
cls: Type[T_EventNewBalanceProofReceived],
data: Dict,
) -> T_EventNewBalanceProofReceived:
return cls(data['balance_proof'])


Expand Down
6 changes: 6 additions & 0 deletions raiden/utils/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@
bound='raiden.messages.RequestMonitoring',
)


T_EventNewBalanceProofReceived = TypeVar(
'T_EventNewBalanceProofReceived',
bound='raiden.transfer.mediated_transfer.events.EventNewBalanceProofReceived',
)

T_TransactionHash = bytes
TransactionHash = NewType('TransactionHash', T_TransactionHash)

Expand Down

0 comments on commit 7dd2691

Please sign in to comment.