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

Commit

Permalink
feat: Synchronize with entangled
Browse files Browse the repository at this point in the history
ze entangled to latest commit, and replace the implementationof `cclient_prepare_transfer()`
into entangled provided exteneded API `iota_client_prepare_transfers()`.

In the latest, the iota defined variable types should be included
respectively (not like what we did before).

And the `mam_api_bundle_write_header_on_channel()` has removed one argument.
  • Loading branch information
howjmay committed Jun 7, 2019
1 parent 4082ee9 commit 0da88e4
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 69 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ load("//third_party:third_party.bzl", "third_party_deps")

git_repository(
name = "rules_iota",
commit = "4ea411a05b38633a8d6b13c2d4d520441aeda9dd",
commit = "8a302aaeba60b9eb38f6500d48249b8cbba16c73",
remote = "https://github.com/iotaledger/rules_iota.git",
)

git_repository(
name = "entangled",
commit = "4960865730640d23e75ffbce84d3f74264cfcd28",
commit = "6ad56514a8a13fb1bf01beb10934cb9e3fd1a8a4",
remote = "https://github.com/iotaledger/entangled.git",
)

Expand Down
2 changes: 1 addition & 1 deletion accelerator/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ cc_library(
":common_core",
":ta_errors",
"//serializer",
"@entangled//common/model:bundle",
"@entangled//common/trinary:trit_tryte",
"@entangled//mam/api",
],
Expand Down Expand Up @@ -62,7 +63,6 @@ cc_library(
"//utils:cache",
"//utils:pow",
"@entangled//cclient/api",
"@entangled//cclient/types",
],
)

Expand Down
2 changes: 1 addition & 1 deletion accelerator/apis.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ status_t api_mam_send_message(const iota_config_t* const tangle,
}

// Write header and packet
if (mam_api_bundle_write_header_on_channel(&mam, channel_id, NULL, NULL, 0,
if (mam_api_bundle_write_header_on_channel(&mam, channel_id, NULL, NULL,
bundle, msg_id) != RC_OK) {
ret = SC_MAM_FAILED_WRITE;
goto done;
Expand Down
2 changes: 1 addition & 1 deletion accelerator/apis.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "accelerator/common_core.h"
#include "accelerator/errors.h"
#include "cclient/types/types.h"
#include "common/model/bundle.h"
#include "common/trinary/trit_tryte.h"
#include "mam/api/api.h"
#include "mam/mam/mam_channel_t_set.h"
Expand Down
77 changes: 33 additions & 44 deletions accelerator/common_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,42 +68,6 @@ status_t cclient_get_tips(const iota_client_service_t* const service,
return ret;
}

status_t cclient_prepare_transfer(const iota_client_service_t* const service,
transfer_t** const transfers,
uint32_t const num_transfer,
bundle_transactions_t* out_bundle) {
if (transfers == NULL || out_bundle == NULL) {
return SC_TA_NULL;
}

status_t ret = SC_OK;
iota_transaction_t* TX = transaction_new();
iota_transaction_t* tx = NULL;
Kerl kerl = {};
transfer_ctx_t transfer_ctx = {};
transfer_iterator_t* transfer_iterator =
transfer_iterator_new(transfers, num_transfer, &kerl, TX);
if (transfer_iterator == NULL) {
ret = SC_CCLIENT_OOM;
goto done;
}

// calculate bundle hash
transfer_ctx_init(&transfer_ctx, transfers, 1);
transfer_ctx_hash(&transfer_ctx, &kerl, transfers, 1);

for (tx = transfer_iterator_next(transfer_iterator); tx;
tx = transfer_iterator_next(transfer_iterator)) {
transaction_set_bundle(tx, transfer_ctx.bundle);
bundle_transactions_add(out_bundle, tx);
}

done:
transfer_iterator_free(&transfer_iterator);
transaction_free(TX);
return ret;
}

status_t ta_attach_to_tangle(const attach_to_tangle_req_t* const req,
attach_to_tangle_res_t* res) {
status_t ret = SC_OK;
Expand Down Expand Up @@ -251,17 +215,41 @@ status_t ta_send_transfer(const iota_config_t* const tangle,
iota_transaction_t* txn = NULL;
bundle_transactions_t* out_bundle = NULL;
bundle_transactions_new(&out_bundle);
transfer_t* transfers[1];
transfers[0] = transfer_data_new(hash243_queue_peek(req->address),
hash81_queue_peek(req->tag), req->message,
req->msg_len, current_timestamp_ms());
if (find_tx_req == NULL || find_tx_res == NULL) {
transfer_array_t* transfers = transfer_array_new();
if (find_tx_req == NULL || find_tx_res == NULL || transfers == NULL) {
ret = SC_CCLIENT_OOM;
goto done;
}

ret = cclient_prepare_transfer(service, transfers, 1, out_bundle);
if (ret) {
// TODO Maybe we can replace the variable type of message from flex_trit_t to
// tryte_t
tryte_t msg_tryte[NUM_TRYTES_SERIALIZED_TRANSACTION];
flex_trits_to_trytes(msg_tryte, req->msg_len / 3, req->message, req->msg_len,
req->msg_len);

transfer_t transfer = {.value = 0,
.timestamp = current_timestamp_ms(),
.msg_len = req->msg_len / 3};

if (transfer_message_set_trytes(&transfer, msg_tryte, transfer.msg_len) !=
RC_OK) {
ret = SC_CCLIENT_OOM;
goto done;
}
memcpy(transfer.address, hash243_queue_peek(req->address),
FLEX_TRIT_SIZE_243);
memcpy(transfer.tag, hash81_queue_peek(req->tag), FLEX_TRIT_SIZE_81);
transfer_array_add(transfers, &transfer);

// TODO we may need args `remainder_address`, `inputs`, `timestampe` in the
// future and declare `security` field in `iota_config_t`
flex_trit_t seed[NUM_FLEX_TRITS_ADDRESS];
flex_trits_from_trytes(seed, NUM_TRITS_HASH, (tryte_t const*)tangle->seed,
NUM_TRYTES_HASH, NUM_TRYTES_HASH);
if (iota_client_prepare_transfers(service, seed, 2, transfers, NULL, NULL,
false, current_timestamp_ms(),
out_bundle) != RC_OK) {
ret = SC_CCLIENT_FAILED_RESPONSE;
goto done;
}

Expand Down Expand Up @@ -297,8 +285,9 @@ status_t ta_send_transfer(const iota_config_t* const tangle,
find_tx_res->hashes = NULL;

done:
transfer_message_free(&transfer);
hash_array_free(raw_tx);
transfer_free(transfers);
transfer_array_free(transfers);
bundle_transactions_free(&out_bundle);
find_transactions_req_free(&find_tx_req);
find_transactions_res_free(&find_tx_res);
Expand Down
1 change: 0 additions & 1 deletion accelerator/common_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define ACCELERATOR_COMMON_CORE_H_

#include "accelerator/config.h"
#include "common/model/bundle.h"
#include "common/model/transfer.h"
#include "request/request.h"
#include "response/response.h"
Expand Down
1 change: 0 additions & 1 deletion accelerator/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "accelerator/message.h"
#include "cclient/api/core/core_api.h"
#include "cclient/api/extended/extended_api.h"
#include "cclient/types/types.h"
#include "utils/cache.h"
#include "utils/pow.h"

Expand Down
7 changes: 6 additions & 1 deletion request/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
"//accelerator:ta_errors",
"@entangled//cclient/types",
"@entangled//common:errors",
"@entangled//common/model:transaction",
"@entangled//common/trinary:tryte",
"@entangled//utils/containers/hash:hash243_queue",
"@entangled//utils/containers/hash:hash81_queue",
"@entangled//utils/containers/hash:hash_array",
],
)
4 changes: 3 additions & 1 deletion request/ta_send_mam.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#ifndef REQUEST_TA_SEND_MAM_H_
#define REQUEST_TA_SEND_MAM_H_

#include <stdlib.h>
#include <string.h>
#include "accelerator/errors.h"
#include "cclient/types/types.h"
#include "common/trinary/tryte.h"

#ifdef __cplusplus
extern "C" {
Expand Down
5 changes: 4 additions & 1 deletion request/ta_send_transfer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#ifndef REQUEST_TA_SEND_TRANSFER_H_
#define REQUEST_TA_SEND_TRANSFER_H_

#include "cclient/types/types.h"
#include <stdlib.h>
#include "common/trinary/flex_trit.h"
#include "utils/containers/hash/hash243_queue.h"
#include "utils/containers/hash/hash81_queue.h"

#ifdef __cplusplus
extern "C" {
Expand Down
6 changes: 5 additions & 1 deletion response/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
"//accelerator:ta_errors",
"@entangled//cclient/types",
"@entangled//common:errors",
"@entangled//common/model:transaction",
"@entangled//utils/containers/hash:hash243_queue",
"@entangled//utils/containers/hash:hash243_stack",
"@entangled//utils/containers/hash:hash8019_queue",
"@entangled//utils/containers/hash:hash_array",
],
)
3 changes: 2 additions & 1 deletion response/ta_find_transactions.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef RESPONSE_TA_FIND_TRANSACTIONS_H_
#define RESPONSE_TA_FIND_TRANSACTIONS_H_

#include "cclient/types/types.h"
#include <stdlib.h>
#include "utils/containers/hash/hash243_queue.h"

#ifdef __cplusplus
extern "C" {
Expand Down
3 changes: 2 additions & 1 deletion response/ta_find_transactions_obj.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef RESPONSE_TA_FIND_TRANSACTIONS_OBJ_H_
#define RESPONSE_TA_FIND_TRANSACTIONS_OBJ_H_

#include "cclient/types/types.h"
#include "./utarray.h"
#include "common/model/transaction.h"

#ifdef __cplusplus
extern "C" {
Expand Down
3 changes: 2 additions & 1 deletion response/ta_generate_address.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef RESPONSE_TA_GENERATE_ADDRESS_H_
#define RESPONSE_TA_GENERATE_ADDRESS_H_

#include "cclient/types/types.h"
#include <stdlib.h>
#include "utils/containers/hash/hash243_queue.h"

#ifdef __cplusplus
extern "C" {
Expand Down
3 changes: 2 additions & 1 deletion response/ta_get_tips.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef RESPONSE_TA_GET_TIPS_H_
#define RESPONSE_TA_GET_TIPS_H_

#include "cclient/types/types.h"
#include <stdlib.h>
#include "utils/containers/hash/hash243_stack.h"

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion response/ta_get_transaction_object.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef RESPONSE_TA_GET_TRANSACTION_OBJECT_H_
#define RESPONSE_TA_GET_TRANSACTION_OBJECT_H_

#include "cclient/types/types.h"
#include "common/model/transaction.h"

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions response/ta_send_mam.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "accelerator/errors.h"
#include "common/model/transaction.h"
#include "common/trinary/tryte.h"

#ifdef __cplusplus
extern "C" {
Expand Down
3 changes: 2 additions & 1 deletion response/ta_send_transfer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef RESPONSE_TA_SEND_TRANSFER_H_
#define RESPONSE_TA_SEND_TRANSFER_H_

#include "cclient/types/types.h"
#include <stdlib.h>
#include "utils/containers/hash/hash243_queue.h"

#ifdef __cplusplus
extern "C" {
Expand Down
6 changes: 5 additions & 1 deletion serializer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ cc_library(
"//response",
"//utils:fill_nines",
"@cJSON",
"@entangled//cclient/types",
"@entangled//common/trinary:flex_trit",
"@entangled//common/trinary:tryte_ascii",
"@entangled//utils/containers/hash:hash243_queue",
"@entangled//utils/containers/hash:hash243_stack",
"@entangled//utils/containers/hash:hash81_queue",
"@entangled//utils/containers/hash:hash_array",
],
)
7 changes: 6 additions & 1 deletion serializer/serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@

#include "accelerator/errors.h"
#include "cJSON.h"
#include "cclient/types/types.h"
#include "common/trinary/flex_trit.h"
#include "common/trinary/tryte_ascii.h"
#include "request/request.h"
#include "response/response.h"
#include "utarray.h"
#include "utils/containers/hash/hash243_queue.h"
#include "utils/containers/hash/hash243_stack.h"
#include "utils/containers/hash/hash81_queue.h"
#include "utils/containers/hash/hash_array.h"
#include "utils/fill_nines.h"

#ifdef __cplusplus
Expand Down
7 changes: 4 additions & 3 deletions utils/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cc_library(
hdrs = ["cache.h"],
deps = [
"//accelerator:ta_errors",
"@entangled//cclient/types",
"@entangled//common/trinary:flex_trit",
"@hiredis",
],
)
Expand All @@ -18,9 +18,10 @@ cc_library(
deps = [
"//accelerator:ta_errors",
"//third_party:dcurl",
"@entangled//cclient/types",
"@com_github_uthash//:uthash",
"@entangled//common/helpers:digest",
"@entangled//common/model:bundle",
"@entangled//common/trinary:flex_trit",
"@entangled//utils:time",
],
)
Expand All @@ -31,6 +32,6 @@ cc_library(
hdrs = ["fill_nines.h"],
deps = [
"//accelerator:ta_errors",
"@entangled//cclient/types",
"@entangled//common/model:transaction",
],
)
4 changes: 3 additions & 1 deletion utils/cache.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#ifndef UTILS_CACHE_H_
#define UTILS_CACHE_H_

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "common/trinary/flex_trit.h"

#include "accelerator/errors.h"
#include "cclient/types/types.h"

#ifdef __cplusplus
extern "C" {
Expand Down
5 changes: 4 additions & 1 deletion utils/fill_nines.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#ifndef UTILS_FILL_NINES_H_
#define UTILS_FILL_NINES_H_

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "accelerator/errors.h"
#include "cclient/types/types.h"
#include "common/model/transaction.h"

#ifdef __cplusplus
extern "C" {
Expand Down
3 changes: 2 additions & 1 deletion utils/pow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#define UTILS_POW_H_

#include <stdint.h>
#include "./utarray.h"
#include "accelerator/errors.h"
#include "cclient/types/types.h"
#include "common/model/bundle.h"
#include "common/trinary/flex_trit.h"

#ifdef __cplusplus
extern "C" {
Expand Down

0 comments on commit 0da88e4

Please sign in to comment.