MCPcopy
hub / github.com/raiden-network/raiden / open

Method open

raiden/api/rest.py:613–714  ·  view source on GitHub ↗
(
        self,
        registry_address: TokenNetworkRegistryAddress,
        partner_address: Address,
        token_address: TokenAddress,
        settle_timeout: BlockTimeout = None,
        reveal_timeout: BlockTimeout = None,
        total_deposit: TokenAmount = None,
    )

Source from the content-addressed store, hash-verified

611 )
612
613 def open(
614 self,
615 registry_address: TokenNetworkRegistryAddress,
616 partner_address: Address,
617 token_address: TokenAddress,
618 settle_timeout: BlockTimeout = None,
619 reveal_timeout: BlockTimeout = None,
620 total_deposit: TokenAmount = None,
621 ) -> Response:
622 log.debug(
623 "Opening channel",
624 node=self.checksum_address,
625 registry_address=to_checksum_address(registry_address),
626 partner_address=to_checksum_address(partner_address),
627 token_address=to_checksum_address(token_address),
628 settle_timeout=settle_timeout,
629 reveal_timeout=reveal_timeout,
630 )
631
632 confirmed_block_identifier = views.get_confirmed_blockhash(self.raiden_api.raiden)
633 try:
634 token = self.raiden_api.raiden.proxy_manager.token(
635 token_address, block_identifier=confirmed_block_identifier
636 )
637 except AddressWithoutCode as e:
638 return api_error(errors=str(e), status_code=HTTPStatus.CONFLICT)
639
640 balance = token.balance_of(self.raiden_api.raiden.address)
641
642 if total_deposit is not None and total_deposit > balance:
643 error_msg = "Not enough balance to deposit. {} Available={} Needed={}".format(
644 to_checksum_address(token_address), balance, total_deposit
645 )
646 return api_error(errors=error_msg, status_code=HTTPStatus.PAYMENT_REQUIRED)
647
648 try:
649 self.raiden_api.channel_open(
650 registry_address=registry_address,
651 token_address=token_address,
652 partner_address=partner_address,
653 settle_timeout=settle_timeout,
654 reveal_timeout=reveal_timeout,
655 )
656 status_code = HTTPStatus.CREATED
657 except DuplicatedChannelError:
658 # This is unlikely to happen in the wild, but it does happen in our
659 # tests.
660
661 channel_status = channel.get_status(
662 self.raiden_api.get_channel(registry_address, token_address, partner_address)
663 )
664
665 if not channel_status == ChannelState.STATE_OPENED:
666 return api_error(
667 errors="Channel is not in an open state.", status_code=HTTPStatus.CONFLICT
668 )
669
670 # The channel is open, just fall-through

Callers 7

mainFunction · 0.80
parse_requirements_devFunction · 0.80
parseMethod · 0.80
matrix_server_starterFunction · 0.80
putMethod · 0.80

Calls 11

to_checksum_addressFunction · 0.90
api_errorFunction · 0.90
api_responseFunction · 0.90
tokenMethod · 0.80
balance_ofMethod · 0.80
get_statusMethod · 0.80
channel_openMethod · 0.45
get_channelMethod · 0.45

Tested by

no test coverage detected