This repository has been archived by the owner on Dec 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mam): Implement send_mam_res object
- Loading branch information
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "ta_send_mam_res.h" | ||
|
||
send_mam_res_t* send_mam_res_new() { | ||
send_mam_res_t* res = (send_mam_res_t*)malloc(sizeof(send_mam_res_t)); | ||
if (res) { | ||
res->bundle_hash = NULL; | ||
res->channel_id = NULL; | ||
} | ||
|
||
return res; | ||
} | ||
|
||
status_t send_mam_res_set_bundle_hash(send_mam_res_t* res, | ||
const tryte_t* bundle_hash) { | ||
if (res->bundle_hash || !bundle_hash) { | ||
return SC_RES_NULL; | ||
} | ||
|
||
size_t bundle_hash_size = NUM_TRYTES_ADDRESS * sizeof(char); | ||
res->bundle_hash = (char*)malloc(bundle_hash_size); | ||
if (!res->bundle_hash) { | ||
return SC_RES_OOM; | ||
} | ||
|
||
memcpy(res->bundle_hash, bundle_hash, bundle_hash_size); | ||
return SC_OK; | ||
} | ||
|
||
status_t send_mam_res_set_channel_id(send_mam_res_t* res, | ||
const tryte_t* channel_id) { | ||
if (res->channel_id || !channel_id) { | ||
return SC_RES_NULL; | ||
} | ||
|
||
size_t channel_id_size = NUM_TRYTES_ADDRESS * sizeof(char); | ||
res->channel_id = (char*)malloc(channel_id_size); | ||
if (!res->channel_id) { | ||
return SC_RES_OOM; | ||
} | ||
|
||
memcpy(res->channel_id, channel_id, channel_id_size); | ||
return SC_OK; | ||
} | ||
|
||
void send_mam_res_free(send_mam_res_t** res) { | ||
if (!res || !(*res)) { | ||
return; | ||
} | ||
if ((*res)->bundle_hash) { | ||
free((*res)->bundle_hash); | ||
(*res)->bundle_hash = NULL; | ||
} | ||
if ((*res)->channel_id) { | ||
free((*res)->channel_id); | ||
(*res)->channel_id = NULL; | ||
} | ||
|
||
free(*res); | ||
*res = NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#ifndef RESPONSE_TA_SEND_MAM_RES_H_ | ||
#define RESPONSE_TA_SEND_MAM_RES_H_ | ||
|
||
#include "accelerator/errors.h" | ||
#include "common/model/transaction.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @file response/ta_send_mam_res.h | ||
*/ | ||
|
||
/** struct of ta_send_mam_res_t */ | ||
typedef struct send_mam_res_s { | ||
/** ascii string bundle hash */ | ||
char* bundle_hash; | ||
/** ascii string channel id */ | ||
char* channel_id; | ||
} send_mam_res_t; | ||
|
||
/** | ||
* Allocate memory of send_mam_res_t | ||
* | ||
* @return | ||
* - struct of send_mam_res_t on success | ||
* - NULL on error | ||
*/ | ||
send_mam_res_t* send_mam_res_new(); | ||
|
||
/** | ||
* @brief Set the bundle_hash field of send_mam_res object. | ||
* | ||
* Receive a bundle hash tryte_t array which is 81 trytes long, | ||
* and convert (instead of decoding) the received bundle hash to ascii string. | ||
* After conversion, set the bundle_hash field of send_mam_res object. | ||
* | ||
* @param[in] res send_mam_res_t struct object | ||
* @param[in] bundle_hash bundle hash decoded in trytes string | ||
* | ||
* @return | ||
* - SC_OK on success | ||
* - non-zero on error | ||
*/ | ||
status_t send_mam_res_set_bundle_hash(send_mam_res_t* res, | ||
const tryte_t* bundle_hash); | ||
|
||
/** | ||
* @brief Set the channel_id field of send_mam_res object. | ||
* | ||
* Receive a channel id tryte_t array which is 81 trytes long, | ||
* and convert (instead of decoding) the received channel id to ascii string. | ||
* After conversion, set the channel_id field of send_mam_res object. | ||
* | ||
* @param[in] res send_mam_res_t struct object | ||
* @param[in] channel_id channel id decoded in trytes string | ||
* | ||
* @return | ||
* - SC_OK on success | ||
* - non-zero on error | ||
*/ | ||
status_t send_mam_res_set_channel_id(send_mam_res_t* res, | ||
const tryte_t* channel_id); | ||
|
||
/** | ||
* Free memory of send_mam_res_t | ||
* | ||
* @param req Data type of send_mam_res_t | ||
* | ||
* @return NULL | ||
*/ | ||
void send_mam_res_free(send_mam_res_t** res); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // RESPONSE_TA_SEND_MAM_RES_H_ |