MCPcopy Create free account
hub / github.com/raiden-network/raiden / set_total_channel_withdraw

Method set_total_channel_withdraw

raiden/api/python.py:537–613  ·  view source on GitHub ↗

Set the `total_withdraw` in the channel with the peer at `partner_address` and the given `token_address`. Raises: InvalidBinaryAddress: If either token_address or partner_address is not 20 bytes long. RaidenUnrecoverableError: May happen for m

(
        self,
        registry_address: TokenNetworkRegistryAddress,
        token_address: TokenAddress,
        partner_address: Address,
        total_withdraw: WithdrawAmount,
        retry_timeout: NetworkTimeout = DEFAULT_RETRY_TIMEOUT,
    )

Source from the content-addressed store, hash-verified

535 return token_proxy.mint_for(value, to)
536
537 def set_total_channel_withdraw(
538 self,
539 registry_address: TokenNetworkRegistryAddress,
540 token_address: TokenAddress,
541 partner_address: Address,
542 total_withdraw: WithdrawAmount,
543 retry_timeout: NetworkTimeout = DEFAULT_RETRY_TIMEOUT,
544 ) -> None:
545 """Set the `total_withdraw` in the channel with the peer at `partner_address` and the
546 given `token_address`.
547
548 Raises:
549 InvalidBinaryAddress: If either token_address or partner_address is not
550 20 bytes long.
551 RaidenUnrecoverableError: May happen for multiple reasons:
552 - During preconditions checks, if the channel was not open
553 at the time of the approve_and_set_total_deposit call.
554 - If the transaction fails during gas estimation or
555 if a previous withdraw transaction with the same value
556 was already mined.
557 DepositMismatch: The total withdraw amount did not increase.
558 """
559 chain_state = views.state_from_raiden(self.raiden)
560
561 token_addresses = views.get_token_identifiers(chain_state, registry_address)
562 channel_state = views.get_channelstate_for(
563 chain_state=chain_state,
564 token_network_registry_address=registry_address,
565 token_address=token_address,
566 partner_address=partner_address,
567 )
568
569 if not is_binary_address(token_address):
570 raise InvalidBinaryAddress(
571 "Expected binary address format for token in channel deposit"
572 )
573
574 if not is_binary_address(partner_address):
575 raise InvalidBinaryAddress(
576 "Expected binary address format for partner in channel deposit"
577 )
578
579 if token_address not in token_addresses:
580 raise UnknownTokenAddress("Unknown token address")
581
582 if channel_state is None:
583 raise NonexistingChannel("No channel with partner_address for the given token")
584
585 if total_withdraw <= channel_state.our_total_withdraw:
586 raise WithdrawMismatch(f"Total withdraw {total_withdraw} did not increase")
587
588 current_balance = channel.get_balance(
589 sender=channel_state.our_state, receiver=channel_state.partner_state
590 )
591 amount_to_withdraw = total_withdraw - channel_state.our_total_withdraw
592 if amount_to_withdraw > current_balance:
593 raise InsufficientFunds(
594 "The withdraw of {} is bigger than the current balance of {}".format(

Calls 8

UnknownTokenAddressClass · 0.90
NonexistingChannelClass · 0.90
WithdrawMismatchClass · 0.90
InsufficientFundsClass · 0.90
get_balanceMethod · 0.45
withdrawMethod · 0.45