Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Mar 8, 2024
1 parent b4f6819 commit 7e19c3d
Show file tree
Hide file tree
Showing 4 changed files with 9,018 additions and 363 deletions.
10 changes: 1 addition & 9 deletions app/src/eth_erc20.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const erc20_tokens_t supportedTokens[] = {
18},
{{0x02, 0xf0, 0x82, 0x6e, 0xf6, 0xad, 0x10, 0x7c, 0xfc, 0x86,
0x11, 0x52, 0xb3, 0x2b, 0x52, 0xfd, 0x11, 0xba, 0xb9, 0xed},
"WSBG ",
"WSGB ",
18},

};
Expand All @@ -40,14 +40,6 @@ parser_error_t getERC20Token(const eth_tx_t *ethObj, char tokenSymbol[MAX_SYMBOL
return parser_unexpected_value;
}

// Verify address contract: first 12 bytes must be 0
const uint8_t *addressPtr = ethObj->legacy.data.ptr + 4;
for (uint8_t i = 0; i < 12; i++) {
if (*(addressPtr++) != 0) {
return parser_unexpected_value;
}
}

// Check if token is in the list
const uint8_t supportedTokensSize = sizeof(supportedTokens) / sizeof(supportedTokens[0]);
for (uint8_t i = 0; i < supportedTokensSize; i++) {
Expand Down
9 changes: 6 additions & 3 deletions app/src/parser_impl_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ static parser_error_t printTxHash(const parser_context_t *ctx, char *outKey, uin
snprintf(outKey, outKeyLen, "Tx Hash");

pageString(outVal, outValLen, hex, pageIdx, pageCount);

return parser_ok;
}

static parser_error_t printERC20(const parser_context_t *ctx, uint8_t displayIdx, char *outKey, uint16_t outKeyLen,
Expand All @@ -205,6 +207,7 @@ static parser_error_t printERC20(const parser_context_t *ctx, uint8_t displayIdx
MEMZERO(outVal, outValLen);
*pageCount = 1;

uint8_t data_array[23] = {0};
// Add check if value equal zero jump to print data
switch (displayIdx) {
case 0:
Expand Down Expand Up @@ -243,9 +246,10 @@ static parser_error_t printERC20(const parser_context_t *ctx, uint8_t displayIdx
snprintf(outKey, outKeyLen, "Value");
CHECK_ERROR(printRLPNumber(&eth_tx_obj.legacy.value, outVal, outValLen, pageIdx, pageCount));
break;

case 7:
snprintf(outKey, outKeyLen, "Data");
// Print data that fits the field
//array_to_hexstr CHECK_ERROR(printRLPNumber(&eth_tx_obj.legacy.value, outVal, outValLen, pageIdx, pageCount));
break;
case 8:
CHECK_ERROR(printTxHash(ctx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount));
Expand Down Expand Up @@ -293,13 +297,12 @@ parser_error_t _getNumItemsEth(uint8_t *numItems) {
// Verify that tx is ERC20

if (validateERC20(&eth_tx_obj)) {
// Add check if value equal zero numitems -1
*numItems = 9;
return parser_ok;
}

// Warning message, amount and the eth transaction hash for now.
*numItems = 3;
*numItems = 2;
return parser_ok;
}

Expand Down
28 changes: 19 additions & 9 deletions tests/expected_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,27 @@ std::vector<std::string> EVMGenerateExpectedUIOutput(const Json::Value &json, bo

///
auto message = json["message"];
auto to = message["To"].asString();
auto receiver = message["Receiver"].asString();
auto contract = message["Contract"].asString();
auto value = message["Value"].asString();
auto amount = message["Amount"].asString();
auto nonce = message["Nonce"].asString();
auto gasPrice = message["GasPrice"].asString();
auto gasLimit = message["GasLimit"].asString();
auto value = message["Value"].asString();
auto txhash = message["TxHash"].asString();
auto data = message["Data"].asString();
///

uint8_t idx = 0;
auto destAddress = FormatEthAddress("To", idx, to);
auto destAddress = FormatEthAddress("Receiver", idx, receiver);
answer.insert(answer.end(), destAddress.begin(), destAddress.end());

if (value.compare(0, 2, "??") == 0) {
idx++;
auto contractAddress = FormatEthAddress("Contract", idx, contract);
answer.insert(answer.end(), contractAddress.begin(), contractAddress.end());
}
idx++;
auto contractAddress = FormatEthAddress("Contract", idx, contract);
answer.insert(answer.end(), contractAddress.begin(), contractAddress.end());

idx++;
addTo(answer, "{} | Value : {}", idx, value);
addTo(answer, "{} | Amount : {}", idx, amount);

idx++;
addTo(answer, "{} | Nonce : {}", idx, nonce);
Expand All @@ -94,5 +95,14 @@ std::vector<std::string> EVMGenerateExpectedUIOutput(const Json::Value &json, bo
idx++;
addTo(answer, "{} | Gas limit : {}", idx, gasLimit);

idx++;
addTo(answer, "{} | Value : {}", idx, value);

idx++;
addTo(answer, "{} | Data : {}", idx, data);

idx++;
addTo(answer, "{} | TxHash : {}", idx, txhash);

return answer;
}
Loading

1 comment on commit 7e19c3d

@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: 1 file(s) not formatted
  • app/src/parser_impl_eth.c

Have any feedback or feature suggestions? Share it here.

Please sign in to comment.