1010#include <stdlib.h>
1111#include "common/model/transaction.h"
1212#include "utils/files.h"
13+ #include "utils/logger_helper.h"
1314#include "utils/macros.h"
1415
16+ #define SNAPSHOT_METADATA_LOGGER_ID "snapshot_metadata"
17+
18+ static logger_id_t logger_id ;
19+
1520retcode_t iota_snapshot_metadata_init (snapshot_metadata_t * const snapshot_metadata , flex_trit_t const * const hash ,
1621 uint64_t index , uint64_t timestamp , hash_to_uint64_t_map_t solid_entry_points ) {
1722 memcpy (snapshot_metadata -> hash , hash , FLEX_TRIT_SIZE_243 );
1823 snapshot_metadata -> index = index ;
1924 snapshot_metadata -> timestamp = timestamp ;
2025 snapshot_metadata -> solid_entry_points = NULL ;
2126 hash_to_uint64_t_map_copy (& solid_entry_points , & snapshot_metadata -> solid_entry_points );
27+ logger_id = logger_helper_enable (SNAPSHOT_METADATA_LOGGER_ID , LOGGER_DEBUG , true);
2228 return RC_OK ;
2329}
2430
@@ -30,6 +36,7 @@ void iota_snapshot_metadata_reset(snapshot_metadata_t *const snapshot_metadata)
3036
3137retcode_t iota_snapshot_metadata_destroy (snapshot_metadata_t * const snapshot_metadata ) {
3238 hash_to_uint64_t_map_free (& snapshot_metadata -> solid_entry_points );
39+ logger_helper_release (logger_id );
3340 return RC_OK ;
3441}
3542
@@ -146,9 +153,15 @@ retcode_t iota_snapshot_metadata_read_from_file(snapshot_metadata_t *const snaps
146153 retcode_t ret = RC_OK ;
147154 char * buffer = NULL ;
148155
149- ERR_BIND_GOTO (iota_utils_read_file_into_buffer (metadata_file , & buffer ), ret , cleanup );
156+ if ((ret = iota_utils_read_file_into_buffer (metadata_file , & buffer )) != RC_OK ) {
157+ log_error (logger_id , "Failed reading metadata file\n" );
158+ goto cleanup ;
159+ }
150160 if (buffer ) {
151- ERR_BIND_GOTO (iota_snapshot_metadata_deserialize_str (buffer , snapshot_metadata ), ret , cleanup );
161+ if ((ret = iota_snapshot_metadata_deserialize_str (buffer , snapshot_metadata )) != RC_OK ) {
162+ log_error (logger_id , "Failed deserializing metadata file\n" );
163+ goto cleanup ;
164+ }
152165 }
153166
154167cleanup :
0 commit comments