Newer
Older
"-value <value_datoshi> -unit <mb|kb|b|sec|day> -service <vpn>\n" );
dap_chain_node_cli_cmd_item_create ("tx_verify", com_tx_verify, NULL, "Verifing transaction",
"tx_verify -wallet <wallet name> \n" );
dap_chain_node_cli_cmd_item_create("tx_history", com_tx_history, NULL, "Transaction history (for address or by hash)",
"tx_history [-addr <addr> | -w <wallet name> | -tx <tx_hash>] -net <net name> -chain <chain name>\n");
// Ledger info
dap_chain_node_cli_cmd_item_create("ledger", com_ledger, NULL, "Ledger info",
"ledger list coins -net <network name>\n"
"ledger list coins_cond -net <network name>\n"
"ledger list addrs -net <network name>\n"
"ledger tx [all | -addr <addr> | -w <wallet name> | -tx <tx_hash>] [-chain <chain name>] -net <network name>\n");
// Token info
dap_chain_node_cli_cmd_item_create("token", com_token, NULL, "Token info",
"token list -net <network name>\n"
"token tx all name <token name> -net <network name> [-page_start <page>] [-page <page>]\n");
dap_chain_node_cli_cmd_item_create ("print_log", com_print_log, NULL, "Print log info",
"print_log [ts_after <timestamp >] [limit <line numbers>]\n" );
dap_chain_node_cli_cmd_item_create("stats", com_stats, NULL, "Print statistics",
// Export GDB to JSON
dap_chain_node_cli_cmd_item_create("gdb_export", com_gdb_export, NULL, "export", "export");
//Import GDB from JSON
dap_chain_node_cli_cmd_item_create("gdb_import", com_gdb_import, NULL, "import", "import");
dap_chain_node_cli_cmd_item_create ("exit", com_exit, NULL, "Stop application and exit",
l_listen_port = dap_config_get_item_uint16_default( g_config, "conserver", "listen_port_tcp",0);
const char * l_listen_unix_socket_path = dap_config_get_item_str( g_config, "conserver", "listen_unix_socket_path");
const char * l_listen_unix_socket_permissions_str = dap_config_get_item_str( g_config, "conserver", "listen_unix_socket_permissions");
mode_t l_listen_unix_socket_permissions = 0770;
if ( l_listen_unix_socket_path && l_listen_unix_socket_permissions ) {
if ( l_listen_unix_socket_permissions_str ) {
dap_sscanf(l_listen_unix_socket_permissions_str,"%ou", &l_listen_unix_socket_permissions );
log_it( L_INFO, "Console interace on path %s (%04o) ", l_listen_unix_socket_path, l_listen_unix_socket_permissions );
#ifndef _WIN32
if ( server_sockfd >= 0 ) {
dap_chain_node_cli_delete( );
server_sockfd = 0;
}
// create socket
sockfd = socket( AF_UNIX, SOCK_STREAM, 0 );
if( sockfd == INVALID_SOCKET )
return -1;
//int gdsg = sizeof(struct sockaddr_un);
if ( access( l_listen_unix_socket_path , R_OK) != -1 )
unlink( l_listen_unix_socket_path );
if( bind(sockfd, (const struct sockaddr*) &l_server_addr, sizeof(struct sockaddr_un)) == SOCKET_ERROR) {
// errno = EACCES 13 Permission denied
if ( errno == EACCES ) // EACCES=13
log_it( L_ERROR, "Server can't start(err=%d). Can't create file=%s [Permission denied]", errno,
l_listen_unix_socket_path );
log_it( L_ERROR, "Server can't start(err=%d). May be problem with file=%s?", errno, l_listen_unix_socket_path );
chmod(l_listen_unix_socket_path,l_listen_unix_socket_permissions);
if( pthread_create(&threadId, NULL, thread_pipe_func, (void*) (intptr_t) sockfd) != 0 ) {
closesocket( sockfd );
else if (l_listen_port ){
const char *l_listen_addr_str = dap_config_get_item_str(g_config, "conserver", "listen_address");
log_it( L_INFO, "Console interace on addr %s port %u ", l_listen_addr_str, l_listen_port );
#ifdef _WIN32
struct in_addr _in_addr = { { .S_addr = htonl(INADDR_LOOPBACK) } };
server_addr.sin_addr = _in_addr;
server_addr.sin_port = l_listen_port;
#else
inet_pton( AF_INET, l_listen_addr_str, &server_addr.sin_addr );
server_addr.sin_port = htons( (uint16_t)l_listen_port );
#endif
// create socket
if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET ) {
#ifdef __WIN32
_set_errno(WSAGetLastError());
#endif
log_it( L_ERROR, "Console Server: can't create socket, err %d", errno );
}
// connecting the address with a socket
if ( bind(sockfd, (struct sockaddr *) &server_addr, sizeof(server_addr)) == SOCKET_ERROR ) {
#ifdef __WIN32
_set_errno(WSAGetLastError());
#endif
log_it( L_ERROR, "Console Server: can't bind socket, err %d", errno );
}else {
log_it (L_INFO, "Not defined console interface");
return 0;
if( pthread_create(&l_thread_id, NULL, thread_main_func, (void*) (intptr_t) sockfd) != 0 ) {
// in order to thread not remain in state "dead" after completion
pthread_detach( l_thread_id );
server_sockfd = sockfd;
return 0;
}
/**
* Deinitialization of the server side
*
*/
void dap_chain_node_cli_delete(void)
{
if(server_sockfd >= 0)
closesocket(server_sockfd);