Ejemplo n.º 1
0
def register_node(name, p2p_ip, public_ip, port, domain_name):

    if not is_node_inited():
        print(TEXTS['node']['not_inited'])
        return

    # todo: add name, ips and port checks
    json_data = {
        'name': name,
        'ip': p2p_ip,
        'publicIP': public_ip,
        'port': port,
        'domain_name': domain_name
    }
    status, payload = post_request(blueprint=BLUEPRINT_NAME,
                                   method='register',
                                   json=json_data)
    if status == 'ok':
        msg = TEXTS['node']['registered']
        logger.info(msg)
        print(msg)
    else:
        error_msg = payload
        logger.error(f'Registration error {error_msg}')
        error_exit(error_msg, exit_code=CLIExitCodes.BAD_API_RESPONSE)
Ejemplo n.º 2
0
def toggle_schain_repair_mode(schain: str) -> None:
    status, payload = post_request(blueprint=BLUEPRINT_NAME,
                                   method='repair',
                                   json={'schain_name': schain})
    if status == 'ok':
        print('Schain has been set for repair')
    else:
        error_exit(payload, exit_code=CLIExitCodes.BAD_API_RESPONSE)
Ejemplo n.º 3
0
def send_eth(address: str, amount: float):
    json_data = {'address': address, 'amount': amount}
    status, payload = post_request(BLUEPRINT_NAME, 'send-eth', json=json_data)
    if status == 'ok':
        msg = TEXTS['wallet']['successful_transfer']
        logger.info(msg)
        print(msg)
    else:
        logger.error(f'Sending error {payload}')
        error_exit(payload, exit_code=CLIExitCodes.BAD_API_RESPONSE)
Ejemplo n.º 4
0
def start():
    status, payload = post_request(
        blueprint=BLUEPRINT_NAME,
        method='exit/start'
    )
    if status == 'ok':
        msg = TEXTS['exit']['start']
        logger.info(msg)
        print(msg)
    else:
        error_exit(payload, exit_code=CLIExitCodes.BAD_API_RESPONSE)
Ejemplo n.º 5
0
def set_domain_name(domain_name):
    print(f'Setting new domain name: {domain_name}')
    status, payload = post_request(blueprint=BLUEPRINT_NAME,
                                   method='set-domain-name',
                                   json={'domain_name': domain_name})
    if status == 'ok':
        msg = TEXTS['node']['domain_name_changed']
        logger.info(msg)
        print(msg)
    else:
        error_exit(payload, exit_code=CLIExitCodes.BAD_API_RESPONSE)
Ejemplo n.º 6
0
def set_maintenance_mode_off():
    print('Setting maintenance mode off...')
    status, payload = post_request(blueprint=BLUEPRINT_NAME,
                                   method='maintenance-off')
    if status == 'ok':
        msg = TEXTS['node']['maintenance_off']
        logger.info(msg)
        print(msg)
    else:
        error_msg = payload
        logger.error(f'Remove from maintenance mode error {error_msg}')
        error_exit(error_msg, exit_code=CLIExitCodes.BAD_API_RESPONSE)
Ejemplo n.º 7
0
def send_saving_cert_request(key_path, cert_path, force):
    with open(key_path, 'rb') as key_file, open(cert_path, 'rb') as cert_file:
        files_data = {
            'ssl_key': (os.path.basename(key_path), key_file,
                        'application/octet-stream'),
            'ssl_cert': (os.path.basename(cert_path), cert_file,
                         'application/octet-stream')
        }
        files_data['json'] = (
            None, json.dumps({'force': force}),
            'application/json'
        )
        return post_request(
            blueprint='ssl',
            method='upload',
            files=files_data
        )