Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/cellframe-sdk
  • MIKA83/cellframe-sdk
2 results
Show changes
Showing
with 588 additions and 2829 deletions
......@@ -85,6 +85,42 @@ DAP_STATIC_INLINE const char * dap_chain_datum_tx_item_type_to_str(dap_chain_tx_
}
}
typedef struct dap_chain_datum_tx_item_groups {
dap_list_t *items_in_all;
dap_list_t *items_in;
dap_list_t *items_in_cond;
dap_list_t *items_in_reward;
dap_list_t *items_sig;
dap_list_t *items_out;
dap_list_t *items_out_all;
dap_list_t *items_out_old;
dap_list_t *items_out_ext;
dap_list_t *items_out_cond;
dap_list_t *items_out_cond_srv_fee;
dap_list_t *items_out_cond_srv_pay;
dap_list_t *items_out_cond_srv_xchange;
dap_list_t *items_out_cond_srv_stake_pos_delegate;
dap_list_t *items_out_cond_srv_stake_lock;
dap_list_t *items_out_cond_unknonwn;
dap_list_t *items_out_cond_undefined;
dap_list_t *items_in_ems;
dap_list_t *items_vote;
dap_list_t *items_voting;
dap_list_t *items_tsd;
dap_list_t *items_pkey;
dap_list_t *items_receipt;
dap_list_t *items_unknown;
} dap_chain_datum_tx_item_groups_t;
bool dap_chain_datum_tx_group_items(dap_chain_datum_tx_t *a_tx, dap_chain_datum_tx_item_groups_t *a_res_group);
void dap_chain_datum_tx_group_items_free( dap_chain_datum_tx_item_groups_t *a_group);
/**
* Get item type by item name
*
......
......@@ -28,7 +28,6 @@
#include "dap_common.h"
#include "dap_time.h"
#include "dap_chain_common.h"
#include "dap_chain_datum_tx.h"
enum dap_chain_tx_out_cond_subtype {
DAP_CHAIN_TX_OUT_COND_SUBTYPE_UNDEFINED = 0x0,
......
......@@ -116,7 +116,7 @@ static int s_cli_block_poa(int argc, char ** argv, void **a_str_reply)
return -3;
}
const char *l_chain_type = dap_chain_net_get_type(l_chain);
const char *l_chain_type = dap_chain_get_cs_type(l_chain);
if (strcmp(l_chain_type, "block_poa")){
dap_cli_server_cmd_set_reply_text(a_str_reply,
"Type of chain %s is not block_poa. This chain with type %s is not supported by this command",
......@@ -211,9 +211,9 @@ static int s_callback_new(dap_chain_t * a_chain, dap_config_t * a_chain_cfg)
}
char l_cert_name[512];
for (size_t i = 0; i < l_poa_pvt->auth_certs_count ; i++ ){
snprintf(l_cert_name,sizeof(l_cert_name),"%s.%zu",l_poa_pvt->auth_certs_prefix, i);
snprintf(l_cert_name, sizeof(l_cert_name), "%s.%zu",l_poa_pvt->auth_certs_prefix, i);
if ((l_poa_pvt->auth_certs[i] = dap_cert_find_by_name( l_cert_name)) == NULL) {
snprintf(l_cert_name,sizeof(l_cert_name),"%s.%zu.pub",l_poa_pvt->auth_certs_prefix, i);
snprintf(l_cert_name, sizeof(l_cert_name), "%s.%zu.pub",l_poa_pvt->auth_certs_prefix, i);
if ((l_poa_pvt->auth_certs[i] = dap_cert_find_by_name( l_cert_name)) == NULL) {
log_it(L_ERROR, "Can't find cert \"%s\"", l_cert_name);
return -1;
......
......@@ -194,7 +194,7 @@ static int s_cli_dag_poa(int argc, char ** argv, void **a_str_reply)
return -3;
}
const char *l_chain_type = dap_chain_net_get_type(l_chain);
const char *l_chain_type = dap_chain_get_cs_type(l_chain);
if (strcmp(l_chain_type, "dag_poa")){
dap_cli_server_cmd_set_reply_text(a_str_reply,
......@@ -378,9 +378,9 @@ static int s_callback_new(dap_chain_t * a_chain, dap_config_t * a_chain_cfg)
}
char l_cert_name[512];
for (size_t i = 0; i < l_poa_pvt->auth_certs_count ; i++ ){
snprintf(l_cert_name,sizeof(l_cert_name),"%s.%zu",l_poa_pvt->auth_certs_prefix, i);
snprintf(l_cert_name, sizeof(l_cert_name), "%s.%zu",l_poa_pvt->auth_certs_prefix, i);
if ((l_poa_pvt->auth_certs[i] = dap_cert_find_by_name( l_cert_name)) == NULL) {
snprintf(l_cert_name,sizeof(l_cert_name),"%s.%zu.pub",l_poa_pvt->auth_certs_prefix, i);
snprintf(l_cert_name, sizeof(l_cert_name), "%s.%zu.pub",l_poa_pvt->auth_certs_prefix, i);
if ((l_poa_pvt->auth_certs[i] = dap_cert_find_by_name( l_cert_name)) == NULL) {
log_it(L_ERROR, "Can't find cert \"%s\"", l_cert_name);
return -1;
......
......@@ -27,7 +27,6 @@ along with any CellFrame SDK based project. If not, see <http://www.gnu.org/lic
#include "dap_chain.h"
#include "dap_chain_block.h"
#include "dap_chain_cs_blocks.h"
#include "dap_cert.h"
#include "dap_global_db_driver.h"
#define DAP_STREAM_CH_ESBOCS_ID 'E'
......@@ -156,6 +155,7 @@ typedef struct dap_chain_esbocs_round {
// Validators section
dap_list_t *validators_list;
uint16_t validators_synced_count;
uint16_t *excluded_list;
// Synchronization params
uint64_t sync_attempt;
bool sync_sent;
......@@ -223,16 +223,30 @@ typedef struct dap_chain_esbocs_block_collect{
#define DAP_CHAIN_ESBOCS(a) ((dap_chain_esbocs_t *)(a)->_inheritor)
typedef enum dap_chain_block_autocollect_type {
DAP_CHAIN_BLOCK_COLLECT_BOTH,
DAP_CHAIN_BLOCK_COLLECT_FEES,
DAP_CHAIN_BLOCK_COLLECT_REWARDS
} dap_chain_block_autocollect_type_t;
int dap_chain_cs_esbocs_init();
void dap_chain_cs_esbocs_deinit(void);
bool dap_chain_esbocs_started();
bool dap_chain_esbocs_started(dap_chain_net_id_t a_net_id);
void dap_chain_esbocs_stop_timer(dap_chain_net_id_t a_net_id);
void dap_chain_esbocs_start_timer(dap_chain_net_id_t a_net_id);
dap_pkey_t *dap_chain_esbocs_get_sign_pkey(dap_chain_net_id_t a_net_id);
uint256_t dap_chain_esbocs_get_fee(dap_chain_net_id_t a_net_id);
bool dap_chain_esbocs_get_autocollect_status(dap_chain_net_id_t a_net_id);
void dap_chain_esbocs_add_block_collect(dap_chain_block_t *a_block_ptr, size_t a_block_size,
dap_chain_esbocs_block_collect_t *a_block_collect_params,int a_type);
void dap_chain_esbocs_add_block_collect(dap_chain_block_cache_t *a_block_cache,
dap_chain_esbocs_block_collect_t *a_block_collect_params,
dap_chain_block_autocollect_type_t a_type);
bool dap_chain_esbocs_add_validator_to_clusters(dap_chain_net_id_t a_net_id, dap_stream_node_addr_t *a_validator_addr);
bool dap_chain_esbocs_remove_validator_from_clusters(dap_chain_net_id_t a_net_id, dap_stream_node_addr_t *a_validator_addr);
uint256_t dap_chain_esbocs_get_collecting_level(dap_chain_t *a_chain);
dap_enc_key_t *dap_chain_esbocs_get_sign_key(dap_chain_t *a_chain);
int dap_chain_esbocs_set_min_validators_count(dap_chain_t *a_chain, uint16_t a_new_value);
int dap_chain_esbocs_set_emergency_validator(dap_chain_t *a_chain, bool a_add, uint32_t a_sign_type, dap_hash_fast_t *a_validator_hash);
int dap_chain_esbocs_set_signs_struct_check(dap_chain_t *a_chain, bool a_enable);
add_subdirectory(mempool)
add_subdirectory(common)
cmake_minimum_required(VERSION 3.10)
project(dap_json_rpc_chain_common)
file(GLOB DAP_JSON_RPC_CHAIN_COMMON_HEADERS include/*.h)
file(GLOB DAP_JSON_RPC_CHAIN_COMMON_SRCS *.c)
add_library(${PROJECT_NAME} STATIC ${DAP_JSON_RPC_CHAIN_COMMON_SRCS} ${DAP_JSON_RPC_CHAIN_COMMON_HEADERS})
target_link_libraries(dap_json_rpc_chain_common dap_core dap_crypto dap_chain_common dap_json-c dap_json_rpc_core dap_json_rpc_crypto)
target_include_directories(dap_json_rpc_chain_common PUBLIC include/)
#include "dap_json_rpc_chain_common.h"
#include "json.h"
#define LOG_TAG "dap_json_rpc_chain_common"
/**
* @brief dap_chain_addr_to_json
* @param a_addr
* @return
*/
json_object *dap_chain_addr_to_json(const dap_chain_addr_t *a_addr) {
return json_object_new_string(dap_chain_addr_to_str(a_addr));
}
#include "dap_common.h"
#include "dap_time.h"
#include "dap_chain_datum.h"
#include "dap_chain_datum_tx.h"
#include "dap_chain_datum_token.h"
#include "dap_chain_datum_tx_items.h"
#include "dap_chain_datum_decree.h"
#include "dap_chain_datum_anchor.h"
#include "dap_chain_datum_hashtree_roots.h"
#include "dap_enc_base58.h"
#include "dap_json_rpc_chain_datum.h"
#include "dap_json_rpc_chain_datum_tx.h"
#include "dap_json_rpc_chain_datum_token.h"
#include "dap_json_rpc_chain_datum_anchor.h"
#include "dap_json_rpc_chain_datum_decree.h"
#include "json.h"
#define LOG_TAG "dap_json_rpc_chain_datum"
json_object *s_dap_chain_datum_token_tsd_to_json(dap_chain_datum_token_t *a_token, size_t a_token_size) {
dap_tsd_t *l_tsd = dap_chain_datum_token_tsd_get(a_token, a_token_size);
if (l_tsd == NULL) {
json_object *l_tsd_wgn = json_object_new_object();
if (!l_tsd_wgn){
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_tsd_wgn_warning = json_object_new_string("<CORRUPTED TSD SECTION>");
if (!l_tsd_wgn_warning) {
json_object_put(l_tsd_wgn);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_tsd_wgn, "warning", l_tsd_wgn_warning);
return l_tsd_wgn;
}
json_object *l_tsd_array = json_object_new_array();
if (!l_tsd_array) {
dap_json_rpc_allocation_error;
return NULL;
}
size_t l_tsd_total_size = 0;
switch (a_token->type) {
case DAP_CHAIN_DATUM_TOKEN_TYPE_DECL:
switch (a_token->subtype) {
case DAP_CHAIN_DATUM_TOKEN_SUBTYPE_PRIVATE:
l_tsd_total_size = a_token->header_private_decl.tsd_total_size; break;
case DAP_CHAIN_DATUM_TOKEN_SUBTYPE_NATIVE:
l_tsd_total_size = a_token->header_native_decl.tsd_total_size; break;
default: break;
} break;
case DAP_CHAIN_DATUM_TOKEN_TYPE_UPDATE:
switch (a_token->subtype) {
case DAP_CHAIN_DATUM_TOKEN_SUBTYPE_PRIVATE:
l_tsd_total_size = a_token->header_private_update.tsd_total_size; break;
case DAP_CHAIN_DATUM_TOKEN_SUBTYPE_NATIVE:
l_tsd_total_size = a_token->header_native_update.tsd_total_size; break;
default: break;
} break;
default: break;
}
size_t l_tsd_size = 0;
for (size_t l_offset = 0; l_offset < l_tsd_total_size; l_offset += l_tsd_size) {
json_object *l_jobj_tsd = json_object_new_object();
l_tsd = (dap_tsd_t *) (((byte_t*)l_tsd) + l_tsd_size);
l_tsd_size = l_tsd ? dap_tsd_size(l_tsd) : 0;
if (l_tsd_size == 0) {
json_object *l_wgn_text = json_object_new_string("Wrong zero TSD size, exiting s_datum_token_dump_tsd()");
if (!l_wgn_text) {
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_wgn = json_object_new_object();
if (!l_wgn) {
json_object_put(l_wgn_text);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_wgn, "error", l_wgn_text);
json_object_array_add(l_tsd_array, l_wgn);
break;
} else if (l_tsd_size+l_offset > l_tsd_total_size) {
char *l_wgn_str = dap_strdup_printf("<CORRUPTED TSD> too big size %u when left maximum %zu",
l_tsd->size, l_tsd_total_size - l_offset);
if (!l_wgn_str) {
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_wgn_text = json_object_new_string(l_wgn_str);
DAP_DELETE(l_wgn_str);
if (!l_wgn_text) {
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_wgn = json_object_new_object();
if (!l_wgn) {
json_object_put(l_wgn_text);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_wgn, "error", l_wgn_text);
json_object_array_add(l_tsd_array, l_wgn);
break;
}
switch( l_tsd->type){
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_SET_FLAGS: {
json_object *l_jobj_tsd = json_object_new_object();
if (!l_jobj_tsd) {
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_SET_FLAGS");
if (!l_jobj_tsd_type) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
uint16_t l_flags = 0;
_dap_tsd_get_scalar(l_tsd, &l_flags);
json_object *l_jobj_tsd_flag = dap_chain_datum_token_flags_to_json(l_flags);
if (!l_jobj_tsd_flag) {
json_object_put(l_jobj_tsd_type);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "flags", l_jobj_tsd_flag);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_UNSET_FLAGS: {
json_object *l_jobj_tsd = json_object_new_object();
if (!l_jobj_tsd) {
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_UNSET_FLAGS");
if (!l_jobj_tsd_type) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
uint16_t l_flags = 0;
_dap_tsd_get_scalar(l_tsd, &l_flags);
json_object *l_jobj_tsd_flag = dap_chain_datum_token_flags_to_json(l_flags);
if (!l_jobj_tsd_flag) {
json_object_put(l_jobj_tsd_type);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "flags", l_jobj_tsd_flag);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY: { // 256
json_object *l_jobj_tsd = json_object_new_object();
if (!l_jobj_tsd) {
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY");
if (!l_jobj_tsd_type) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
uint256_t l_balance_native = uint256_0;
_dap_tsd_get_scalar(l_tsd, &l_balance_native);
json_object *l_jobj_tsd_value = json_object_new_string(dap_uint256_to_char(l_balance_native, NULL));
if (!l_jobj_tsd_value) {
json_object_put(l_jobj_tsd);
json_object_put(l_jobj_tsd_type);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "value", l_jobj_tsd_value);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY_OLD: {// 128
json_object *l_jobj_tsd = json_object_new_object();
if (!l_jobj_tsd) {
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SUPPLY_OLD");
if (!l_jobj_tsd_type) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
uint128_t l_balance_native_old = uint128_0;
_dap_tsd_get_scalar(l_tsd, &l_balance_native_old);
json_object *l_jobj_tsd_value =
json_object_new_string(dap_uint256_to_char(GET_256_FROM_128(l_balance_native_old), NULL));
if (!l_jobj_tsd_value) {
json_object_put(l_jobj_tsd_type);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "value", l_jobj_tsd_value);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SIGNS_VALID: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_SIGNS_VALID");
uint16_t l_flags = 0;
_dap_tsd_get_scalar(l_tsd, &l_flags);
json_object *l_jobj_value = json_object_new_uint64(l_flags);
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "total_signs_valid", l_jobj_value);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_PKEYS_ADD: {
json_object *l_jobj_tsd = json_object_new_object();
if (!l_jobj_tsd) {
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_PKEYS_ADD");
if (!l_jobj_tsd_type) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
if (l_tsd->size >= sizeof(dap_pkey_t)) {
dap_pkey_t *l_pkey = (dap_pkey_t *) l_tsd->data;
dap_hash_fast_t l_hf = {0};
if (!dap_pkey_get_hash(l_pkey, &l_hf)) {
json_object *l_wgn_text = json_object_new_string("total_pkeys_add: <WRONG CALCULATION FINGERPRINT>");
if (!l_wgn_text) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_wgn_text);
} else {
json_object_object_add(l_jobj_tsd, "pkey",
json_object_new_string(dap_chain_hash_fast_to_str_static(&l_hf)));
}
} else {
char *l_wgn_text = dap_strdup_printf("total_pkeys_add: <WRONG SIZE %u>\n", l_tsd->size);
if (!l_wgn_text) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_wgn_text = json_object_new_string(l_wgn_text);
DAP_DELETE(l_wgn_text);
if (!l_jobj_wgn_text) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_jobj_wgn_text);
}
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_PKEYS_REMOVE: {
json_object *l_jobj_tsd = json_object_new_object();
if (!l_jobj_tsd){
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TOTAL_PKEYS_REMOVE");
if (!l_jobj_tsd_type) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
if (l_tsd->size == sizeof(dap_chain_hash_fast_t)) {
json_object_object_add(l_jobj_tsd, "pkey",
json_object_new_string(dap_chain_hash_fast_to_str_static((dap_chain_hash_fast_t*) l_tsd->data)));
} else {
char *l_wgn_text = dap_strdup_printf("total_pkeys_remove: <WRONG SIZE %u>\n", l_tsd->size);
if (!l_wgn_text) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_wgn_text = json_object_new_string(l_wgn_text);
DAP_DELETE(l_wgn_text);
if (!l_jobj_wgn_text) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_jobj_wgn_text);
}
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_DELEGATE_EMISSION_FROM_STAKE_LOCK: {
json_object *l_jobj_tsd = json_object_new_object();
if (!l_jobj_tsd) {
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_DELEGATE_EMISSION_FROM_STAKE_LOCK");
if (!l_jobj_tsd_type) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
dap_chain_datum_token_tsd_delegate_from_stake_lock_t *l_tsd_section = _dap_tsd_get_object(l_tsd, dap_chain_datum_token_tsd_delegate_from_stake_lock_t);
json_object *l_jobj_ticker_token_from = json_object_new_string((char*)l_tsd_section->ticker_token_from);
if (!l_jobj_ticker_token_from) {
json_object_put(l_jobj_ticker_token_from);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "ticker_token_from", l_jobj_ticker_token_from);
char *balance; dap_uint256_to_char(l_tsd_section->emission_rate, &balance);
json_object *l_jobj_emission_rate = json_object_new_string(balance);
if (!l_jobj_emission_rate) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "emission_rate", l_jobj_emission_rate);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_DATUM_TYPE_ALLOWED_ADD: {
json_object *l_jobj_tsd = json_object_new_object();
if (!l_jobj_tsd) {
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_DATUM_TYPE_ALLOWED_ADD");
if (!l_jobj_tsd_type) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object *l_jobj_datum_type_allowed_add = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_datum_type_allowed_add) {
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "datum_type_allowed_add", l_jobj_datum_type_allowed_add);
json_object_array_add(l_tsd_array, l_jobj_tsd);
}continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_DATUM_TYPE_ALLOWED_REMOVE: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_DATUM_TYPE_ALLOWED_REMOVE");
json_object *l_jobj_datum_type_allowed_remove = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_jobj_datum_type_allowed_remove) {
json_object_put(l_jobj_datum_type_allowed_remove);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "datum_type_allowed_remove", l_jobj_datum_type_allowed_remove);
json_object_array_add(l_tsd_array, l_jobj_tsd);
}continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_DATUM_TYPE_BLOCKED_ADD: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_DATUM_TYPE_BLOCKED_ADD");
json_object *l_jobj_datum_type_blocked_add = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_jobj_datum_type_blocked_add) {
json_object_put(l_jobj_datum_type_blocked_add);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "datum_type_blocked_add", l_jobj_datum_type_blocked_add);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_DATUM_TYPE_BLOCKED_REMOVE: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_DATUM_TYPE_BLOCKED_REMOVE");
json_object *l_jobj_datum_type_blocked_remove = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_jobj_datum_type_blocked_remove) {
json_object_put(l_jobj_datum_type_blocked_remove);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "datum_type_blocked_remove", l_jobj_datum_type_blocked_remove);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_SENDER_ALLOWED_ADD: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_SENDER_ALLOWED_ADD");
json_object *l_jobj_tx_sender_allowed_add = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_jobj_tx_sender_allowed_add) {
json_object_put(l_jobj_tx_sender_allowed_add);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "tx_sender_allowed_add",l_jobj_tx_sender_allowed_add);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_SENDER_ALLOWED_REMOVE: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_SENDER_ALLOWED_REMOVE");
json_object *l_jobj_tx_sender_allowed_remove = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_jobj_tx_sender_allowed_remove) {
json_object_put(l_jobj_tx_sender_allowed_remove);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "tx_sender_allowed_remove",l_jobj_tx_sender_allowed_remove);
json_object_array_add(l_tsd_array, l_jobj_tsd);
}continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_SENDER_BLOCKED_ADD: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_SENDER_BLOCKED_ADD");
json_object *l_jobj_tx_sender_blocked_add = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_jobj_tx_sender_blocked_add) {
json_object_put(l_jobj_tx_sender_blocked_add);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "tx_sender_blocked_add", l_jobj_tx_sender_blocked_add);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_SENDER_BLOCKED_REMOVE: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_SENDER_BLOCKED_REMOVE");
json_object *l_jobj_tx_sender_blocked_remove = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_jobj_tx_sender_blocked_remove) {
json_object_put(l_jobj_tx_sender_blocked_remove);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "tx_sender_blocked_remove", l_jobj_tx_sender_blocked_remove);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_RECEIVER_ALLOWED_ADD: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_RECEIVER_ALLOWED_ADD");
json_object *l_tx_receiver_allowed_add = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_tx_receiver_allowed_add) {
json_object_put(l_tx_receiver_allowed_add);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "tx_receiver_allowed_add", l_tx_receiver_allowed_add);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_RECEIVER_ALLOWED_REMOVE: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_RECEIVER_ALLOWED_REMOVE");
json_object *l_jobj_tx_receiver_allowed_remove = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_jobj_tx_receiver_allowed_remove){
json_object_put(l_jobj_tx_receiver_allowed_remove);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "tx_receiver_allowed_remove", l_jobj_tx_receiver_allowed_remove);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_RECEIVER_BLOCKED_ADD: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_RECEIVER_BLOCKED_ADD");
json_object *l_jobj_tx_receiver_blocked_add = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_jobj_tx_receiver_blocked_add){
json_object_put(l_jobj_tx_receiver_blocked_add);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "tx_receiver_blocked_add", l_jobj_tx_receiver_blocked_add);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_RECEIVER_BLOCKED_REMOVE: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TYPE_TX_RECEIVER_BLOCKED_REMOVE");
json_object *l_jobj_tx_receiver_blocked_remove = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_jobj_tx_receiver_blocked_remove) {
json_object_put(l_jobj_tx_receiver_blocked_remove);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "tx_receiver_blocked_remove", l_jobj_tx_receiver_blocked_remove);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
case DAP_CHAIN_DATUM_TOKEN_TSD_TOKEN_DESCRIPTION: {
json_object *l_jobj_tsd = json_object_new_object();
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TSD_TOKEN_DESCRIPTION");
json_object *l_jobj_tsd_description = json_object_new_string(dap_tsd_get_string_const(l_tsd));
if (!l_jobj_tsd || !l_jobj_tsd_type || !l_jobj_tsd_description) {
json_object_put(l_jobj_tsd_description);
json_object_put(l_jobj_tsd_type);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "description", l_jobj_tsd_description);
json_object_array_add(l_tsd_array, l_jobj_tsd);
} continue;
default: {
char *l_wgn_text = dap_strdup_printf("<0x%04hX>: <size %u>\n", l_tsd->type, l_tsd->size);
if (!l_wgn_text){
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_wgn_text = json_object_new_string(l_wgn_text);
DAP_DELETE(l_wgn_text);
json_object *l_jobj_warning = json_object_new_object();
if (!l_jobj_wgn_text || !l_jobj_warning) {
json_object_put(l_jobj_wgn_text);
json_object_put(l_jobj_warning);
json_object_put(l_jobj_tsd);
json_object_put(l_tsd_array);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_warning, "warning", l_jobj_wgn_text);
json_object_array_add(l_tsd_array, l_jobj_warning);
}
}
}
return l_tsd_array;
}
typedef enum dap_chain_datum_to_json_err_list {
CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_TX_TO_JSON = DAP_JSON_RPC_ERR_CODE_METHOD_ERR_START,
CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_DECL_TO_JSON,
CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_READ_DECL,
CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_TSD_SECTION_DECL_TO_JSON,
CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_EMISSION_TO_JSON,
CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_READ_EMISSION,
CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_ANCHOR_TO_JSON,
CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_DECREE_TO_JSON
}dap_chain_datum_to_json_err_list_t;
json_object * dap_chain_datum_to_json(dap_chain_datum_t* a_datum){
json_object *l_object = json_object_new_object();
if (!l_object){
dap_json_rpc_allocation_error;
return NULL;
}
char *l_hash_data_str;
dap_get_data_hash_str_static(a_datum->data, a_datum->header.data_size, l_hash_data_str);
json_object *l_obj_data_hash = json_object_new_string(l_hash_data_str);
if (!l_obj_data_hash) {
json_object_put(l_object);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_version = json_object_new_int(a_datum->header.version_id);
if (!l_obj_version) {
json_object_put(l_object);
json_object_put(l_obj_data_hash);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_size = json_object_new_int(a_datum->header.data_size);
if (!l_obj_size) {
json_object_put(l_object);
json_object_put(l_obj_data_hash);
json_object_put(l_obj_version);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_type = json_object_new_string(dap_chain_datum_type_id_to_str(a_datum->header.type_id));
if (!l_obj_type) {
json_object_put(l_object);
json_object_put(l_obj_data_hash);
json_object_put(l_obj_version);
json_object_put(l_obj_size);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_data = dap_chain_datum_data_to_json(a_datum);
json_object_object_add(l_object, "hash", l_obj_data_hash);
json_object_object_add(l_object, "data_size", l_obj_size);
json_object_object_add(l_object, "version", l_obj_version);
char l_time_str[DAP_TIME_STR_SIZE];
if (a_datum->header.ts_create) {
dap_time_to_str_rfc822(l_time_str, DAP_TIME_STR_SIZE, a_datum->header.ts_create); /* Convert ts to "Sat May 17 01:17:08 2014\n" */
l_time_str[strlen(l_time_str)-1] = '\0'; /* Remove "\n"*/
}
json_object *l_obj_ts_created = json_object_new_string(l_time_str);
json_object_object_add(l_object, "ts_create", l_obj_ts_created);
json_object_object_add(l_object, "type", l_obj_type);
if (a_datum->header.type_id == DAP_CHAIN_DATUM_TX) {
json_object_object_add(l_object, "items", l_obj_data);
} else {
json_object_object_add(l_object, "data", l_obj_data);
}
return l_object;
}
json_object * dap_chain_datum_data_to_json(dap_chain_datum_t *a_datum) {
if (!a_datum)
return json_object_new_null();
json_object *l_obj_data;
switch (a_datum->header.type_id) {
case DAP_CHAIN_DATUM_TX:
l_obj_data = dap_chain_datum_tx_to_json((dap_chain_datum_tx_t*)a_datum->data, NULL);
if (!l_obj_data) {
dap_json_rpc_error_add(CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_TX_TO_JSON,
"Can't convert DAP_CHAIN_DATUM_TX to JSON");
return NULL;
}
break;
case DAP_CHAIN_DATUM_DECREE:
l_obj_data = dap_chain_datum_decree_to_json((dap_chain_datum_decree_t*)a_datum->data);
if (!l_obj_data) {
dap_json_rpc_error_add(CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_DECREE_TO_JSON,
"Can't convert DAP_CHAIN_DATUM_DECREE to JSON");
return NULL;
}
break;
case DAP_CHAIN_DATUM_ANCHOR:
l_obj_data = dap_chain_datum_anchor_to_json((dap_chain_datum_anchor_t*)a_datum->data);
if (!l_obj_data) {
dap_json_rpc_error_add(CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_ANCHOR_TO_JSON,
"Can't convert DAP_CHAIN_DATUM_ANCHOR to JSON");
return NULL;
}
break;
case DAP_CHAIN_DATUM_TOKEN_DECL: {
size_t l_token_size = a_datum->header.data_size;
dap_chain_datum_token_t *l_token = dap_chain_datum_token_read(a_datum->data, &l_token_size);
if (!l_token) {
dap_json_rpc_error_add(CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_READ_DECL,
"The contents of the token delcaration could not be read.");
return NULL;
}
l_obj_data = dap_chain_datum_token_to_json(l_token, l_token_size);
if (!l_obj_data) {
dap_json_rpc_error_add(CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_DECL_TO_JSON,
"Can't convert DAP_CHAIN_DATUM_TOKEN_DECL to JSON");
DAP_DELETE(l_token);
return NULL;
}
json_object *l_obj_tsd_data = s_dap_chain_datum_token_tsd_to_json(l_token, l_token_size);
if (!l_obj_tsd_data) {
json_object_put(l_obj_data);
DAP_DELETE(l_token);
log_it(L_ERROR, "It was not possible to read the contents of the TSD sections of the token delcaration.");
dap_json_rpc_error_add(CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_TSD_SECTION_DECL_TO_JSON,
"It was not possible to read the contents of the TSD sections of the token delcaration.");
return NULL;
}
json_object_object_add(l_obj_data, "TSD", l_obj_tsd_data);
DAP_DELETE(l_token);
} break;
case DAP_CHAIN_DATUM_TOKEN_EMISSION: {
size_t l_emission_size = a_datum->header.data_size;
dap_chain_datum_token_emission_t *l_emission = dap_chain_datum_emission_read(a_datum->data, &l_emission_size);
if (l_emission_size == 0 || !l_emission) {
log_it(L_ERROR, "Failed to read emission");
dap_json_rpc_error_add(CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_READ_EMISSION,
"Failed to read emission.");
return NULL;
} else {
l_obj_data = dap_chain_datum_emission_to_json(l_emission, l_emission_size);
DAP_DELETE(l_emission);
if (!l_obj_data) {
dap_json_rpc_error_add(CHAIN_DATUM_TO_JSON_ERR_CAN_NOT_SERIALIZATION_EMISSION_TO_JSON,
"Can't convert DAP_CHAIN_DATUM_TOKEN_DECL to JSON");
return NULL;
}
}
} break;
default:
l_obj_data = json_object_new_null();
break;
}
return l_obj_data;
}
#include "dap_json_rpc_chain_datum_anchor.h"
#include "json.h"
#define LOG_TAG "dap_json_rpc_chain_datum_anchor"
json_object *s_dap_chain_datum_anchor_sign_to_json(byte_t * a_signs, size_t a_certs_size) {
json_object *l_jobs_signs = json_object_new_array();
size_t l_offset = 0;
for (int i = 1; l_offset < (a_certs_size); i++) {
json_object *l_jobj_sign = json_object_new_object();
dap_sign_t *l_sign = (dap_sign_t*)(a_signs + l_offset);
l_offset += dap_sign_get_size(l_sign);
if (l_sign->header.sign_size == 0) {
json_object *l_wrn_text = json_object_new_string("<CORRUPTED - 0 size signature>");
json_object_object_add(l_jobj_sign, "warning", l_wrn_text);
continue;
}
dap_chain_hash_fast_t l_pkey_hash = {0};
if (dap_sign_get_pkey_hash(l_sign, &l_pkey_hash) == false) {
json_object *l_wrn_text = json_object_new_string("<CORRUPTED - can't calc hash>");
json_object_object_add(l_jobj_sign, "warning", l_wrn_text);
continue;
}
json_object *l_jobj_hash_str = json_object_new_string(dap_chain_hash_fast_to_str_static(&l_pkey_hash));
json_object *l_jobj_type_str = json_object_new_string(dap_sign_type_to_str(l_sign->header.type));
json_object *l_jobj_sign_size = json_object_new_uint64(l_sign->header.sign_size);
json_object_object_add(l_jobj_sign, "hash", l_jobj_hash_str);
json_object_object_add(l_jobj_sign, "type", l_jobj_type_str);
json_object_object_add(l_jobj_sign, "size", l_jobj_sign_size);
json_object_array_add(l_jobs_signs, l_jobj_sign);
}
return l_jobs_signs;
}
json_object *dap_chain_datum_anchor_to_json(dap_chain_datum_anchor_t *a_anchor){
json_object *l_obj_anchor = json_object_new_object();
if (!l_obj_anchor) {
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_version = json_object_new_uint64(a_anchor->anchor_version);
if (!l_obj_version){
json_object_put(l_obj_anchor);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_ts_created = json_object_new_uint64(a_anchor->header.ts_created);
if (!l_obj_ts_created) {
json_object_put(l_obj_version);
json_object_put(l_obj_anchor);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_tsd_array = json_object_new_array();
if(!l_obj_tsd_array) {
json_object_put(l_obj_ts_created);
json_object_put(l_obj_version);
json_object_put(l_obj_anchor);
dap_json_rpc_allocation_error;
return NULL;
}
size_t l_tsd_offset = 0, tsd_data_size = a_anchor->header.data_size;
while(l_tsd_offset < tsd_data_size){
json_object *l_jobj_tsd = json_object_new_object();
if (!l_jobj_tsd) {
json_object_put(l_obj_tsd_array);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_version);
json_object_put(l_obj_anchor);
dap_json_rpc_allocation_error;
return NULL;
}
dap_tsd_t *l_tsd = (dap_tsd_t*)a_anchor->data_n_sign + l_tsd_offset;
size_t l_tsd_size = l_tsd->size + sizeof(dap_tsd_t);
if(l_tsd_size > tsd_data_size){
json_object *l_jobj_wgn = json_object_new_string("TSD size is greater than all data size. It's possible corrupt data.");
if (!l_jobj_wgn){
json_object_put(l_jobj_tsd);
json_object_put(l_obj_tsd_array);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_version);
json_object_put(l_obj_anchor);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_jobj_wgn);
json_object_array_add(l_obj_tsd_array, l_jobj_tsd);
break;
}
if (l_tsd->type == DAP_CHAIN_DATUM_ANCHOR_TSD_TYPE_DECREE_HASH){
json_object *l_obj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_ANCHOR_TSD_TYPE_DECREE_HASH");
if (!l_obj_tsd_type){
json_object_put(l_jobj_tsd);
json_object_put(l_obj_tsd_array);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_version);
json_object_put(l_obj_anchor);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
if(l_tsd->size > sizeof(dap_hash_fast_t)){
json_object *l_jobj_wgn = json_object_new_string("Wrong fee tsd data size.");
if (!l_jobj_wgn){
json_object_put(l_jobj_tsd);
json_object_put(l_obj_tsd_array);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_version);
json_object_put(l_obj_anchor);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_jobj_wgn);
json_object_array_add(l_obj_tsd_array, l_jobj_tsd);
break;
}
dap_hash_fast_t l_out_hash = {0};
_dap_tsd_get_scalar(l_tsd, &l_out_hash);
char *l_hash_str = dap_hash_fast_to_str_new(&l_out_hash);
if (!l_hash_str) {
json_object_put(l_jobj_tsd);
json_object_put(l_obj_tsd_array);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_version);
json_object_put(l_obj_anchor);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_tsd_hash = json_object_new_string(l_hash_str);
DAP_DELETE(l_hash_str);
if (!l_obj_tsd_hash){
json_object_put(l_jobj_tsd);
json_object_put(l_obj_tsd_array);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_version);
json_object_put(l_obj_anchor);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "hash", l_obj_tsd_hash);
}
json_object_array_add(l_obj_tsd_array, l_jobj_tsd);
l_tsd_offset += l_tsd_size;
}
json_object_object_add(l_obj_anchor, "version", l_obj_version);
json_object_object_add(l_obj_anchor, "ts_created", l_obj_ts_created);
json_object_object_add(l_obj_anchor, "TSD", l_obj_tsd_array);
json_object *l_jobj_signs = s_dap_chain_datum_anchor_sign_to_json(a_anchor->data_n_sign + a_anchor->header.data_size,
a_anchor->header.signs_size);
if (!l_jobj_signs) {
json_object_put(l_obj_tsd_array);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_ts_created);
json_object_put(l_obj_version);
json_object_put(l_obj_anchor);
dap_json_rpc_error_add(DAP_JSON_RPC_ERR_CODE_SERIALIZATION_SIGN_TO_JSON, "I can't serialize the anchor signature in JSON.");
return NULL;
}
json_object_object_add(l_obj_anchor, "signs", l_jobj_signs);
return l_obj_anchor;
}
#include "dap_json_rpc_chain_datum_decree.h"
#include "dap_json_rpc_chain_common.h"
#include "json.h"
#define LOG_TAG "dap_json_rpc_chain_datum_decree"
json_object *s_dap_chain_datum_decree_certs_dump_json(byte_t * a_signs, size_t a_certs_size){
json_object *l_jobj_signatures = json_object_new_array();
if (!l_jobj_signatures) {
dap_json_rpc_allocation_error;
return NULL;
}
size_t l_offset = 0;
for (int i = 1; l_offset < (a_certs_size); i++) {
json_object *l_jobj_signature = json_object_new_object();
if (!l_jobj_signature) {
json_object_put(l_jobj_signatures);
dap_json_rpc_allocation_error;
return NULL;
}
dap_sign_t *l_sign = (dap_sign_t *) (a_signs + l_offset);
l_offset += dap_sign_get_size(l_sign);
if (l_sign->header.sign_size == 0) {
json_object *l_wrn_text = json_object_new_string("<CORRUPTED - 0 size signature>");
if(!l_wrn_text) {
json_object_put(l_jobj_signature);
json_object_put(l_jobj_signatures);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_signature, "warning", l_wrn_text);
continue;
}
dap_chain_hash_fast_t l_pkey_hash = {0};
if (dap_sign_get_pkey_hash(l_sign, &l_pkey_hash) == false) {
json_object *l_wrn_text = json_object_new_string("<CORRUPTED - can't calc hash>");
if (!l_wrn_text){
json_object_put(l_jobj_signature);
json_object_put(l_jobj_signatures);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_signature, "warning", l_wrn_text);
continue;
}
json_object *l_jobj_hash_str
= json_object_new_string(dap_chain_hash_fast_to_str_static(&l_pkey_hash));
if (!l_jobj_hash_str) {
json_object_put(l_jobj_signature);
json_object_put(l_jobj_signatures);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_type_str = json_object_new_string(dap_sign_type_to_str(l_sign->header.type));
if (!l_jobj_type_str) {
json_object_put(l_jobj_hash_str);
json_object_put(l_jobj_signature);
json_object_put(l_jobj_signatures);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_sign_size = json_object_new_uint64(l_sign->header.sign_size);
if (!l_jobj_sign_size) {
json_object_put(l_jobj_hash_str);
json_object_put(l_jobj_type_str);
json_object_put(l_jobj_signature);
json_object_put(l_jobj_signatures);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_signature, "hash", l_jobj_hash_str);
json_object_object_add(l_jobj_signature, "type", l_jobj_type_str);
json_object_object_add(l_jobj_signature, "size", l_jobj_sign_size);
json_object_array_add(l_jobj_signatures, l_jobj_signature);
}
return l_jobj_signatures;
}
json_object *dap_chain_datum_decree_to_json(dap_chain_datum_decree_t *a_decree){
json_object *l_jobj_decree = json_object_new_object();
if (!l_jobj_decree) {
dap_json_rpc_allocation_error;
return NULL;
}
char *l_type_str = "";
switch(a_decree->header.type)
{
case DAP_CHAIN_DATUM_DECREE_TYPE_COMMON:
l_type_str = "DECREE_TYPE_COMMON";
break;
case DAP_CHAIN_DATUM_DECREE_TYPE_SERVICE:
l_type_str = "DECREE_TYPE_SERVICE";
break;
default:
l_type_str = "DECREE_TYPE_UNKNOWN";
}
json_object *l_jobj_type = json_object_new_string(l_type_str);
if (!l_jobj_type) {
json_object_put(l_jobj_decree);
dap_json_rpc_allocation_error;
return NULL;
}
const char *l_subtype_str = dap_chain_datum_decree_subtype_to_str(a_decree->header.sub_type);
json_object *l_json_subtype = json_object_new_string(l_subtype_str);
if (!l_json_subtype) {
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_json_tsd_array = json_object_new_array();
if (!l_json_tsd_array){
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
dap_json_rpc_allocation_error;
return NULL;
}
for (size_t l_offset = 0; l_offset < a_decree->header.data_size;) {
dap_tsd_t *l_tsd = (dap_tsd_t *)((byte_t*)a_decree->data_n_signs + l_offset);
l_offset += dap_tsd_size(l_tsd);
json_object *l_jobj_tsd = json_object_new_object();
if (!l_jobj_tsd) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
dap_json_rpc_allocation_error;
return NULL;
}
switch(l_tsd->type) {
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_SIGN: {
json_object *l_obj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_DECREE_TSD_TYPE_SIGN");
if (!l_obj_tsd_type) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE: {
json_object *l_obj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE");
if (!l_obj_tsd_type) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
if (l_tsd->size > sizeof(uint256_t)) {
json_object *l_text_wgn = json_object_new_string("Fee: <WRONG SIZE>");
if (!l_text_wgn) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_text_wgn);
break;
}
uint256_t l_fee_value = uint256_0;
_dap_tsd_get_scalar(l_tsd, &l_fee_value);
json_object *l_jobj_fee = json_object_new_string(dap_uint256_to_char(l_fee_value, NULL));
if (!l_jobj_fee) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "value", l_jobj_fee);
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_OWNER: {
json_object *l_obj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_DECREE_TSD_TYPE_OWNER");
if (!l_obj_tsd_type){
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
if (l_tsd->size < sizeof(dap_pkey_t)) {
json_object *l_text_wgn = json_object_new_string("Owner fingerprint: <WRONG SIZE>");
if (!l_text_wgn){
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_text_wgn);
break;
}
dap_pkey_t *l_owner_pkey = DAP_NEW_Z_SIZE(dap_pkey_t, l_tsd->size);
if(!l_owner_pkey) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
memcpy(l_owner_pkey, l_tsd->data, l_tsd->size);
dap_hash_fast_t l_owner_pkey_hash = {0};
dap_hash_fast(l_owner_pkey->pkey, l_owner_pkey->header.size, &l_owner_pkey_hash);
char l_owner_pkey_str[DAP_CHAIN_HASH_FAST_STR_SIZE];
dap_chain_hash_fast_to_str(&l_owner_pkey_hash, l_owner_pkey_str, sizeof(l_owner_pkey_str));
json_object *l_jobj_owner_pkey = json_object_new_string(l_owner_pkey_str);
if (!l_jobj_owner_pkey) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "owner_fingerprint", l_jobj_owner_pkey);
DAP_DELETE(l_owner_pkey);
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_MIN_OWNER: {
json_object *l_obj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_DECREE_TSD_TYPE_MIN_OWNER");
if (!l_obj_tsd_type){
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
if (l_tsd->size > sizeof(uint256_t)){
json_object *l_text_wgn = json_object_new_string("Owner min: <WRONG SIZE>");
if (!l_text_wgn) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_text_wgn);
break;
}
uint256_t l_owner_min = {0};
_dap_tsd_get_scalar(l_tsd, &l_owner_min);
json_object *l_jobj_owner_min = json_object_new_string(dap_uint256_to_char(l_owner_min, NULL));
if (!l_jobj_owner_min) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "owner_min", l_jobj_owner_min);
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE_WALLET: {
json_object *l_obj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_DECREE_TSD_TYPE_FEE_WALLET");
if (!l_obj_tsd_type) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
if (l_tsd->size > sizeof(dap_chain_addr_t)) {
json_object *l_text_wgn = json_object_new_string("Wallet for fee: <WRONG SIZE>");
if (!l_text_wgn) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_text_wgn);
break;
}
dap_chain_addr_t l_addr_fee_wallet = {0};
_dap_tsd_get_scalar(l_tsd, &l_addr_fee_wallet);
json_object *l_jobj_addr_fee_wallet = dap_chain_addr_to_json(&l_addr_fee_wallet);
if (!l_jobj_addr_fee_wallet) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "addr", l_jobj_addr_fee_wallet);
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_TX_HASH: {
json_object *l_obj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_TX_HASH");
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
if (l_tsd->size > sizeof(dap_hash_fast_t)) {
json_object *l_text_wgn = json_object_new_string("Stake tx: <WRONG SIZE>");
json_object_object_add(l_jobj_tsd, "warning", l_text_wgn);
break;
}
dap_hash_fast_t l_stake_tx = {0};
_dap_tsd_get_scalar(l_tsd, &l_stake_tx);
json_object *l_jobj_tx_hash =
json_object_new_string(dap_chain_hash_fast_to_str_static(&l_stake_tx));
if (!l_jobj_tx_hash) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "hash", l_jobj_tx_hash);
// char *l_stake_tx_hash = dap_strcmp(a_hash_out_type, "hex")
// ? dap_enc_base58_encode_hash_to_str(&l_stake_tx)
// : dap_chain_hash_fast_to_str_new(&l_stake_tx);
// dap_string_append_printf(a_str_out, "\tStake tx: %s\n", l_stake_tx_hash);
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_VALUE: {
json_object *l_obj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_VALUE");
if (!l_obj_tsd_type){
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
if (l_tsd->size > sizeof(uint256_t)) {
json_object *l_text_wgn = json_object_new_string("Stake value: <WRONG SIZE>");
if (!l_text_wgn){
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_text_wgn);
break;
}
uint256_t l_stake_value = uint256_0;
_dap_tsd_get_scalar(l_tsd, &l_stake_value);
json_object *l_jobj_stake_value = json_object_new_string(dap_uint256_to_char(l_stake_value, NULL));
if (!l_jobj_stake_value){
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "value", l_jobj_stake_value);
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_SIGNING_ADDR: {
json_object *l_obj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_SIGNING_ADDR");
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
if (l_tsd->size > sizeof(dap_chain_addr_t)) {
json_object *l_text_wgn = json_object_new_string("Signing addr: <WRONG SIZE>");
json_object_object_add(l_jobj_tsd, "warning", l_text_wgn);
break;
}
dap_chain_addr_t l_stake_addr_signing = {0};
_dap_tsd_get_scalar(l_tsd, &l_stake_addr_signing);
// dap_string_append_printf(a_str_out, "\tSigning addr: %s\n", l_stake_addr_signing_str);
dap_chain_hash_fast_t l_pkey_signing = l_stake_addr_signing.data.hash_fast;
const char *l_pkey_signing_str = dap_chain_hash_fast_to_str_static(&l_pkey_signing);
json_object *l_jobj_stake_addr_signing = dap_chain_addr_to_json(&l_stake_addr_signing);
json_object *l_jobj_pkey_signing = json_object_new_string(l_pkey_signing_str);
json_object_object_add(l_jobj_tsd, "addr", l_jobj_stake_addr_signing);
json_object_object_add(l_jobj_tsd, "pkey", l_jobj_pkey_signing);
// char *l_pkey_signing_str = dap_strcmp(a_hash_out_type, "hex")
// ? dap_enc_base58_encode_hash_to_str(l_pkey_signing)
// : dap_chain_hash_fast_to_str_new(l_pkey_signing);
// dap_string_append_printf(a_str_out, "\tSigning pkey fingerprint: %s\n", l_pkey_signing_str);
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_SIGNER_NODE_ADDR: {
json_object *l_obj_tsd_type = json_object_new_string(
"DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_SIGNER_NODE_ADDR");
if (!l_obj_tsd_type) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
if(l_tsd->size > sizeof(dap_chain_node_addr_t)){
json_object *l_text_wgn = json_object_new_string("Node addr: <WRONG SIZE>");
if (!l_text_wgn){
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_text_wgn);
break;
}
dap_chain_node_addr_t l_node_addr = {0};
_dap_tsd_get_scalar(l_tsd, &l_node_addr);
char *l_node_addr_str = dap_strdup_printf(NODE_ADDR_FP_STR,NODE_ADDR_FP_ARGS_S(l_node_addr));
if (!l_node_addr_str) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_node_addr = json_object_new_string(l_node_addr_str);
DAP_DELETE(l_node_addr_str);
if (!l_jobj_node_addr){
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "node", l_jobj_node_addr);
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_VALUE: {
json_object *l_obj_tsd_type = json_object_new_string(
"DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_VALUE");
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
if (l_tsd->size > sizeof(uint256_t)) {
json_object *l_text_wgn = json_object_new_string("Min value: <WRONG SIZE>");
json_object_object_add(l_jobj_tsd, "warning", l_text_wgn);
break;
}
uint256_t l_min_value = uint256_0;
_dap_tsd_get_scalar(l_tsd, &l_min_value);
json_object_object_add(l_jobj_tsd, "value", json_object_new_string(dap_uint256_to_char(l_min_value, NULL)));
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_SIGNERS_COUNT: {
json_object *l_obj_tsd_type = json_object_new_string(
"DAP_CHAIN_DATUM_DECREE_TSD_TYPE_STAKE_MIN_SIGNERS_COUNT");
if (!l_obj_tsd_type) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
if (l_tsd->size > sizeof(uint256_t)) {
json_object *l_text_wgn = json_object_new_string("Min signers count: <WRONG SIZE>");
if(!l_text_wgn){
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "warning", l_text_wgn);
break;
}
uint256_t l_min_signers_count = uint256_0;
_dap_tsd_get_scalar(l_tsd, &l_min_signers_count);
json_object *l_jobj_min_signers_count = json_object_new_string(dap_uint256_to_char(l_min_signers_count, NULL));
if (!l_jobj_min_signers_count) {
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "count", l_jobj_min_signers_count);
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_NODE_ADDR: {
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_DECREE_TSD_TYPE_NODE_ADDR");
json_object *l_jobj_node_addr = json_object_new_string(l_tsd->data);
if (!l_jobj_tsd_type && !l_jobj_node_addr) {
json_object_put(l_jobj_tsd_type);
json_object_put(l_jobj_node_addr);
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "node_addr", l_jobj_node_addr);
} break;
case DAP_CHAIN_DATUM_DECREE_TSD_TYPE_HOST: {
json_object *l_jobj_tsd_type = json_object_new_string("DAP_CHAIN_DATUM_DECREE_TSD_TYPE_HOST");
json_object *l_jobj_host = json_object_new_string(l_tsd->data);
if (!l_jobj_tsd_type && !l_jobj_host) {
json_object_put(l_jobj_tsd_type);
json_object_put(l_jobj_host);
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_jobj_tsd_type);
json_object_object_add(l_jobj_tsd, "host", l_jobj_host);
} break;
default: {
json_object *l_obj_tsd_type = json_object_new_string(
"<UNKNOWN_TYPE_TSD_SECTION>");
if (!l_obj_tsd_type){
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
json_object_put(l_jobj_tsd);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_tsd, "type", l_obj_tsd_type);
} break;
}
json_object_array_add(l_json_tsd_array, l_jobj_tsd);
}
json_object *l_jobj_signs = s_dap_chain_datum_decree_certs_dump_json(a_decree->data_n_signs + a_decree->header.data_size,
a_decree->header.signs_size);
if (!l_jobj_signs){
json_object_put(l_json_tsd_array);
json_object_put(l_json_subtype);
json_object_put(l_jobj_type);
json_object_put(l_jobj_decree);
dap_json_rpc_error_add(DAP_JSON_RPC_ERR_CODE_SERIALIZATION_SIGN_TO_JSON, "Can't serialize the decree signature in JSON.");
return NULL;
}
json_object_object_add(l_jobj_decree, "type", l_jobj_type);
json_object_object_add(l_jobj_decree, "subtype", l_json_subtype);
json_object_object_add(l_jobj_decree, "TSD", l_json_tsd_array);
json_object_object_add(l_jobj_decree, "signs", l_jobj_signs);
return l_jobj_decree;
}
#include "dap_json_rpc_chain_datum_token.h"
#include "dap_json_rpc_chain_common.h"
#include "dap_json_rpc_sign.h"
#include "json.h"
#define LOG_TAG "dap_json_rpc_chain_datum_token"
json_object *dap_chain_datum_token_flags_to_json(uint16_t a_flags){
if (!a_flags) {
return json_object_new_null();
}
json_object *l_jobj_flags = json_object_new_array();
for (uint16_t i = 0; BIT(i) <= DAP_CHAIN_DATUM_TOKEN_FLAG_MAX; i++){
if(a_flags & (1 << i)){
json_object *l_jobj_flag_txt = json_object_new_string(c_dap_chain_datum_token_flag_str[BIT(i)]);
json_object_array_add(l_jobj_flags, l_jobj_flag_txt);
}
}
return l_jobj_flags;
}
json_object *dap_chain_datum_token_to_json(dap_chain_datum_token_t * a_token, size_t a_token_size){
json_object *l_jobj_token = json_object_new_object();
if (!l_jobj_token){
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_type;
json_object *l_jobj_version = json_object_new_uint64(a_token->version);
if (!l_jobj_version) {
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
switch (a_token->type) {
case DAP_CHAIN_DATUM_TOKEN_TYPE_DECL:
l_jobj_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TYPE_DECL");
break;
case DAP_CHAIN_DATUM_TOKEN_TYPE_UPDATE:
l_jobj_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TYPE_UPDATE");
break;
default:
l_jobj_type = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_TYPE_UNKNOWN");
break;
}
if (!l_jobj_type) {
json_object_put(l_jobj_version);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_token, "version", l_jobj_version);
json_object_object_add(l_jobj_token, "type", l_jobj_type);
json_object *l_jobj_subtype = NULL;
json_object *l_jobj_header = json_object_new_object();
if (!l_jobj_header){
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
size_t l_tsd_total_size = 0;
switch (a_token->subtype) {
case DAP_CHAIN_DATUM_TOKEN_SUBTYPE_SIMPLE: {
json_object *l_jobj_decimals = json_object_new_uint64(a_token->header_simple.decimals);
if (!l_jobj_decimals){
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_header, "decimals", l_jobj_decimals);
l_jobj_subtype = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_SUBTYPE_SIMPLE");
}break;
case DAP_CHAIN_DATUM_TOKEN_SUBTYPE_PRIVATE: {
json_object *l_jobj_flags = NULL;
json_object *l_jobj_decimals = NULL;
if (a_token->type == DAP_CHAIN_DATUM_TOKEN_TYPE_DECL) {
l_jobj_flags = json_object_new_string(s_flag_str_from_code(a_token->header_private_decl.flags));
if (!l_jobj_flags){
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
l_jobj_decimals = json_object_new_uint64(a_token->header_private_decl.decimals);
if (!l_jobj_decimals) {
json_object_put(l_jobj_flags);
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
l_tsd_total_size = a_token->header_private_decl.tsd_total_size;
} else {
l_jobj_flags = json_object_new_string(s_flag_str_from_code(a_token->header_private_update.flags));
if (!l_jobj_flags) {
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
l_jobj_decimals = json_object_new_uint64(a_token->header_private_update.decimals);
if (!l_jobj_decimals) {
json_object_put(l_jobj_flags);
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
l_tsd_total_size = a_token->header_private_update.tsd_total_size;
}
json_object_object_add(l_jobj_header, "flags", l_jobj_flags);
json_object_object_add(l_jobj_header, "decimals", l_jobj_decimals);
l_jobj_subtype = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_SUBTYPE_PRIVATE");
} break;
case DAP_CHAIN_DATUM_TOKEN_SUBTYPE_NATIVE: {
json_object *l_jobj_flags = NULL;
json_object *l_jobj_decimals = NULL;
if (a_token->type == DAP_CHAIN_DATUM_TOKEN_TYPE_DECL) {
l_jobj_flags = json_object_new_string(s_flag_str_from_code(a_token->header_native_decl.flags));
if (!l_jobj_flags) {
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
l_jobj_decimals = json_object_new_uint64(a_token->header_native_decl.decimals);
if (!l_jobj_decimals){
json_object_put(l_jobj_flags);
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
l_tsd_total_size = a_token->header_native_decl.tsd_total_size;
} else {
l_jobj_flags = json_object_new_string(s_flag_str_from_code(a_token->header_native_update.flags));
if (!l_jobj_flags) {
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
l_jobj_decimals = json_object_new_uint64(a_token->header_native_update.decimals);
if (!l_jobj_decimals) {
json_object_put(l_jobj_flags);
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
l_tsd_total_size = a_token->header_native_update.tsd_total_size;
}
json_object_object_add(l_jobj_header, "flags", l_jobj_flags);
json_object_object_add(l_jobj_header, "decimals", l_jobj_decimals);
l_jobj_subtype = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_SUBTYPE_NATIVE");
} break;
case DAP_CHAIN_DATUM_TOKEN_SUBTYPE_PUBLIC: {
json_object *l_jobj_flags = json_object_new_string(s_flag_str_from_code(a_token->header_public.flags));
if (!l_jobj_flags){
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_premine_supply = json_object_new_string(dap_uint256_to_char(a_token->header_public.premine_supply, NULL));
if (!l_jobj_premine_supply) {
json_object_put(l_jobj_flags);
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_premine_address = dap_chain_addr_to_json(&a_token->header_public.premine_address);
if (!l_jobj_premine_address) {
json_object_put(l_jobj_flags);
json_object_put(l_jobj_premine_supply);
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_error_add(DAP_JSON_RPC_ERR_CODE_SERIALIZATION_ADDR_TO_JSON,
"Failed to convert address to JSON.");
return NULL;
}
json_object_object_add(l_jobj_header, "flags", l_jobj_flags);
json_object_object_add(l_jobj_header, "premine_supply", l_jobj_premine_supply);
json_object_object_add(l_jobj_header, "premine_address", l_jobj_premine_address);
l_jobj_subtype = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_SUBTYPE_PUBLIC");
} break;
default: {
l_jobj_subtype = json_object_new_string("DAP_CHAIN_DATUM_TOKEN_SUBTYPE_UNKNOWN");
} break;
}
if (!l_jobj_subtype) {
json_object_put(l_jobj_header);
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_token, "subtype", l_jobj_subtype);
json_object_object_add(l_jobj_token, "header", l_jobj_header);
json_object *l_jobj_ticker = json_object_new_string(a_token->ticker);
if (!l_jobj_ticker) {
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_token, "ticker", l_jobj_ticker);
json_object *l_jobj_signs_valid = json_object_new_uint64(a_token->signs_valid);
if (!l_jobj_signs_valid) {
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_token, "signs_valid", l_jobj_signs_valid);
json_object *l_jobj_signs_total = json_object_new_uint64(a_token->signs_total);
if (!l_jobj_signs_total) {
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_jobj_token, "signs_total", l_jobj_signs_total);
json_object *l_obj_signs = json_object_new_array();
if (!l_obj_signs) {
json_object_put(l_jobj_token);
dap_json_rpc_allocation_error;
return NULL;
}
size_t l_offset = 0;
size_t l_certs_field_size = a_token_size - sizeof(*a_token);
while ((l_offset + l_tsd_total_size) < l_certs_field_size) {
dap_sign_t *l_sign = (dap_sign_t *) ((byte_t*)a_token->data_n_tsd + l_tsd_total_size + l_offset);
l_offset += dap_sign_get_size(l_sign);
json_object *l_obj_sign = dap_sign_to_json(l_sign);
if (!l_obj_sign || !dap_sign_get_size(l_sign)) {
json_object_put(l_obj_signs);
json_object_put(l_jobj_token);
dap_json_rpc_error_add(DAP_JSON_RPC_ERR_CODE_SERIALIZATION_SIGN_TO_JSON, "Failed to convert signature to JSON.");
return NULL;
}
json_object_array_add(l_obj_signs, l_obj_sign);
}
json_object_object_add(l_jobj_token, "signs", l_obj_signs);
return l_jobj_token;
}
json_object *dap_chain_datum_emission_to_json(dap_chain_datum_token_emission_t *a_emission, size_t a_emission_size){
json_object *l_emi_obj = json_object_new_object();
json_object *l_emi_version = json_object_new_uint64(a_emission->hdr.version);
json_object *l_emi_type = json_object_new_string(c_dap_chain_datum_token_emission_type_str[a_emission->hdr.type]);
json_object *l_emi_address = dap_chain_addr_to_json(&a_emission->hdr.address);
json_object *l_emi_header = json_object_new_object();
json_object *l_emi_data = json_object_new_object();
if (!l_emi_obj || !l_emi_version || !l_emi_type || !l_emi_address || !l_emi_header || ! l_emi_data) {
json_object_put(l_emi_obj);
json_object_put(l_emi_version);
json_object_put(l_emi_type);
json_object_put(l_emi_address);
json_object_put(l_emi_header);
json_object_put(l_emi_data);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_emi_header, "version", l_emi_version);
json_object_object_add(l_emi_header, "type", l_emi_type);
json_object_object_add(l_emi_header, "address", l_emi_address);
json_object_object_add(l_emi_obj, "header", l_emi_header);
switch (a_emission->hdr.type){
case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_AUTH: {
json_object *l_obj_size = json_object_new_uint64(a_emission->data.type_auth.size);
json_object *l_obj_tsd_total_size = json_object_new_uint64(a_emission->data.type_auth.tsd_total_size);
json_object *l_obj_signs_count = json_object_new_uint64(a_emission->data.type_auth.signs_count);
if (!l_obj_size || !l_obj_tsd_total_size || !l_obj_signs_count) {
json_object_put(l_obj_size);
json_object_put(l_obj_tsd_total_size);
json_object_put(l_obj_signs_count);
json_object_put(l_emi_data);
json_object_put(l_emi_obj);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_emi_data, "size", l_obj_size);
json_object_object_add(l_emi_data, "tsd_total_size", l_obj_tsd_total_size);
json_object_object_add(l_emi_data, "signs_count", l_obj_signs_count);
if (((void *) a_emission->tsd_n_signs + a_emission->data.type_auth.tsd_total_size) >
((void *) a_emission + a_emission_size)) {
char *l_err_str = dap_strdup_printf("Malformed DATUM type %d, TSD section is out-of-buffer (%" DAP_UINT64_FORMAT_U " vs %zu)",
a_emission->hdr.type, a_emission->data.type_auth.tsd_total_size, a_emission_size);
if (!l_err_str){
json_object_put(l_emi_data);
json_object_put(l_emi_obj);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_err_tsd = json_object_new_string(l_err_str);
DAP_DELETE(l_err_str);
if (!l_err_tsd) {
json_object_put(l_emi_data);
json_object_put(l_emi_obj);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_emi_data, "ERROR", l_err_tsd);
}
json_object *l_obj_signs = json_object_new_array();
if (!l_obj_signs){
json_object_put(l_emi_data);
json_object_put(l_emi_obj);
dap_json_rpc_allocation_error;
return NULL;
}
size_t l_offset = a_emission->data.type_auth.tsd_total_size;
for (int i = 0; i < a_emission->data.type_auth.signs_count; i++) {
dap_sign_t *l_sign = (dap_sign_t *) ((byte_t*)a_emission->tsd_n_signs + l_offset);
l_offset += dap_sign_get_size(l_sign);
json_object *l_obj_sign = dap_sign_to_json(l_sign);
if (!l_obj_sign) {
json_object_put(l_obj_signs);
json_object_put(l_emi_data);
json_object_put(l_emi_obj);
dap_json_rpc_error_add(3, "Failed to serialize signature to JSON object.");
return NULL;
}
json_object_array_add(l_obj_signs, l_obj_sign);
}
json_object_object_add(l_emi_data, "signs", l_obj_signs);
} break;
case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_ALGO: {
json_object *l_code_name = json_object_new_string(a_emission->data.type_algo.codename);
if (!l_code_name) {
json_object_put(l_emi_data);
json_object_put(l_emi_obj);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_emi_data, "codename", l_code_name);
} break;
case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_ATOM_OWNER: {
json_object *l_value_start = json_object_new_uint64(a_emission->data.type_atom_owner.value_start);
json_object *l_value_change_algo_codename = json_object_new_string(
a_emission->data.type_atom_owner.value_change_algo_codename);
if (!l_value_start || !l_value_change_algo_codename) {
json_object_put(l_value_start);
json_object_put(l_value_change_algo_codename);
json_object_put(l_emi_data);
json_object_put(l_emi_obj);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_emi_data, "value_start", l_value_start);
json_object_object_add(l_emi_data, "value_change_algo_codename", l_value_change_algo_codename);
} break;
case DAP_CHAIN_DATUM_TOKEN_EMISSION_TYPE_SMART_CONTRACT:
{
json_object *l_obj_addr = dap_chain_addr_to_json(&a_emission->data.type_presale.addr);
json_object *l_obj_flags = json_object_new_int64(a_emission->data.type_presale.flags);
json_object *l_obj_lock_time = json_object_new_uint64(a_emission->data.type_presale.lock_time);
if (!l_obj_addr || !l_obj_flags || !l_obj_lock_time) {
json_object_put(l_obj_addr);
json_object_put(l_obj_flags);
json_object_put(l_obj_lock_time);
json_object_put(l_emi_data);
json_object_put(l_emi_obj);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_emi_data, "addr", l_obj_addr);
json_object_object_add(l_emi_data, "flags", l_obj_flags);
json_object_object_add(l_emi_data, "lock_time", l_obj_lock_time);
}break;
}
json_object_object_add(l_emi_obj, "data", l_emi_data);
return l_emi_obj;
}
#include <memory.h>
#include <assert.h>
#include "dap_common.h"
#include "dap_sign.h"
#include "dap_chain_datum_tx.h"
#include "dap_chain_datum_tx_items.h"
#include "dap_json_rpc_chain_datum_tx.h"
#include "dap_json_rpc_chain_datum_tx_items.h"
#include "dap_json_rpc_chain_datum_tx_receipt.h"
#include "json.h"
#include "dap_chain_datum_tx_voting.h"
#include "dap_chain_net.h"
#define LOG_TAG "dap_json_rpc_chain_datum_tx"
json_object *dap_chain_datum_tx_to_json(dap_chain_datum_tx_t *a_tx, dap_chain_net_id_t *a_net_id){
json_object *l_obj_items = json_object_new_array();
if (!l_obj_items) {
dap_json_rpc_allocation_error;
return NULL;
}
uint32_t
l_tx_items_size_total = 0,
l_tx_items_size = a_tx->header.tx_items_size;
while(l_tx_items_size_total < l_tx_items_size) {
uint8_t *item = a_tx->tx_items + l_tx_items_size_total;
size_t l_tx_item_size = dap_chain_datum_item_tx_get_size(item);
if (l_tx_item_size == 0) {
json_object_put(l_obj_items);
l_obj_items = json_object_new_null();
break;
}
dap_chain_tx_item_type_t l_item_type = dap_chain_datum_tx_item_get_type(item);
json_object *l_obj_item_type = NULL, *l_obj_item_data = NULL;
switch (l_item_type) {
case TX_ITEM_TYPE_IN:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_IN");
l_obj_item_data = dap_chain_datum_tx_item_in_to_json((dap_chain_tx_in_t*)item);
break;
case TX_ITEM_TYPE_OUT:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_OUT");
l_obj_item_data = dap_chain_datum_tx_item_out_to_json((dap_chain_tx_out_t*)item);
break;
case TX_ITEM_TYPE_IN_REWARD:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_IN_REWARD");
l_obj_item_data = dap_chain_datum_tx_item_in_reward_to_json((dap_chain_tx_in_reward_t*)item);
break;
case TX_ITEM_TYPE_IN_EMS:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_IN_EMS");
l_obj_item_data = dap_chain_datum_tx_item_in_ems_to_json((dap_chain_tx_in_ems_t*)item);
break;
case TX_ITEM_TYPE_SIG:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_SIG");
l_obj_item_data = dap_chain_datum_tx_item_sig_to_json((dap_chain_tx_sig_t*)item);
break;
case TX_ITEM_TYPE_RECEIPT:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_RECEIPT");
l_obj_item_data = dap_chain_datum_tx_receipt_to_json((dap_chain_datum_tx_receipt_t*)item);
break;
case TX_ITEM_TYPE_IN_COND:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_IN_COND");
l_obj_item_data = dap_chain_datum_tx_item_in_cond_to_json((dap_chain_tx_in_cond_t*)item);
break;
case TX_ITEM_TYPE_OUT_COND:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_OUT_COND");
switch (((dap_chain_tx_out_cond_t*)item)->header.subtype) {
case DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_PAY:
l_obj_item_data = dap_chain_datum_tx_item_out_cond_srv_pay_to_json((dap_chain_tx_out_cond_t*)item);
break;
case DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_STAKE_LOCK:
l_obj_item_data = dap_chain_net_srv_stake_lock_cond_out_to_json((dap_chain_tx_out_cond_t*)item);
break;
case DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_STAKE_POS_DELEGATE:
l_obj_item_data = dap_chain_datum_tx_item_out_cond_srv_stake_to_json((dap_chain_tx_out_cond_t*)item);
break;
case DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE:
l_obj_item_data = dap_chain_datum_tx_item_out_cond_srv_xchange_to_json((dap_chain_tx_out_cond_t*)item);
break;
case DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE:
l_obj_item_data = json_object_new_object();
break;
default:break;
}
// add time
dap_time_t l_ts_exp = ((dap_chain_tx_out_cond_t*)item)->header.ts_expires;
char l_time_str[32] = "never";
if (l_ts_exp) {
dap_time_to_str_rfc822(l_time_str, DAP_TIME_STR_SIZE, l_ts_exp); /* Convert ts to "Sat May 17 01:17:08 2014\n" */
l_time_str[strlen(l_time_str)-1] = '\0'; /* Remove "\n"*/
}
json_object_object_add(l_obj_item_data, "ts_expires", json_object_new_string(l_time_str));
json_object_object_add(l_obj_item_data, "subtype", json_object_new_string(dap_chain_tx_out_cond_subtype_to_str(((dap_chain_tx_out_cond_t*)item)->header.subtype)));
char *l_val_str, *l_val_datoshi_str = dap_uint256_to_char(((dap_chain_tx_out_cond_t*)item)->header.value, &l_val_str);
json_object_object_add(l_obj_item_data, "value", json_object_new_string(l_val_str));
json_object_object_add(l_obj_item_data, "value_datoshi", json_object_new_string(l_val_datoshi_str));
char uid_str[32];
sprintf(uid_str, "0x%016"DAP_UINT64_FORMAT_x"", ((dap_chain_tx_out_cond_t*)item)->header.srv_uid.uint64);
json_object_object_add(l_obj_item_data, "uid", json_object_new_string(uid_str));
break;
case TX_ITEM_TYPE_OUT_EXT:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_OUT_EXT");
l_obj_item_data = dap_chain_datum_tx_item_out_ext_to_json((dap_chain_tx_out_ext_t*)item);
break;
case TX_ITEM_TYPE_TSD:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_TSD");
l_obj_item_data = dap_chain_datum_tx_item_tsd_to_json((dap_chain_tx_tsd_t*)item);
break;
case TX_ITEM_TYPE_VOTE:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_VOTE");
dap_chain_net_t *l_net = dap_chain_net_by_id(*a_net_id);
l_obj_item_data = dap_chain_datum_tx_item_vote_to_json((dap_chain_tx_vote_t*)item, l_net->pub.ledger);
break;
case TX_ITEM_TYPE_VOTING:
l_obj_item_type = json_object_new_string("TX_ITEM_TYPE_VOTING");
l_obj_item_data = dap_chain_datum_tx_item_voting_tsd_to_json(a_tx);
break;
default: {
char *l_hash_str;
dap_get_data_hash_str_static(a_tx, dap_chain_datum_tx_get_size(a_tx), l_hash_str);
log_it(L_NOTICE, "Transaction %s has an item whose type cannot be handled by the dap_chain_datum_tx_to_json function.", l_hash_str);
break;
}
}
if (!l_obj_item_type){
json_object_array_add(l_obj_items, json_object_new_null());
} else {
if (!l_obj_item_data)
l_obj_item_data = json_object_new_null();
json_object *l_obj_item = json_object_new_object();
if (!l_obj_item) {
json_object_put(l_obj_item_type);
json_object_put(l_obj_item_data);
json_object_put(l_obj_items);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_obj_item, "type", l_obj_item_type);
json_object_object_add(l_obj_item, "data", l_obj_item_data);
json_object_array_add(l_obj_items, l_obj_item);
}
l_tx_items_size_total += l_tx_item_size;
}
return l_obj_items;
}
#include <stdint.h>
#include <string.h>
#include "dap_common.h"
#include "dap_enc_key.h"
#include "dap_chain_common.h"
#include "dap_sign.h"
#include "dap_hash.h"
#include "dap_chain_datum_tx.h"
#include "dap_chain_datum_tx_in.h"
#include "dap_chain_datum_tx_out.h"
#include "dap_chain_datum_tx_in_cond.h"
#include "dap_chain_datum_tx_out_cond.h"
#include "dap_chain_datum_tx_items.h"
#include "dap_enc_base58.h"
#include "dap_json_rpc_chain_datum_tx_items.h"
#include "dap_json_rpc_chain_common.h"
#include "dap_json_rpc_sign.h"
#include "json.h"
#define LOG_TAG "dap_json_rpc_chain_datum_tx_items"
json_object *dap_chain_datum_tx_item_out_cond_srv_pay_to_json(dap_chain_tx_out_cond_t *item) {
char *l_coins_str,
*l_value_str = dap_uint256_to_char(((dap_chain_tx_out_cond_t*)item)->subtype.srv_pay.unit_price_max_datoshi, &l_coins_str);
char *l_hash_str = dap_enc_base58_encode_hash_to_str_static(&((dap_chain_tx_out_cond_t*)item)->subtype.srv_pay.pkey_hash);
json_object *l_obj = json_object_new_object();
char unit_str[32];
snprintf(unit_str, 32, "0x%08x", ((dap_chain_tx_out_cond_t*)item)->subtype.srv_pay.unit.uint32);
json_object_object_add(l_obj, "unit", json_object_new_string(unit_str));
json_object_object_add(l_obj, "pkey", json_object_new_string(l_hash_str));
json_object_object_add(l_obj, "max_price", json_object_new_string(l_coins_str));
json_object_object_add(l_obj, "max_price_datoshi", json_object_new_string(l_value_str));
return l_obj;
}
json_object* dap_chain_datum_tx_item_out_cond_srv_xchange_to_json(dap_chain_tx_out_cond_t* a_srv_xchange) {
if (a_srv_xchange->header.subtype == DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE){
json_object *l_object = json_object_new_object();
json_object_object_add(l_object, "value", json_object_new_string(dap_uint256_to_char(a_srv_xchange->header.value, NULL)));
json_object_object_add(l_object, "rate", ( {
char *l_rate; dap_uint256_to_char(a_srv_xchange->subtype.srv_xchange.rate, &l_rate);
json_object_new_string(l_rate); } ));
json_object_object_add(l_object, "srv_uid", json_object_new_uint64(a_srv_xchange->header.srv_uid.uint64));
json_object_object_add(l_object, "buy_net_id", dap_chain_net_id_to_json(a_srv_xchange->subtype.srv_xchange.buy_net_id));
json_object_object_add(l_object, "sell_net_id", dap_chain_net_id_to_json(a_srv_xchange->subtype.srv_xchange.sell_net_id));
json_object_object_add(l_object, "buy_token", json_object_new_string(a_srv_xchange->subtype.srv_xchange.buy_token));
json_object_object_add(l_object, "seller_addr", dap_chain_addr_to_json(&a_srv_xchange->subtype.srv_xchange.seller_addr));
//TODO: Parse TSD
return l_object;
}
return NULL;
}
json_object *dap_chain_datum_tx_item_out_cond_srv_stake_to_json(dap_chain_tx_out_cond_t* a_srv_stake) {
if (a_srv_stake->header.subtype == DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_STAKE_POS_DELEGATE) {
json_object *l_object = json_object_new_object();
json_object *l_obj_value = json_object_new_string(dap_uint256_to_char(a_srv_stake->header.value, NULL));
json_object *l_obj_srv_uid = json_object_new_uint64(a_srv_stake->header.srv_uid.uint64);
json_object *l_obj_signing_addr = dap_chain_addr_to_json(&a_srv_stake->subtype.srv_stake_pos_delegate.signing_addr);
char *l_signer_node_addr = dap_strdup_printf(
NODE_ADDR_FP_STR,
NODE_ADDR_FP_ARGS_S(a_srv_stake->subtype.srv_stake_pos_delegate.signer_node_addr));
json_object *l_obj_signer_node_addr = json_object_new_string(l_signer_node_addr);
DAP_DELETE(l_signer_node_addr);
json_object_object_add(l_object, "value", l_obj_value);
json_object_object_add(l_object, "srv_uid", l_obj_srv_uid);
json_object_object_add(l_object, "signind_addr", l_obj_signing_addr);
json_object_object_add(l_object, "signer_node_addr", l_obj_signer_node_addr);
return l_object;
}
return NULL;
}
json_object *dap_chain_net_srv_stake_lock_cond_out_to_json(dap_chain_tx_out_cond_t *a_stake_lock)
{
if (a_stake_lock->header.subtype == DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_STAKE_LOCK) {
json_object *l_object = json_object_new_object();
json_object_object_add(l_object, "value", json_object_new_string(dap_uint256_to_char(a_stake_lock->header.value, NULL)));
json_object_object_add(l_object, "srv_uid", json_object_new_uint64(a_stake_lock->header.srv_uid.uint64));
json_object_object_add(l_object, "reinvest_percent",
json_object_new_string(dap_uint256_to_char(a_stake_lock->subtype.srv_stake_lock.reinvest_percent, NULL)));
json_object_object_add(l_object, "time_unlock", json_object_new_uint64(a_stake_lock->subtype.srv_stake_lock.time_unlock));
json_object_object_add(l_object, "flags", json_object_new_uint64(a_stake_lock->subtype.srv_stake_lock.flags));
return l_object;
}
return NULL;
}
json_object* dap_chain_datum_tx_item_out_to_json(const dap_chain_tx_out_t *a_out) {
json_object *l_object = json_object_new_object();
char *l_val_coins, *l_val_datoshi = dap_uint256_to_char(a_out->header.value, &l_val_coins);
json_object_object_add(l_object, "value", json_object_new_string(l_val_coins));
json_object_object_add(l_object, "value_datoshi", json_object_new_string(l_val_datoshi));
json_object_object_add(l_object, "address", dap_chain_addr_to_json(&a_out->addr));
return l_object;
}
json_object* dap_chain_datum_tx_item_out_ext_to_json(const dap_chain_tx_out_ext_t *a_out_ext) {
json_object *l_obj = json_object_new_object();
json_object_object_add(l_obj, "value", json_object_new_string(dap_uint256_to_char(a_out_ext->header.value, NULL)));
json_object_object_add(l_obj, "addr", dap_chain_addr_to_json(&a_out_ext->addr));
json_object_object_add(l_obj, "token", json_object_new_string(a_out_ext->token));
return l_obj;
}
json_object* dap_chain_datum_tx_item_in_cond_to_json(dap_chain_tx_in_cond_t *a_in_cond){
json_object *l_obj = json_object_new_object();
if (!l_obj) {
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_receipt_idx = json_object_new_uint64(a_in_cond->header.receipt_idx);
if (!l_obj_receipt_idx) {
json_object_put(l_obj);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_out_prev_idx = json_object_new_uint64(a_in_cond->header.tx_out_prev_idx);
if (!l_obj_out_prev_idx) {
json_object_put(l_obj_receipt_idx);
json_object_put(l_obj);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_prev_hash = NULL;
if (dap_hash_fast_is_blank(&a_in_cond->header.tx_prev_hash)){
l_obj_prev_hash = json_object_new_null();
} else {
char *l_prev_hash = dap_hash_fast_to_str_new(&a_in_cond->header.tx_prev_hash);
if(!l_prev_hash) {
json_object_put(l_obj_out_prev_idx);
json_object_put(l_obj_receipt_idx);
json_object_put(l_obj);
dap_json_rpc_allocation_error;
return NULL;
}
l_obj_prev_hash = json_object_new_string(dap_strdup(l_prev_hash));
if (!l_obj_prev_hash) {
json_object_put(l_obj_out_prev_idx);
json_object_put(l_obj_receipt_idx);
json_object_put(l_obj);
DAP_DELETE(l_prev_hash);
dap_json_rpc_allocation_error;
return NULL;
}
DAP_DELETE(l_prev_hash);
}
json_object_object_add(l_obj, "receipt_idx", l_obj_receipt_idx);
json_object_object_add(l_obj, "out_prev_idx", l_obj_out_prev_idx);
json_object_object_add(l_obj, "tx_prev_hash", l_obj_prev_hash);
return l_obj;
}
json_object* dap_chain_datum_tx_item_in_to_json(dap_chain_tx_in_t *a_in){
json_object *l_obj_in = json_object_new_object();
if (!l_obj_in) {
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_prev_idx = json_object_new_uint64(a_in->header.tx_out_prev_idx);
if (!l_obj_prev_idx) {
json_object_put(l_obj_in);
dap_json_rpc_allocation_error;
return NULL;
}
char l_hash[DAP_CHAIN_HASH_FAST_STR_SIZE];
dap_chain_hash_fast_to_str(&a_in->header.tx_prev_hash, l_hash, sizeof(l_hash));
json_object *l_obj_hash = json_object_new_string(l_hash);
if (!l_obj_hash) {
json_object_put(l_obj_in);
json_object_put(l_obj_prev_idx);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_obj_in, "prev_idx", l_obj_prev_idx);
json_object_object_add(l_obj_in, "prev_hash", l_obj_hash);
return l_obj_in;
}
json_object* dap_chain_datum_tx_item_in_reward_to_json(dap_chain_tx_in_reward_t *a_in_reward){
json_object *l_jobj_ret = json_object_new_object();
char *l_hash_block = dap_hash_fast_to_str_new(&a_in_reward->block_hash);
if (!l_jobj_ret && !l_hash_block) {
json_object_put(l_jobj_ret);
DAP_DEL_Z(l_hash_block);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_jobj_block_hash = json_object_new_string(l_hash_block);
DAP_DEL_Z(l_hash_block);
if (!l_jobj_block_hash) {
return NULL;
}
json_object_object_add(l_jobj_ret, "block_hash", l_jobj_block_hash);
return l_jobj_ret;
}
json_object* dap_chain_datum_tx_item_tsd_to_json(dap_chain_tx_tsd_t *a_tsd){
json_object *l_object = json_object_new_object();
if (!l_object) {
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_tsd_type = json_object_new_int(a_tsd->header.type);
if(!l_obj_tsd_type) {
json_object_put(l_object);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_tsd_size = json_object_new_uint64(a_tsd->header.size);
if (!l_obj_tsd_size) {
json_object_put(l_obj_tsd_type);
json_object_put(l_object);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_data = json_object_new_string_len((char *)a_tsd->tsd, a_tsd->header.size);
if (!l_obj_data) {
json_object_put(l_obj_tsd_size);
json_object_put(l_obj_tsd_type);
json_object_put(l_object);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_object, "type", l_obj_tsd_type);
json_object_object_add(l_object, "size", l_obj_tsd_size);
json_object_object_add(l_object, "data", l_obj_data);
return l_object;
}
json_object *dap_chain_datum_tx_item_in_ems_to_json(const dap_chain_tx_in_ems_t *a_in_ems)
{
json_object *l_object = json_object_new_object();
if (!l_object) {
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_ticker = json_object_new_string(a_in_ems->header.ticker);
if (!l_obj_ticker){
json_object_put(l_object);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_chain_id = json_object_new_uint64(a_in_ems->header.token_emission_chain_id.uint64);
if (!l_obj_chain_id) {
json_object_put(l_object);
json_object_put(l_obj_ticker);
dap_json_rpc_allocation_error;
return NULL;
}
char l_ehf[DAP_CHAIN_HASH_FAST_STR_SIZE];
dap_chain_hash_fast_to_str(&a_in_ems->header.token_emission_hash, l_ehf, sizeof(l_ehf));
json_object *l_obj_ehf = json_object_new_string(l_ehf);
if (!l_obj_ehf) {
json_object_put(l_object);
json_object_put(l_obj_chain_id);
json_object_put(l_obj_ticker);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_object, "ticker", l_obj_ticker);
json_object_object_add(l_object, "chain_id", l_obj_chain_id);
json_object_object_add(l_object, "emission_hash", l_obj_ehf);
return l_object;
}
json_object *dap_chain_datum_tx_item_out_cond_fee_to_json(dap_chain_tx_out_cond_t *a_fee) {
return a_fee->header.subtype == DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE
? ( {
json_object *l_obj = json_object_new_object();
json_object_object_add(l_obj, "balance", json_object_new_string(dap_uint256_to_char(a_fee->header.value, NULL)));
l_obj;
} )
: NULL;
}
json_object* dap_chain_datum_tx_item_sig_to_json(const dap_chain_tx_sig_t *a_sig){
json_object *l_object = json_object_new_object();
if (!l_object) {
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_sign_size = json_object_new_uint64(a_sig->header.sig_size);
if (!l_sign_size) {
json_object_put(l_object);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_sign = dap_sign_to_json((dap_sign_t*)a_sig->sig);
if (!l_sign) {
json_object_put(l_object);
json_object_put(l_sign_size);
dap_json_rpc_error_add(DAP_JSON_RPC_ERR_CODE_SERIALIZATION_SIGN_TO_JSON,
"Error serializing signature to JSON.");
return NULL;
}
json_object_object_add(l_object, "sign_size", l_sign_size);
json_object_object_add(l_object, "sign", l_sign);
return l_object;
}
#include "dap_common.h"
#include "dap_enc_key.h"
#include "dap_sign.h"
#include "dap_chain_datum_tx_receipt.h"
#include "dap_json_rpc_sign.h"
#include "dap_json_rpc_chain_datum_tx_receipt.h"
#include "json.h"
#define LOG_TAG "dap_json_rpc_chain_datum_tx_receipt"
json_object* dap_chain_receipt_info_to_json(dap_chain_receipt_info_t *a_info){
json_object *l_obj = json_object_new_object();
if (!l_obj) {
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_obj, "uid", json_object_new_uint64(a_info->srv_uid.uint64));
#if DAP_CHAIN_NET_SRV_UID_SIZE == 8
json_object_object_add(l_obj, "ext_size", json_object_new_uint64(a_info->addition));
#endif
json_object_object_add(l_obj, "units", json_object_new_uint64(a_info->units));
json_object_object_add(l_obj, "units_type", json_object_new_string(dap_chain_srv_unit_enum_to_str(a_info->units_type.enm)));
char *l_value, *l_datoshi_value = dap_uint256_to_char(a_info->value_datoshi, &l_value);
json_object_object_add(l_obj, "value", json_object_new_string(l_value));
json_object_object_add(l_obj, "value_datoshi", json_object_new_string(l_datoshi_value));
return l_obj;
}
json_object *dap_chain_datum_tx_receipt_to_json(dap_chain_datum_tx_receipt_t *a_receipt) {
json_object *l_obj = json_object_new_object();
if (!l_obj) {
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_info = dap_chain_receipt_info_to_json(&a_receipt->receipt_info);
if (!l_obj_info) {
json_object_put(l_obj);
return NULL;
}
json_object *l_obj_size = json_object_new_uint64(a_receipt->size);
if (!l_obj_size) {
json_object_put(l_obj);
json_object_put(l_obj_info);
dap_json_rpc_allocation_error;
return NULL;
}
//Provider
dap_sign_t *l_first_sign = dap_chain_datum_tx_receipt_sign_get(a_receipt, a_receipt->size, 1);
//Client
dap_sign_t *l_second_sign = dap_chain_datum_tx_receipt_sign_get(a_receipt, a_receipt->size, 2);
json_object *l_obj_signs = json_object_new_object();
if (!l_obj_signs) {
json_object_put(l_obj_size);
json_object_put(l_obj_info);
json_object_put(l_obj);
dap_json_rpc_allocation_error;
return NULL;
}
json_object *l_obj_provider_sign = dap_sign_to_json(l_first_sign);
json_object *l_obj_client_sign = dap_sign_to_json(l_second_sign);
json_object_object_add(l_obj_signs, "provider", l_obj_provider_sign);
json_object_object_add(l_obj_signs, "client", l_obj_client_sign);
json_object *l_exts_data = json_object_new_string_len((char *)a_receipt->exts_n_signs, a_receipt->exts_size);
if (!l_exts_data) {
json_object_put(l_obj_size);
json_object_put(l_obj_info);
json_object_put(l_obj_signs);
json_object_put(l_obj);
dap_json_rpc_allocation_error;
return NULL;
}
json_object_object_add(l_obj, "info", l_obj_info);
json_object_object_add(l_obj, "size", l_obj_size);
json_object_object_add(l_obj, "sings", l_obj_signs);
json_object_object_add(l_obj, "exts_data", l_exts_data);
return l_obj;
}
/*
* Authors:
* Alexey V. Stratulat <alexey.stratulat@demlabs.net>
* Olzhas Zharasbaev <oljas.jarasbaev@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk
* Copyright (c) 2017-2023
* All rights reserved.
This file is part of DAP (Demlabs Application Protocol) the open source project
DAP (Demlabs Application Protocol) 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/>.
*/
#pragma once
#include "dap_chain_common.h"
#include "dap_json_rpc_errors.h"
json_object *dap_chain_addr_to_json(const dap_chain_addr_t *a_addr);
DAP_STATIC_INLINE json_object *dap_chain_net_id_to_json(dap_chain_net_id_t a_net_id) {
return json_object_new_uint64(a_net_id.uint64);
}
/*
* Authors:
* Alexey V. Stratulat <alexey.stratulat@demlabs.net>
* Olzhas Zharasbaev <oljas.jarasbaev@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk
* Copyright (c) 2017-2023
* All rights reserved.
This file is part of DAP (Demlabs Application Protocol) the open source project
DAP (Demlabs Application Protocol) 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/>.
*/
#pragma once
#include "dap_chain_datum.h"
#include "dap_json_rpc_errors.h"
json_object * dap_chain_datum_to_json(dap_chain_datum_t* a_datum);
json_object * dap_chain_datum_data_to_json(dap_chain_datum_t *a_datum);
\ No newline at end of file
/*
* Authors:
* Alexey V. Stratulat <alexey.stratulat@demlabs.net>
* Olzhas Zharasbaev <oljas.jarasbaev@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk
* Copyright (c) 2017-2023
* All rights reserved.
This file is part of DAP (Demlabs Application Protocol) the open source project
DAP (Demlabs Application Protocol) 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/>.
*/
#pragma once
#include "dap_chain_datum_anchor.h"
#include "dap_json_rpc_errors.h"
json_object *dap_chain_datum_anchor_to_json(dap_chain_datum_anchor_t *a_anchor);
/*
* Authors:
* Alexey V. Stratulat <alexey.stratulat@demlabs.net>
* Olzhas Zharasbaev <oljas.jarasbaev@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://gitlab.demlabs.net/cellframe/cellframe-sdk
* Copyright (c) 2017-2023
* All rights reserved.
This file is part of DAP (Demlabs Application Protocol) the open source project
DAP (Demlabs Application Protocol) 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/>.
*/
#pragma once
#include "dap_chain_datum_decree.h"
#include "dap_json_rpc_errors.h"
/**
* @brief dap_chain_datum_decree_to_json Convert dap_chain_datum_decree_t tp json_object
* @param a_decree pointer to decree
* @return pointer json_object
*/
json_object *dap_chain_datum_decree_to_json(dap_chain_datum_decree_t *a_decree);