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

Commit eb36842

Browse files
author
Yu Wei Wu
committed
feat(core): add send_transfer cache
Send_transfer would now cache transaction infos to cache. When performing attach_to_tangle, raw transaction trytes would store as value to cache, then find_transaction action will search transaction directly through memory after broadcast_and_store. Resolve #78
1 parent 6c2c92f commit eb36842

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

accelerator/common_core.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,27 @@ status_t ta_attach_to_tangle(const attach_to_tangle_req_t* const req,
111111
bundle_transactions_t* bundle = NULL;
112112
iota_transaction_t tx;
113113
flex_trit_t* elt = NULL;
114+
char cache_key[NUM_TRYTES_HASH] = {0};
115+
char cache_value[NUM_TRYTES_SERIALIZED_TRANSACTION] = {0};
116+
cache_t* cache = cache_init();
114117
pow_init();
115118

116119
// create bundle
117120
bundle_transactions_new(&bundle);
118121
HASH_ARRAY_FOREACH(req->trytes, elt) {
119-
transaction_deserialize_from_trits(&tx, elt, false);
122+
transaction_deserialize_from_trits(&tx, elt, true);
120123
bundle_transactions_add(bundle, &tx);
124+
125+
// store transaction to cache
126+
flex_trits_to_trytes((tryte_t*)cache_key, NUM_TRYTES_HASH,
127+
transaction_hash(&tx), NUM_TRITS_HASH, NUM_TRITS_HASH);
128+
flex_trits_to_trytes(
129+
(tryte_t*)cache_value, NUM_TRYTES_SERIALIZED_TRANSACTION, elt,
130+
NUM_TRITS_SERIALIZED_TRANSACTION, NUM_TRITS_SERIALIZED_TRANSACTION);
131+
ret = cache_set(cache, cache_key, cache_value);
132+
if (ret) {
133+
goto done;
134+
}
121135
}
122136

123137
// PoW to bundle
@@ -141,6 +155,7 @@ status_t ta_attach_to_tangle(const attach_to_tangle_req_t* const req,
141155
}
142156

143157
done:
158+
cache_stop(&cache);
144159
pow_destroy();
145160
bundle_transactions_free(&bundle);
146161
return ret;

0 commit comments

Comments
 (0)