Close a channel opened with `partner_address` for the given `token_address`. Race condition, this can fail if channel was closed externally.
(
self,
registry_address: TokenNetworkRegistryAddress,
token_address: TokenAddress,
partner_addresses: List[Address],
retry_timeout: NetworkTimeout = DEFAULT_RETRY_TIMEOUT,
coop_settle: bool = True,
)
| 846 | ) |
| 847 | |
| 848 | def channel_batch_close( |
| 849 | self, |
| 850 | registry_address: TokenNetworkRegistryAddress, |
| 851 | token_address: TokenAddress, |
| 852 | partner_addresses: List[Address], |
| 853 | retry_timeout: NetworkTimeout = DEFAULT_RETRY_TIMEOUT, |
| 854 | coop_settle: bool = True, |
| 855 | ) -> None: |
| 856 | """Close a channel opened with `partner_address` for the given |
| 857 | `token_address`. |
| 858 | |
| 859 | Race condition, this can fail if channel was closed externally. |
| 860 | """ |
| 861 | |
| 862 | if not is_binary_address(token_address): |
| 863 | raise InvalidBinaryAddress("Expected binary address format for token in channel close") |
| 864 | |
| 865 | if not all(map(is_binary_address, partner_addresses)): |
| 866 | raise InvalidBinaryAddress( |
| 867 | "Expected binary address format for partner in channel close" |
| 868 | ) |
| 869 | |
| 870 | valid_tokens = views.get_token_identifiers( |
| 871 | chain_state=views.state_from_raiden(self.raiden), |
| 872 | token_network_registry_address=registry_address, |
| 873 | ) |
| 874 | if token_address not in valid_tokens: |
| 875 | raise UnknownTokenAddress("Token address is not known.") |
| 876 | |
| 877 | chain_state = views.state_from_raiden(self.raiden) |
| 878 | channels_to_close = views.filter_channels_by_partneraddress( |
| 879 | chain_state=chain_state, |
| 880 | token_network_registry_address=registry_address, |
| 881 | token_address=token_address, |
| 882 | partner_addresses=partner_addresses, |
| 883 | ) |
| 884 | |
| 885 | if coop_settle: |
| 886 | non_settled_channels = self._batch_coop_settle(channels_to_close, retry_timeout) |
| 887 | if not non_settled_channels: |
| 888 | return |
| 889 | |
| 890 | close_state_changes: List[StateChange] = [ |
| 891 | ActionChannelClose(canonical_identifier=channel_state.canonical_identifier) |
| 892 | for channel_state in channels_to_close |
| 893 | ] |
| 894 | |
| 895 | greenlets = set(self.raiden.handle_state_changes(close_state_changes)) |
| 896 | gevent.joinall(greenlets, raise_error=True) |
| 897 | |
| 898 | channel_ids = [channel_state.identifier for channel_state in channels_to_close] |
| 899 | |
| 900 | waiting.wait_for_close( |
| 901 | raiden=self.raiden, |
| 902 | token_network_registry_address=registry_address, |
| 903 | token_address=token_address, |
| 904 | channel_ids=channel_ids, |
| 905 | retry_timeout=retry_timeout, |
no test coverage detected