Skip to content

Commit

Permalink
Parsing simple transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
0xPxt committed Aug 8, 2024
1 parent f965061 commit b681832
Show file tree
Hide file tree
Showing 16 changed files with 1,612 additions and 107 deletions.
25 changes: 21 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,14 @@ add_definitions(
##{TODO}
##############################################################
# Static Libraries
file(GLOB_RECURSE LIB_SRC

file(GLOB_RECURSE BLAKE_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/BLAKE2/ref/blake2b-ref.c
)

file(GLOB_RECURSE LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/app_mode.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/base64.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/base58.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/bech32.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/bignum.c
Expand All @@ -141,18 +146,28 @@ file(GLOB_RECURSE LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_impl.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/crypto_helper.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/json/json_parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/jsmn/jsmn.c
)

add_library(app_lib STATIC ${LIB_SRC})
add_library(app_lib STATIC
${LIB_SRC}
${JSMN_SRC}
${BLAKE_SRC}
)

target_include_directories(app_lib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/deps/BLAKE2/ref
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/include
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
${CMAKE_CURRENT_SOURCE_DIR}/app/src/common
${CMAKE_CURRENT_SOURCE_DIR}/app/src/json
${CMAKE_CURRENT_SOURCE_DIR}/app/src/jsmn
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/app/common
)

target_link_libraries(app_lib PUBLIC)

##############################################################
# Fuzz Targets
if(ENABLE_FUZZING)
Expand All @@ -177,6 +192,8 @@ else()
${gmock_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
${CMAKE_CURRENT_SOURCE_DIR}/app/src/json
${CMAKE_CURRENT_SOURCE_DIR}/app/src/jsmn
)

target_link_libraries(unittests PRIVATE
Expand All @@ -188,4 +205,4 @@ else()
add_compile_definitions(TESTVECTORS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/")
add_test(NAME unittests COMMAND unittests)
set_tests_properties(unittests PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
endif()
endif()
4 changes: 2 additions & 2 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ $(info COIN = [$(COIN)])

ifeq ($(COIN),KDA)
# Main app configuration
APPNAME = "Kadena"
APPPATH = "44'/626'"
APPNAME = "Kadena-Led"
APPPATH = "44'/626'" --path "44'/1'"

else
define error_message
Expand Down
5 changes: 5 additions & 0 deletions app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ extern "C" {
#define APPVERSION_LINE1 "Kadena"
#define APPVERSION_LINE2 "v" APPVERSION

typedef enum {
tx_json = 0,
tx_textual
} tx_type_e;

#ifdef __cplusplus
}
#endif
26 changes: 16 additions & 10 deletions app/src/common/parser_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ extern "C" {
#include <stddef.h>
#include <stdint.h>

#include "parser_txdef.h"

#define CHECK_ERROR(__CALL) \
{ \
parser_error_t __err = __CALL; \
Expand Down Expand Up @@ -56,15 +54,23 @@ typedef enum {
parser_missing_field,
paser_unknown_transaction,
parser_tx_obj_empty,
} parser_error_t;

typedef struct {
const uint8_t *buffer;
uint16_t bufferLen;
uint16_t offset;
parser_tx_t *tx_obj;
} parser_context_t;
// Coin Specific
parser_json_zero_tokens,
parser_json_too_many_tokens, // "NOMEM: JSON string contains too many tokens"
parser_json_incomplete_json, // "JSON string is not complete";
// TODO : Clean these if never used
//parser_json_contains_whitespace,
//parser_json_is_not_sorted,
//parser_json_missing_chain_id,
//parser_json_missing_sequence,
//parser_json_missing_fee,
//parser_json_missing_msgs,
//parser_json_missing_account_number,
//parser_json_missing_memo,
parser_json_unexpected_error,
} parser_error_t;

#ifdef __cplusplus
}
#endif
#endif
Loading

1 comment on commit b681832

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format reports: 10 file(s) not formatted
  • app/src/parser_impl.c
  • app/src/parser.c
  • app/src/jsmn/jsmn.c
  • app/src/json/json_parser.c
  • app/src/coin.h
  • app/src/parser_txdef.h
  • app/src/parser_impl.h
  • app/src/jsmn/jsmn.h
  • app/src/common/parser_common.h
  • app/src/json/json_parser.h

Have any feedback or feature suggestions? Share it here.

Please sign in to comment.