Skip to content

Commit

Permalink
wip print parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
abenso committed Dec 3, 2024
1 parent d9f5885 commit a41f8aa
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 59 deletions.
29 changes: 11 additions & 18 deletions app/src/parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
* limitations under the License.
********************************************************************************/

#include "note.h"
#include "parser_impl.h"
#include "parser_interface.h"
#include "parser_pb_utils.h"
#include "pb_common.h"
#include "pb_decode.h"
#include "protobuf/penumbra/core/transaction/v1/transaction.pb.h"
#include "zxformat.h"
#include "ui_utils.h"
#include "note.h"
#include "zxformat.h"

parser_error_t decode_parameters(const bytes_t *data,
const penumbra_core_transaction_v1_TransactionParameters *transaction_parameters,
Expand Down Expand Up @@ -52,38 +51,32 @@ parser_error_t parameters_getNumItems(const parser_context_t *ctx, uint8_t *num_
return parser_ok;
}

parser_error_t parameters_getItem(const parser_context_t *ctx, const parameters_t *parameters,
uint8_t displayIdx, char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen, uint8_t pageIdx,
uint8_t *pageCount) {

parser_error_t parameters_getItem(const parser_context_t *ctx, uint8_t displayIdx, char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen, uint8_t pageIdx, uint8_t *pageCount) {
parser_error_t err = parser_no_data;
if (parameters == NULL || outKey == NULL || outVal == NULL || outKeyLen == 0 || outValLen == 0) {
if (ctx == NULL || outKey == NULL || outVal == NULL || outKeyLen == 0 || outValLen == 0) {
return err;
}


switch ( displayIdx ) {
switch (displayIdx) {
case 0:
snprintf(outKey, outKeyLen, "Chain ID");
char print[200] = {0};
array_to_hexstr(print, sizeof(print), parameters->chain_id.ptr, parameters->chain_id.len);
pageString(outVal, outValLen, print, pageIdx, pageCount);
pageStringExt(outVal, outValLen, (char *)ctx->tx_obj->parameters_plan.chain_id.ptr, ctx->tx_obj->parameters_plan.chain_id.len, pageIdx, pageCount);
return parser_ok;
case 1:
snprintf(outKey, outKeyLen, "Expiry Height");
snprintf(outKey, outKeyLen, "Expiry height");
char bufferUI[200] = {0};
if (uint64_to_str(bufferUI, sizeof(bufferUI), parameters->expiry_height) != NULL) {
if (uint64_to_str(bufferUI, sizeof(bufferUI), ctx->tx_obj->parameters_plan.expiry_height) != NULL) {
return parser_unexpected_value;
}
pageString(outVal, outValLen, bufferUI, pageIdx, pageCount);
return parser_ok;
case 2:
snprintf(outKey, outKeyLen, "Fee");
return printValue(ctx, &parameters->fee, outVal, outValLen);
snprintf(outVal, outValLen, "TODO");
return parser_ok; //printValue(ctx, &ctx->tx_obj->parameters_plan.fee, outVal, outValLen);
default:
return parser_no_data;
}
return parser_ok;

}
6 changes: 6 additions & 0 deletions app/src/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "pb_common.h"
#include "pb_decode.h"
#include "zxtypes.h"
#include "protobuf/penumbra/core/transaction/v1/transaction.pb.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -34,6 +35,11 @@ parser_error_t decode_parameters(const bytes_t *data,
const penumbra_core_transaction_v1_TransactionParameters *transaction_parameters,
parameters_t *parameters);

parser_error_t parameters_getNumItems(const parser_context_t *ctx, uint8_t *num_items);
parser_error_t parameters_getItem(const parser_context_t *ctx, uint8_t displayIdx, char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen, uint8_t pageIdx,
uint8_t *pageCount);

#ifdef __cplusplus
}
#endif
30 changes: 8 additions & 22 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "parser_common.h"
#include "parser_impl.h"
#include "tx_metadata.h"
#include "parameters.h"

parser_error_t parser_init_context(parser_context_t *ctx, const uint8_t *buffer, uint16_t bufferSize) {
ctx->offset = 0;
Expand Down Expand Up @@ -64,10 +65,11 @@ parser_error_t parser_validate(parser_context_t *ctx) {
}

parser_error_t parser_getNumItems(const parser_context_t *ctx, uint8_t *num_items) {
// #{TODO} --> function to retrieve num Items
// *num_items = _getNumItems();
UNUSED(ctx);
*num_items = 1;

uint8_t parameters_num_items = 0;
CHECK_ERROR(parameters_getNumItems(ctx, &parameters_num_items))
*num_items = parameters_num_items;
if (*num_items == 0) {
return parser_unexpected_number_items;
}
Expand Down Expand Up @@ -99,27 +101,11 @@ parser_error_t parser_getItem(const parser_context_t *ctx, uint8_t displayIdx, c
CHECK_ERROR(checkSanity(numItems, displayIdx))
cleanOutput(outKey, outKeyLen, outVal, outValLen);

switch (displayIdx) {
case 0:
// Display Item 0
snprintf(outKey, outKeyLen, "Title #0");
snprintf(outVal, outValLen, "Value #0");
return parser_ok;
case 1:
// Display Item 1
snprintf(outKey, outKeyLen, "Title #1");
snprintf(outVal, outValLen, "Value #1");
return parser_ok;
case 10:
// Display Item 10
snprintf(outKey, outKeyLen, "Title #N");
snprintf(outVal, outValLen, "Value #N");
return parser_ok;
default:
break;
if (displayIdx < 3) {
CHECK_ERROR(parameters_getItem(ctx, displayIdx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
}

return parser_display_idx_out_of_range;
return parser_ok;
}

parser_error_t parser_parseTxMetadata(const uint8_t *data, size_t dataLen, tx_metadata_t *metadata, uint8_t metadataLen) {
Expand Down
1 change: 1 addition & 0 deletions app/src/ui/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
#include "parser_common.h"

#pragma once
#ifdef __cplusplus
Expand Down
26 changes: 7 additions & 19 deletions tests/testcases.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
[
{
"blob": "0a94021291020a330a0d08e2e9fe9ed0b0eef5e401101812220a2029ea9c2f3371f6a487e7e95c247041f4a356f983eb064e5d2b3bcf322ca96a1012520a50b11ae50bc74e409feeb9674076c5a9cb04361b16ab6d70692c5b140e92d72a4d7b68b94e3225f577ebcd504554aaa4334277b35d80bb0a6339e2e34702a586acd27088076457b8d65b6b43d424ffd8b81a2038c12ab558bd7b9eaed0cbefa33dbc8a7256985d9d9b8806ddffd6aa8c55ca9a2220d83ee341cc5f2dc216ad1879dca72fe7f28b492522e81a697062fe9fb5d9a9042a20c19e3ddfb3eb28af76fc3dc37eb18a6479ac1f415340f25a7686b442c30d6e113220239e937ecd3e047697047aec7a418a4ef2cce3eaebf5cf6be2721775f7b5a20e123b08ce88e8e00a1222757a7878746f686d65776d6a7a626f76647672696e6e6a71712d39323533373730331a0f0a0d08e5adf4f1bbc8f1f01a10a501",
"blob": "0a95021292020a340a0e08bde98790d8f6fcf7880110e10212220a2029ea9c2f3371f6a487e7e95c247041f4a356f983eb064e5d2b3bcf322ca96a1012520a505e975ea7e68e16d9ba24563d40b14e6008c6f66a69aa1afa23319d924fd7a2215faee380e86b8626b2cbbec6227ae9700b9c52ad80463d98760c4012601d9d375d7dd0e093e9369a34c14c43cb93edde1a204a90e0f8f8a1792a7db9cc05645c30b5161e48d7096ca9f1fcac60d2f9ec6c9e22205b7b44376c60a11f5cb4a34b629724680373eda24cf24b9eae1a79f2955b0e042a20f00c946bdddb662817d26bb83bdf46248cbb91ebd332531bf5f065d6c562460c32208b8facc970998e87d6491c89597246a16c437c90e2fb492574d7ff503b6b600e123c08d79cd5881b12237766776e736a7679747a6a626a63702d343730363136313838393833323732393337311a0f0a0d08bdcdd6dcf9ea99e646108102",
"index": 0,
"name": "Output_0",
"output": [
"0 | Chain ID : uzxxtohmewmjzbovdvrinnjqq-9253",
"1 | Chain ID : 7703",
"2 | Expiry height : 2887386190",
"3 | Fee: 3045649819471078823653",
"4 | Memo : None",
"5 | Delegation : None",
"6 | Output : 459217339810150593762",
"7 | To : penumbra1kydw2z78feqflm4evaq8d",
"8 | To : 3df…"
"0 | Chain ID : wfwnsjvytzjbjcp-4706161889832729371",
"1 | Expiry height : 7265930839",
"2 | Fee : TODO"
],
"output_expert": [
"0 | Chain ID : uzxxtohmewmjzbovdvrinnjqq-9253",
"1 | Chain ID : 7703",
"2 | Expiry height : 2887386190",
"3 | Fee: 3045649819471078823653",
"4 | Memo : None",
"5 | Delegation : None",
"6 | Output : 459217339810150593762",
"7 | To : penumbra1kydw2z78feqflm4evaq8d",
"8 | To : 3df…"
"0 | Chain ID : wfwnsjvytzjbjcp-4706161889832729371",
"1 | Expiry height : 7265930839",
"2 | Fee : TODO"
]
}
]

0 comments on commit a41f8aa

Please sign in to comment.