11import json
22from functools import partial
3+ from typing import TYPE_CHECKING
34
45from eth_utils import to_canonical_address
56from gevent .pool import Pool
67
78from raiden .constants import EMPTY_MERKLE_ROOT
89from raiden .exceptions import RaidenUnrecoverableError
910from raiden .network .proxies .utils import get_onchain_locksroots
10- from raiden .storage .sqlite import SQLiteStorage , StateChangeRecord
11+ from raiden .storage .sqlite import SnapshotRecord , SQLiteStorage , StateChangeRecord
1112from raiden .transfer .identifiers import CanonicalIdentifier
1213from raiden .utils .serialization import serialize_bytes
13- from raiden .utils .typing import Any , Dict , Locksroot , Tuple
14+ from raiden .utils .typing import (
15+ Any ,
16+ ChainID ,
17+ ChannelID ,
18+ Dict ,
19+ Locksroot ,
20+ TokenNetworkAddress ,
21+ Tuple ,
22+ )
23+
24+ if TYPE_CHECKING :
25+ # pylint: disable=unused-import
26+ from raiden .raiden_service import RaidenService # noqa: F401
1427
15- RaidenService = "RaidenService"
1628
1729SOURCE_VERSION = 19
1830TARGET_VERSION = 20
@@ -31,7 +43,7 @@ def _find_channel_new_state_change(
3143
3244
3345def _get_onchain_locksroots (
34- raiden : RaidenService ,
46+ raiden : " RaidenService" ,
3547 storage : SQLiteStorage ,
3648 token_network : Dict [str , Any ],
3749 channel : Dict [str , Any ],
@@ -49,9 +61,9 @@ def _get_onchain_locksroots(
4961 )
5062
5163 canonical_identifier = CanonicalIdentifier (
52- chain_identifier = - 1 ,
53- token_network_address = to_canonical_address (token_network ["address" ]),
54- channel_identifier = int (channel ["identifier" ]),
64+ chain_identifier = ChainID ( - 1 ) ,
65+ token_network_address = TokenNetworkAddress ( to_canonical_address (token_network ["address" ]) ),
66+ channel_identifier = ChannelID ( int (channel ["identifier" ]) ),
5567 )
5668
5769 our_locksroot , partner_locksroot = get_onchain_locksroots (
@@ -96,7 +108,7 @@ def _add_onchain_locksroot_to_channel_new_state_changes(storage: SQLiteStorage,)
96108
97109
98110def _add_onchain_locksroot_to_channel_settled_state_changes (
99- raiden : RaidenService , storage : SQLiteStorage
111+ raiden : " RaidenService" , storage : SQLiteStorage
100112) -> None :
101113 """ Adds `our_onchain_locksroot` and `partner_onchain_locksroot` to
102114 ContractReceiveChannelSettled. """
@@ -134,9 +146,11 @@ def _add_onchain_locksroot_to_channel_settled_state_changes(
134146 new_channel_state = channel_state_data ["channel_state" ]
135147
136148 canonical_identifier = CanonicalIdentifier (
137- chain_identifier = - 1 ,
138- token_network_address = to_canonical_address (token_network_identifier ),
139- channel_identifier = int (channel_identifier ),
149+ chain_identifier = ChainID (- 1 ),
150+ token_network_address = TokenNetworkAddress (
151+ to_canonical_address (token_network_identifier )
152+ ),
153+ channel_identifier = ChannelID (int (channel_identifier )),
140154 )
141155 our_locksroot , partner_locksroot = get_onchain_locksroots (
142156 chain = raiden .chain ,
@@ -156,8 +170,8 @@ def _add_onchain_locksroot_to_channel_settled_state_changes(
156170
157171
158172def _add_onchain_locksroot_to_snapshot (
159- raiden : RaidenService , storage : SQLiteStorage , snapshot_record : StateChangeRecord
160- ) -> str :
173+ raiden : " RaidenService" , storage : SQLiteStorage , snapshot_record : SnapshotRecord
174+ ) -> Tuple [ str , int ] :
161175 """
162176 Add `onchain_locksroot` to each NettingChannelEndState
163177 """
@@ -178,7 +192,7 @@ def _add_onchain_locksroot_to_snapshot(
178192 return json .dumps (snapshot , indent = 4 ), snapshot_record .identifier
179193
180194
181- def _add_onchain_locksroot_to_snapshots (raiden : RaidenService , storage : SQLiteStorage ) -> None :
195+ def _add_onchain_locksroot_to_snapshots (raiden : " RaidenService" , storage : SQLiteStorage ) -> None :
182196 snapshots = storage .get_snapshots ()
183197
184198 transform_func = partial (_add_onchain_locksroot_to_snapshot , raiden , storage )
0 commit comments