Register a token with the raiden token manager.

        Args:
            registry_address: registry address
            token_address_hex (string): a hex encoded token address.

        Returns:

            The token network proxy.
764790
def register_token(
            self,
            registry_address_hex: typing.AddressHex,
            token_address_hex: typing.AddressHex,
            retry_timeout: typing.NetworkTimeout = DEFAULT_RETRY_TIMEOUT,
    ) -> TokenNetwork:
        
        registry_address = decode_hex(registry_address_hex)
        token_address = decode_hex(token_address_hex)

        registry = self._raiden.chain.token_network_registry(registry_address)
        contracts_version = self._raiden.contract_manager.contracts_version

        if contracts_version == DEVELOPMENT_CONTRACT_VERSION:
            token_network_address = registry.add_token_with_limits(
                token_address=token_address,
                channel_participant_deposit_limit=UINT256_MAX,
                token_network_deposit_limit=UINT256_MAX,
            )
        else:
            token_network_address = registry.add_token_without_limits(
                token_address=token_address,
            )

        # Register the channel manager with the raiden registry
        waiting.wait_for_payment_network(
            self._raiden,
            registry.address,
            token_address,
            retry_timeout,
        )

        return self._raiden.chain.token_network(token_network_address)
22359
def token_address(self) -> Address:
        
        return to_canonical_address(self.proxy.contract.functions.token().call())
89036
def add_token(self, token_identifier, delegation_token):
    
    self.send_add_token(token_identifier, delegation_token)
    return self.recv_add_token()
281292
def proxy_register(register_funtion):
    
    def wrapper(function):
        @functools.wraps(function)
        def register(excepted, filter_function=None):
            if inspect.isfunction(excepted):
                register_funtion(excepted.__name__, excepted)
            elif isinstance(excepted, str) and filter_function:
                if not inspect.isfunction(filter_function):
                    raise RegisterError('Registered must be a function.')
                filter_function.__name__ = excepted
                register_funtion(excepted, filter_function)
            elif isinstance(excepted, str):
                def register_wrapper(func):
                    if not inspect.isfunction(func):
                        raise RegisterError('Registered must be a function.')
                    func.__name__ = excepted
                    register_funtion(excepted, func)
                return register_wrapper
        return register
    return wrapper
444310
def set_register_context(self, data):
        
        logging.debug("GDB setting register context")
        reg_num_list = []
        reg_data_list = []
        for reg in self._register_list:
            if reg.bitsize == 64:
                regValue = conversion.hex16_to_u64be(data)
                data = data[16:]
            else:
                regValue = conversion.hex8_to_u32be(data)
                data = data[8:]
            reg_num_list.append(reg.reg_num)
            reg_data_list.append(regValue)
            logging.debug("GDB reg: %s = 0x%X", reg.name, regValue)
        self._context.write_core_registers_raw(reg_num_list, reg_data_list)
739723
function Registry(ctx, prefixLength) {
  this._ctx = ctx; // Context for all callbacks.
  this._mask = ~0 >>> (prefixLength | 0); // 16 bits by default.
  this._id = 0; // Unique integer ID for each call.
  this._n = 0; // Number of pending calls.
  this._cbs = {};
}
731574
def get_proxy(self, proxy_address):
        
        if not proxy_address:
            return None
        hostport = extract_proxy_hostport(proxy_address)
        return self.proxies_by_hostport.get(hostport, None)
391796
def rpc_get_account_tokens(self, address, **con_info):
        
        if not check_account_address(address):
            return {'error': 'Invalid address', 'http_status': 400}

        # must be b58
        if is_c32_address(address):
            address = c32ToB58(address)

        db = get_db_state(self.working_dir)
        token_list = db.get_account_tokens(address)
        db.close()
        return self.success_response({'token_types': token_list})
729195
def btc_make_p2sh_address( script_hex ):
    
    h = hashing.bin_hash160(binascii.unhexlify(script_hex))
    addr = bin_hash160_to_address(h, version_byte=multisig_version_byte)
    return addr
1231988
def channel_open(
            self,
            registry_address: PaymentNetworkID,
            token_address: TokenAddress,
            partner_address: Address,
            settle_timeout: BlockTimeout = None,
            retry_timeout: NetworkTimeout = DEFAULT_RETRY_TIMEOUT,
    ) -> ChannelID:
        
        if settle_timeout is None:
            settle_timeout = self.raiden.config['settle_timeout']

        if settle_timeout < self.raiden.config['reveal_timeout'] * 2:
            raise InvalidSettleTimeout(
                'settle_timeout can not be smaller than double the reveal_timeout',
            )

        if not is_binary_address(registry_address):
            raise InvalidAddress('Expected binary address format for registry in channel open')

        if not is_binary_address(token_address):
            raise InvalidAddress('Expected binary address format for token in channel open')

        if not is_binary_address(partner_address):
            raise InvalidAddress('Expected binary address format for partner in channel open')

        chain_state = views.state_from_raiden(self.raiden)
        channel_state = views.get_channelstate_for(
            chain_state=chain_state,
            payment_network_id=registry_address,
            token_address=token_address,
            partner_address=partner_address,
        )

        if channel_state:
            raise DuplicatedChannelError('Channel with given partner address already exists')

        registry = self.raiden.chain.token_network_registry(registry_address)
        token_network_address = registry.get_token_network(token_address)

        if token_network_address is None:
            raise TokenNotRegistered(
                'Token network for token %s does not exist' % to_checksum_address(token_address),
            )

        token_network = self.raiden.chain.token_network(
            registry.get_token_network(token_address),
        )

        with self.raiden.gas_reserve_lock:
            has_enough_reserve, estimated_required_reserve = has_enough_gas_reserve(
                self.raiden,
                channels_to_open=1,
            )

            if not has_enough_reserve:
                raise InsufficientGasReserve((
                    'The account balance is below the estimated amount necessary to '
                    'finish the lifecycles of all active channels. A balance of at '
                    f'least {estimated_required_reserve} wei is required.'
                ))

            try:
                token_network.new_netting_channel(
                    partner=partner_address,
                    settle_timeout=settle_timeout,
                    given_block_identifier=views.state_from_raiden(self.raiden).block_hash,
                )
            except DuplicatedChannelError:
                log.info('partner opened channel first')

        waiting.wait_for_newchannel(
            raiden=self.raiden,
            payment_network_id=registry_address,
            token_address=token_address,
            partner_address=partner_address,
            retry_timeout=retry_timeout,
        )
        chain_state = views.state_from_raiden(self.raiden)
        channel_state = views.get_channelstate_for(
            chain_state=chain_state,
            payment_network_id=registry_address,
            token_address=token_address,
            partner_address=partner_address,
        )

        assert channel_state, f'channel {channel_state} is gone'

        return channel_state.identifier
586017
def push_tx(self, crypto, tx_hex):
        
        url = "%s/pushtx" % self.base_url
        return self.post_url(url, {'hex': tx_hex}).content
421269
def get_account_tokens(self, address):
        
        cur = self.db.cursor()
        return namedb_get_account_tokens(cur, address)
84620
def send(token_hex, message, **kwargs):
    
    is_enhanced = kwargs.pop('is_enhanced', False)
    identifier = kwargs.pop('identifier', 0)
    expiry = kwargs.pop('expiry', 0)

    alert = {
        "title": kwargs.pop("event"),
        "body": message,
        "action": kwargs.pop(
            'apns_action', defaults.APNS_PROVIDER_DEFAULT_ACTION)
    }

    data = {
        "aps": {
            'alert': alert,
            'content-available': kwargs.pop('content_available', 0) and 1
        }
    }
    data['aps'].update(kwargs)
    payload = dumps(data, separators=(',', ':'))

    token = a2b_hex(token_hex)
    if is_enhanced is True:
        fmt = '!BIIH32sH%ds' % len(payload)
        expiry = expiry and time() + expiry
        notification = pack(
            fmt, 1, identifier, expiry,
            32, token, len(payload), payload)
    else:
        token_length_bin = pack('>H', len(token))
        payload_length_bin = pack('>H', len(payload))
        zero_byte = bytes('\0', 'utf-8') if PY3 is True else '\0'
        payload = bytes(payload, 'utf-8') if PY3 is True else payload
        notification = (
            zero_byte + token_length_bin + token +
            payload_length_bin + payload)

    sock = socket(AF_INET, SOCK_STREAM)
    sock.settimeout(3)
    sock.connect((settings.APNS_GW_HOST, settings.APNS_GW_PORT))
    ssl = wrap_socket(
        sock, settings.APNS_KEY_FILE,
        settings.APNS_CERT_FILE,
        do_handshake_on_connect=False)

    result = ssl.write(notification)

    sock.close()
    ssl.close()

    if not result:
        raise APNsError

    return True
255758
def _join_partner(self, partner: Address):
        
        try:
            self.api.channel_open(
                self.registry_address,
                self.token_address,
                partner,
            )
        except DuplicatedChannelError:
            # If channel already exists (either because partner created it,
            # or it's nonfunded channel), continue to ensure it's funded
            pass

        total_deposit = self._initial_funding_per_partner
        if total_deposit == 0:
            return

        try:
            self.api.set_total_channel_deposit(
                registry_address=self.registry_address,
                token_address=self.token_address,
                partner_address=partner,
                total_deposit=total_deposit,
            )
        except InvalidDBData:
            raise
        except RECOVERABLE_ERRORS:
            log.info(
                'Deposit failed',
                node=pex(self.raiden.address),
                partner=pex(partner),
            )
        except RaidenUnrecoverableError:
            should_crash = (
                self.raiden.config['environment_type'] != Environment.PRODUCTION or
                self.raiden.config['unrecoverable_error_should_crash']
            )
            if should_crash:
                raise

            log.critical(
                'Deposit failed',
                node=pex(self.raiden.address),
                partner=pex(partner),
            )
593774
def register(host=DFLT_ADDRESS[0], port=DFLT_ADDRESS[1],
             signum=signal.SIGUSR1):
    
    _pdbhandler._register(host, port, signum)
797099
def btc_script_hex_to_address( script_hex, segwit=None ):
    
    # TODO: make this support more than bitcoin-like scripts
    if script_hex.startswith("76a914") and script_hex.endswith("88ac") and len(script_hex) == 50:
        # p2pkh script
        hash160_bin = binascii.unhexlify(script_hex[6:-4])
        return bin_hash160_to_address(hash160_bin, version_byte=version_byte)

    elif script_hex.startswith("a914") and script_hex.endswith("87") and len(script_hex) == 46:
        # p2sh script
        hash160_bin = binascii.unhexlify(script_hex[4:-2])
        return bin_hash160_to_address(hash160_bin, version_byte=multisig_version_byte)

    elif script_hex.startswith('0014') and len(script_hex) == 44:
        # p2wpkh script (bech32 address)
        hash160_bin = binascii.unhexlify(script_hex[4:])
        return segwit_addr_encode(hash160_bin) 

    elif script_hex.startswith('0020') and len(script_hex) == 68:
        # p2wsh script (bech32 address)
        sha256_bin = binascii.unhexlify(script_hex[4:])
        return segwit_addr_encode(sha256_bin)

    return None
755461
def read_reg(self, addr):
        
        # we don't call check_command here because read_reg() function is called
        # when detecting chip type, and the way we check for success (STATUS_BYTES_LENGTH) is different
        # for different chip types (!)
        val, data = self.command(self.ESP_READ_REG, struct.pack('<I', addr))
        if byte(data, 0) != 0:
            raise FatalError.WithResult("Failed to read register address %08x" % addr, data)
        return val