Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
feat(api): Implement IRI Proxy API
Browse files Browse the repository at this point in the history
  • Loading branch information
yiwei01 committed Oct 11, 2019
1 parent afff715 commit e900bf5
Show file tree
Hide file tree
Showing 7 changed files with 537 additions and 65 deletions.
16 changes: 16 additions & 0 deletions accelerator/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cc_binary(
copts = ["-DLOGGER_ENABLE"],
deps = [
":apis",
":proxy_apis",
":ta_config",
":ta_errors",
"@served",
Expand Down Expand Up @@ -80,13 +81,28 @@ cc_library(
],
)

cc_library(
name = "proxy_apis",
srcs = ["proxy_apis.c"],
hdrs = ["proxy_apis.h"],
visibility = ["//visibility:public"],
deps = [
":ta_errors",
"@entangled//cclient/api",
"@entangled//cclient/request:requests",
"@entangled//cclient/response:responses",
"@entangled//utils:logger_helper",
],
)

cc_library(
name = "http",
srcs = ["http.c"],
hdrs = ["http.h"],
visibility = ["//visibility:public"],
deps = [
":apis",
":proxy_apis",
":ta_config",
":ta_errors",
"@libmicrohttpd",
Expand Down
49 changes: 0 additions & 49 deletions accelerator/apis.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,55 +154,6 @@ status_t api_generate_address(const iota_config_t* const iconf, const iota_clien
return ret;
}

status_t api_find_transactions(const iota_client_service_t* const service, const char* const obj, char** json_result) {
status_t ret = SC_OK;
find_transactions_req_t* req = find_transactions_req_new();
find_transactions_res_t* res = find_transactions_res_new();
char_buffer_t* res_buff = char_buffer_new();
if (req == NULL || res == NULL || res_buff == NULL) {
ret = SC_TA_OOM;
ta_log_error("%s\n", "SC_TA_OOM");
goto done;
}
lock_handle_lock(&cjson_lock);
if (service->serializer.vtable.find_transactions_deserialize_request(obj, req) != RC_OK) {
lock_handle_unlock(&cjson_lock);
ret = SC_CCLIENT_JSON_PARSE;
ta_log_error("%s\n", "SC_CCLIENT_JSON_PARSE");
goto done;
}
lock_handle_unlock(&cjson_lock);

lock_handle_lock(&cjson_lock);
if (iota_client_find_transactions(service, req, res) != RC_OK) {
lock_handle_unlock(&cjson_lock);
ret = SC_CCLIENT_FAILED_RESPONSE;
ta_log_error("%s\n", "SC_CCLIENT_FAILED_RESPONSE");
goto done;
}
lock_handle_unlock(&cjson_lock);

if (service->serializer.vtable.find_transactions_serialize_response(res, res_buff) != RC_OK) {
ret = SC_CCLIENT_JSON_PARSE;
ta_log_error("%s\n", "SC_CCLIENT_JSON_PARSE");
goto done;
}

*json_result = (char*)malloc((res_buff->length + 1) * sizeof(char));
if (*json_result == NULL) {
ret = SC_CCLIENT_JSON_PARSE;
ta_log_error("%s\n", "SC_CCLIENT_JSON_PARSE");
goto done;
}
snprintf(*json_result, (res_buff->length + 1), "%s", res_buff->data);

done:
find_transactions_req_free(&req);
find_transactions_res_free(&res);
char_buffer_free(res_buff);
return ret;
}

status_t api_find_transaction_object_single(const iota_client_service_t* const service, const char* const obj,
char** json_result) {
status_t ret = SC_OK;
Expand Down
16 changes: 0 additions & 16 deletions accelerator/apis.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,6 @@ status_t api_mam_send_message(const iota_config_t* const iconf, const iota_clien
status_t api_send_transfer(const iota_config_t* const iconf, const iota_client_service_t* const service,
const char* const obj, char** json_result);

/**
* @brief Return transaction hashes with given information such as bundle hashes, addresses, tags, or approvees.
*
* Explore transaction hash with given transaction related information. This would
* return a list of transaction hashes in json format.
*
* @param[in] service IRI node end point service
* @param[in] obj bundle hashes, addresses, tags, or approvees.
* @param[out] json_result Result containing transaction objects in json format
*
* @return
* - SC_OK on success
* - non-zero on error
*/
status_t api_find_transactions(const iota_client_service_t* const service, const char* const obj, char** json_result);

/**
* @brief Return transaction object with given single transaction hash.
*
Expand Down
1 change: 1 addition & 0 deletions accelerator/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "accelerator/apis.h"
#include "accelerator/config.h"
#include "accelerator/errors.h"
#include "accelerator/proxy_apis.h"

#ifdef __cplusplus
extern "C" {
Expand Down
Loading

0 comments on commit e900bf5

Please sign in to comment.