diff --git a/dap_chain_net.c b/dap_chain_net.c index f09b3f6dae1abab8df885a8d2b9eb8da284d3ddc..fc3daced3799f4747e880167e04d77abc286c0a7 100755 --- a/dap_chain_net.c +++ b/dap_chain_net.c @@ -142,6 +142,22 @@ dap_chain_net_t * dap_chain_net_new(const char * a_id, const char * a_name , PVT(ret)->node_role.enums = ROOT; log_it (L_NOTICE, "Node role \"root\" selected"); } + else if(strcmp(a_node_role, "master") == 0) { + PVT(ret)->node_role.enums = MASTER; + log_it(L_NOTICE, "Node role \"root\" selected"); + } + else if(strcmp(a_node_role, "archive") == 0) { + PVT(ret)->node_role.enums = ARCHIVE; + log_it(L_NOTICE, "Node role \"root\" selected"); + } + else if(strcmp(a_node_role, "full") == 0) { + PVT(ret)->node_role.enums = FULL; + log_it(L_NOTICE, "Node role \"root\" selected"); + } + else if(strcmp(a_node_role, "ligth") == 0) { + PVT(ret)->node_role.enums = LIGHT; + log_it(L_NOTICE, "Node role \"root\" selected"); + } } else { log_it (L_ERROR, "Wrong id format (\"%s\"). Must be like \"0x0123456789ABCDE\"" , a_id ); } @@ -186,13 +202,17 @@ int dap_chain_net_init() case ROOT: case ARCHIVE: l_utxo_flags |= DAP_CHAIN_UTXO_CHECK_TOKEN_EMISSION; + break; case MASTER: l_utxo_flags |= DAP_CHAIN_UTXO_CHECK_CELLS_DS; + break; case CELL_MASTER: l_utxo_flags |= DAP_CHAIN_UTXO_CHECK_TOKEN_EMISSION; + break; case FULL: case LIGHT: l_utxo_flags |= DAP_CHAIN_UTXO_CHECK_LOCAL_DS; + break; } dap_chain_utxo_init(l_utxo_flags); diff --git a/dap_chain_node_cli.c b/dap_chain_node_cli.c index 6b7f6ca16bdefe3bb7568210476bd67351414cd9..b911c2d092f56d30eec1853e6e045356bff4dc5c 100755 --- a/dap_chain_node_cli.c +++ b/dap_chain_node_cli.c @@ -413,6 +413,7 @@ void dap_chain_node_cli_cmd_item_create(const char * a_name, cmdfunc_t *a_func, snprintf(l_cmd_item->name,sizeof (l_cmd_item->name),"%s",a_name); l_cmd_item->doc = strdup( a_doc); l_cmd_item->doc_ex = strdup( a_doc_ex); + l_cmd_item->func = a_func; HASH_ADD_STR(s_commands,name,l_cmd_item); log_it(L_DEBUG,"Added command %s",l_cmd_item->name); } diff --git a/dap_chain_node_cli_cmd.c b/dap_chain_node_cli_cmd.c index 99cabc810091a848c1ea8cc03b144132ceed893e..8f1925bdd91c0fa748863efbd2c97ba8b03e2753 100755 --- a/dap_chain_node_cli_cmd.c +++ b/dap_chain_node_cli_cmd.c @@ -8,19 +8,19 @@ This file is part of DAP (Deus Applications Prototypes) the open source project - DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DAP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. -*/ + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. + */ #include <stdio.h> #include <stdlib.h> @@ -61,7 +61,6 @@ #define LOG_TAG "chain_node_cli_cmd" - /** * Convert string to digit */ @@ -212,7 +211,8 @@ static dap_chain_node_info_t* dap_chain_node_info_read(dap_chain_node_addr_t *ad } size_t node_info_size_must_be = dap_chain_node_info_get_size(node_info); if(node_info_size_must_be != node_info_size) { - dap_chain_node_cli_set_reply_text(str_reply, "node has bad size in base=%u (must be %u)", node_info_size, node_info_size_must_be); + dap_chain_node_cli_set_reply_text(str_reply, "node has bad size in base=%u (must be %u)", node_info_size, + node_info_size_must_be); DAP_DELETE(node_info); DAP_DELETE(l_key); return NULL; @@ -745,25 +745,32 @@ int com_global_db(int argc, const char ** argv, char **str_reply) int arg_index_n = ++arg_index; // find command (add, delete, etc) as second parameter only int cmd_num = CMD_NONE; - if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "add", NULL)) != 0) { + if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "add", NULL)) + != 0) { cmd_num = CMD_ADD; } - else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "del", NULL)) != 0) { + else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "del", NULL)) + != 0) { cmd_num = CMD_DEL; } - else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "link", NULL)) != 0) { + else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "link", NULL)) + != 0) { cmd_num = CMD_LINK; } - else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "dump", NULL)) != 0) { + else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "dump", NULL)) + != 0) { cmd_num = CMD_DUMP; } - else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "get", NULL)) != 0) { + else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "get", NULL)) + != 0) { cmd_num = CMD_GET; } - else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "set", NULL)) != 0) { + else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "set", NULL)) + != 0) { cmd_num = CMD_SET; } - else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "remote_set", NULL)) != 0) { + else if((arg_index_n = dap_chain_node_cli_find_option_val(argv, arg_index, min(argc, arg_index + 1), "remote_set", + NULL)) != 0) { cmd_num = CMD_REMOTE_SET; } if(cmd_num == CMD_NONE) { @@ -968,7 +975,7 @@ int com_node(int argc, const char ** argv, char **str_reply) uint8_t l_ch_id = dap_stream_ch_chain_net_get_id(); // Channel id for global_db sync res = dap_chain_node_client_send_chain_net_request(client, l_ch_id, - STREAM_CH_CHAIN_NET_PKT_TYPE_GLOBAL_DB_REQUEST_SYNC, l_data_send, l_data_send_len); //, NULL); + STREAM_CH_CHAIN_NET_PKT_TYPE_GLOBAL_DB_REQUEST_SYNC, l_data_send, l_data_send_len); //, NULL); DAP_DELETE(l_data_send); if(res != 1) { dap_chain_node_cli_set_reply_text(str_reply, "no request sent"); @@ -1074,7 +1081,8 @@ int com_traceroute(int argc, const char** argv, char **str_reply) iputils_set_verbose(); int res = (addr) ? traceroute_util(addr, &hops, &time_usec) : -EADDRNOTAVAIL; if(res >= 0) { - dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s hops=%d time=%.1lf ms", addr, hops, time_usec * 1. / 1000); + dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s hops=%d time=%.1lf ms", addr, hops, + time_usec * 1. / 1000); } else { if(str_reply) { @@ -1085,19 +1093,23 @@ int com_traceroute(int argc, const char** argv, char **str_reply) (addr) ? "Name or service not known" : "Host not defined"); break; case 2: - dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, "Unknown traceroute module"); + dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, + "Unknown traceroute module"); break; case 3: dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, "first hop out of range"); break; case 4: - dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, "max hops cannot be more than 255"); + dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, + "max hops cannot be more than 255"); break; case 5: - dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, "no more than 10 probes per hop"); + dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, + "no more than 10 probes per hop"); break; case 6: - dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, "bad wait specifications"); + dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, + "bad wait specifications"); break; case 7: dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, "too big packetlen "); @@ -1119,10 +1131,12 @@ int com_traceroute(int argc, const char** argv, char **str_reply) dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, "parse cmdline"); break; case 13: - dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, "trace method's init failed"); + dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error: %s", addr, + "trace method's init failed"); break; default: - dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error(%d) %s", addr, res, "trace not found"); + dap_chain_node_cli_set_reply_text(str_reply, "traceroute %s error(%d) %s", addr, res, + "trace not found"); } } } @@ -1144,7 +1158,8 @@ int com_tracepath(int argc, const char** argv, char **str_reply) int res = (addr) ? tracepath_util(addr, &hops, &time_usec) : -EADDRNOTAVAIL; if(res >= 0) { if(str_reply) - dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s hops=%d time=%.1lf ms", addr, hops, time_usec * 1. / 1000); + dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s hops=%d time=%.1lf ms", addr, hops, + time_usec * 1. / 1000); } else { if(str_reply) { @@ -1158,28 +1173,35 @@ int com_tracepath(int argc, const char** argv, char **str_reply) dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, "Can't create socket"); break; case 2: - dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, "Can't setsockopt IPV6_MTU_DISCOVER"); + dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, + "Can't setsockopt IPV6_MTU_DISCOVER"); break; case 3: - dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, "Can't setsockopt IPV6_RECVERR"); + dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, + "Can't setsockopt IPV6_RECVERR"); break; case 4: - dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, "Can't setsockopt IPV6_HOPLIMIT"); + dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, + "Can't setsockopt IPV6_HOPLIMIT"); break; case 5: - dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, "Can't setsockopt IP_MTU_DISCOVER"); + dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, + "Can't setsockopt IP_MTU_DISCOVER"); break; case 6: - dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, "Can't setsockopt IP_RECVERR"); + dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, + "Can't setsockopt IP_RECVERR"); break; case 7: - dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, "Can't setsockopt IP_RECVTTL"); + dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, + "Can't setsockopt IP_RECVTTL"); break; case 8: dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, "malloc"); break; case 9: - dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, "Can't setsockopt IPV6_UNICAST_HOPS"); + dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, + "Can't setsockopt IPV6_UNICAST_HOPS"); break; case 10: dap_chain_node_cli_set_reply_text(str_reply, "tracepath %s error: %s", addr, "Can't setsockopt IP_TTL"); @@ -1257,7 +1279,7 @@ int com_help(int argc, const char ** argv, char **str_reply) { if(argc > 1) { dap_chain_node_cmd_item_t *l_cmd = dap_chain_node_cli_cmd_find(argv[1]); - if(l_cmd){ + if(l_cmd) { dap_chain_node_cli_set_reply_text(str_reply, "%s:\n%s", l_cmd->doc, l_cmd->doc_ex); return 1; } @@ -1296,7 +1318,8 @@ int com_tx_wallet(int argc, const char ** argv, char **str_reply) } arg_index++; if(cmd_num == CMD_NONE) { - dap_chain_node_cli_set_reply_text(str_reply, "format of command: wallet [list | info -addr <addr> -w <wallet_name>]"); + dap_chain_node_cli_set_reply_text(str_reply, + "format of command: wallet [list | info -addr <addr> -w <wallet_name>]"); return -1; } @@ -1358,7 +1381,7 @@ int com_tx_wallet(int argc, const char ** argv, char **str_reply) size_t l_addr_tokens_size = 0; char **l_addr_tokens = NULL; dap_chain_utxo_addr_get_token_ticker_all(l_addr, &l_addr_tokens, &l_addr_tokens_size); - if(l_addr_tokens_size>0) + if(l_addr_tokens_size > 0) dap_string_append_printf(l_string_ret, "balance:\n"); else dap_string_append_printf(l_string_ret, "balance: 0\n"); @@ -1454,16 +1477,11 @@ int com_token_emit(int argc, const char ** argv, char ** str_reply) char * l_certs_str_dup = strdup(l_certs_str); char *l_cert_str = strtok_r(l_certs_str_dup, ",", &l_certs_tmp_ptrs); //debug - { - const char * l_wallets_path = dap_config_get_item_str(g_config, "general", "wallets_path"); - dap_chain_net_id_t a_net_id; - a_net_id.uint64 = 0x123; - dap_chain_sign_type_t l_type; - l_type.type = 0x0003;// SIG_TYPE_TESLA=0x0003 - dap_chain_wallet_t *wallet1 = dap_chain_wallet_create("tesla_first", l_wallets_path, a_net_id, l_type); - dap_chain_wallet_t *wallet2 = dap_chain_wallet_create("tesla_second", l_wallets_path, a_net_id, l_type); - wallet1 = NULL; - } +/* { + dap_chain_cert_t *l_cert1 = dap_chain_cert_generate("cert_b","/tmp/cert_b.dcert",DAP_ENC_KEY_TYPE_SIG_BLISS); + dap_chain_cert_t *l_cert2 = dap_chain_cert_generate("cert_p","/tmp/cert_p.dcert",DAP_ENC_KEY_TYPE_SIG_PICNIC); + dap_chain_cert_t *l_cert3 = dap_chain_cert_generate("cert_t","/tmp/cert_t.dcert",DAP_ENC_KEY_TYPE_SIG_TESLA); + }*/ // First we just calc items while(l_cert_str) { @@ -1532,7 +1550,7 @@ int com_token_emit(int argc, const char ** argv, char ** str_reply) , dap_config_get_item_str_default(g_config, "mempool", "gdb_group", "datum-pool"))) { str_reply_tmp = dap_strdup_printf("datum emission %s is placed in datum pool ", l_key_str); } - else{ + else { dap_chain_node_cli_set_reply_text(str_reply, "datum emission %s is not placed in datum pool ", l_key_str); return -1; } @@ -1553,8 +1571,13 @@ int com_token_emit(int argc, const char ** argv, char ** str_reply) dap_chain_datum_tx_add_item(&l_tx, (const uint8_t*) l_out); // Sign all that we have with certs - for(size_t i = 0; i < l_certs_size; i++) - dap_chain_datum_tx_add_sign_item(&l_tx, l_certs[i]->enc_key); + for(size_t i = 0; i < l_certs_size; i++) { + if(dap_chain_datum_tx_add_sign_item(&l_tx, l_certs[i]->enc_key) < 0) { + dap_chain_node_cli_set_reply_text(str_reply, "No private key for certificate=%s", + l_certs[i]->name); + return -3; + } + } DAP_DELETE(l_certs); DAP_DELETE(l_tx_token); @@ -1568,18 +1591,21 @@ int com_token_emit(int argc, const char ** argv, char ** str_reply) size_t l_datum_tx_size = dap_chain_datum_size(l_datum_tx); // use l_tx hash for compatible with utho hash - dap_hash_fast(l_tx, l_tx_size, &l_key_hash);//dap_hash_fast(l_datum_tx, l_datum_tx_size, &l_key_hash); + dap_hash_fast(l_tx, l_tx_size, &l_key_hash); //dap_hash_fast(l_datum_tx, l_datum_tx_size, &l_key_hash); l_key_str = dap_chain_hash_fast_to_str_new(&l_key_hash); DAP_DELETE(l_tx); + // Add to mempool emission token if(dap_chain_global_db_gr_set(l_key_str, (uint8_t *) l_datum_tx, l_datum_tx_size , dap_config_get_item_str_default(g_config, "mempool", "gdb_group", "datum-pool"))) { - dap_chain_node_cli_set_reply_text(str_reply, "%s\ndatum tx %s is placed in datum pool ", str_reply_tmp, l_key_str); - dap_chain_utxo_tx_add((dap_chain_datum_tx_t*)l_datum_tx->data); + dap_chain_node_cli_set_reply_text(str_reply, "%s\ndatum tx %s is placed in datum pool ", str_reply_tmp, + l_key_str); + dap_chain_utxo_tx_add((dap_chain_datum_tx_t*) l_datum_tx->data); } - else{ - dap_chain_node_cli_set_reply_text(str_reply, "%s\ndatum tx %s is not placed in datum pool ", str_reply_tmp, l_key_str); + else { + dap_chain_node_cli_set_reply_text(str_reply, "%s\ndatum tx %s is not placed in datum pool ", str_reply_tmp, + l_key_str); return -2; } DAP_DELETE(str_reply_tmp); @@ -1601,28 +1627,35 @@ int com_tx_cond_create(int argc, const char ** argv, char **str_reply) const char *c_wallet_name_from = "w_tesla"; // where to take coins for service const char *c_wallet_name_cond = "w_picnic"; // who will be use service, usually the same address (addr_from) uint64_t l_value = 50; + //debug + { + dap_chain_wallet_t * l_wallet_tesla = dap_chain_wallet_open("w_picnic", c_wallets_path); + const dap_chain_addr_t *l_addr_tesla = dap_chain_wallet_get_addr(l_wallet_tesla); + char *addr = dap_chain_addr_to_str(l_addr_tesla); + addr = 0; + } dap_chain_wallet_t *l_wallet_from = dap_chain_wallet_open(c_wallet_name_from, c_wallets_path); dap_enc_key_t *l_key = dap_chain_wallet_get_key(l_wallet_from, 0); dap_chain_wallet_t *l_wallet_cond = dap_chain_wallet_open(c_wallet_name_cond, c_wallets_path); - dap_enc_key_t *l_key_cond = dap_chain_wallet_get_key(l_wallet_from, 0); + dap_enc_key_t *l_key_cond = dap_chain_wallet_get_key(l_wallet_cond, 0); // where to take coins for service const dap_chain_addr_t *addr_from = dap_chain_wallet_get_addr(l_wallet_from); // who will be use service, usually the same address (addr_from) const dap_chain_addr_t *addr_cond = dap_chain_wallet_get_addr(l_wallet_cond); dap_chain_net_srv_abstract_t l_cond; - l_cond.price = l_value; + dap_chain_net_srv_abstract_set(&l_cond, SERV_CLASS_PERMANENT, SERV_ID_VPN, l_value, SERV_UNIT_MB, + "test vpn service"); int res = dap_chain_mempool_tx_create_cond(l_key, l_key_cond, addr_from, addr_cond, NULL, l_token_ticker, l_value, 0, (const void*) &l_cond, sizeof(dap_chain_net_srv_abstract_t)); dap_chain_wallet_close(l_wallet_from); dap_chain_wallet_close(l_wallet_cond); - dap_chain_node_cli_set_reply_text(str_reply, "tx_cond_create res=%d", res); - if(res == 1) - return 0; - return -1; + dap_chain_node_cli_set_reply_text(str_reply, "cond create=%s\n", + (res == 0) ? "Ok" : (res == -2) ? "False, not enough funds for service fee" : "False"); + return res; } /** @@ -1678,13 +1711,6 @@ int com_tx_create(int argc, const char ** argv, char **str_reply) dap_chain_node_cli_set_reply_text(str_reply, "wallet %s does not exist", l_from_wallet_name); return -1; } -/* //debug - { - dap_chain_wallet_t * l_wallet_tesla = dap_chain_wallet_open("w_tesla", c_wallets_path); - const dap_chain_addr_t *l_addr_tesla = dap_chain_wallet_get_addr(l_wallet_tesla); - char *addr = dap_chain_addr_to_str(l_addr_tesla); - addr = 0; - }*/ const dap_chain_addr_t *addr_from = (const dap_chain_addr_t *) dap_chain_wallet_get_addr(l_wallet); dap_chain_addr_t *addr_to = dap_chain_str_to_addr(addr_base58_to); dap_chain_addr_t *addr_fee = dap_chain_str_to_addr(addr_base58_fee); @@ -1708,7 +1734,8 @@ int com_tx_create(int argc, const char ** argv, char **str_reply) int res = dap_chain_mempool_tx_create(dap_chain_wallet_get_key(l_wallet, 0), addr_from, addr_to, addr_fee, l_token_ticker, value, value_fee); - dap_string_append_printf(string_ret, "transfer=%s\n", (res == 0) ? "Ok" : (res==-2)? "False, not enough funds for transfer" : "False"); + dap_string_append_printf(string_ret, "transfer=%s\n", + (res == 0) ? "Ok" : (res == -2) ? "False, not enough funds for transfer" : "False"); char *str_ret_tmp = dap_string_free(string_ret, false); char *str_ret = strdup(str_ret_tmp);