Skip to content

Commit

Permalink
Revert "parse param depending on method number" (#106)
Browse files Browse the repository at this point in the history
* Revert "parse param depending on method number"

This reverts commit dadf45e.

* fix test; changeowneraddress params is double cbor encoded;

* bump version
  • Loading branch information
rllola authored May 2, 2022
1 parent ebf1323 commit df5835d
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 64 deletions.
2 changes: 1 addition & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ endif

APPVERSION_M=0
APPVERSION_N=22
APPVERSION_P=3
APPVERSION_P=4

$(info COIN = [$(COIN)])
ifeq ($(COIN),FIL)
Expand Down
72 changes: 27 additions & 45 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,20 @@ parser_error_t _printParam(const parser_tx_t *tx, uint8_t paramIdx,

CborValue itParams = itContainer;

switch(tx->method) {
case 23: {
PARSER_ASSERT_OR_ERROR(itContainer.type == CborByteStringType, parser_unexpected_type)
switch (itContainer.type) {
case CborByteStringType: {
address_t tmpAddr;
MEMZERO(&tmpAddr, sizeof(address_t));
CHECK_PARSER_ERR(readAddress(&tmpAddr, &itContainer))
PARSER_ASSERT_OR_ERROR(itContainer.type != CborInvalidType, parser_unexpected_type)
//Not every ByteStringType must be interpreted as address. Depends on method number and actor.
CHECK_PARSER_ERR(_printAddress(&tmpAddr, outVal, outValLen, pageIdx, pageCount));
break;
}
case 2:
case 0: {
/// Enter container
case CborMapType:
case CborArrayType:
default: {
/// Enter container?
CHECK_CBOR_MAP_ERR(cbor_value_enter_container(&itContainer, &itParams))
CHECK_APP_CANARY()
for (uint8_t i = 0; i < paramIdx; ++i) {
Expand All @@ -301,11 +302,7 @@ parser_error_t _printParam(const parser_tx_t *tx, uint8_t paramIdx,
CHECK_APP_CANARY()
break;
}
default:
return parser_unexpected_method;
break;
}

return parser_ok;
}

Expand Down Expand Up @@ -369,46 +366,31 @@ __Z_INLINE parser_error_t readMethod(parser_tx_t *tx, CborValue *value) {
CborParser parser;
CborValue itParams;
CHECK_CBOR_MAP_ERR(cbor_parser_init(tx->params, paramsLen, 0, &parser, &itParams))
switch (methodValue) {
case 2:
case 0: {
switch (itParams.type) {
case CborArrayType: {
size_t arrayLength = 0;
CHECK_CBOR_MAP_ERR(cbor_value_get_array_length(&itParams, &arrayLength))
PARSER_ASSERT_OR_ERROR(arrayLength < UINT8_MAX, parser_value_out_of_range)
tx->numparams = arrayLength;
break;
}
case CborMapType: {
size_t mapLength = 0;
CHECK_CBOR_MAP_ERR(cbor_value_get_map_length(&itParams, &mapLength))
PARSER_ASSERT_OR_ERROR(mapLength < UINT8_MAX, parser_value_out_of_range)
tx->numparams = mapLength;
break;
}
case CborInvalidType:
default:
return parser_unexpected_type;
}

switch (itParams.type) {
case CborArrayType: {
size_t arrayLength = 0;
CHECK_CBOR_MAP_ERR(cbor_value_get_array_length(&itParams, &arrayLength))
PARSER_ASSERT_OR_ERROR(arrayLength < UINT8_MAX, parser_value_out_of_range)
tx->numparams = arrayLength;
break;
}
case 23: {
switch (itParams.type) {
case CborByteStringType: {
//Only one parameter is expected when ByteStringType is received.
PARSER_ASSERT_OR_ERROR(itParams.remaining == 1, parser_value_out_of_range)
tx->numparams = 1;
break;
}
default:
return parser_unexpected_type;
}
case CborMapType: {
size_t mapLength = 0;
CHECK_CBOR_MAP_ERR(cbor_value_get_map_length(&itParams, &mapLength))
PARSER_ASSERT_OR_ERROR(mapLength < UINT8_MAX, parser_value_out_of_range)
tx->numparams = mapLength;
break;
}
default: {
return parser_unexpected_method;
case CborByteStringType: {
//Only one parameter is expected when ByteStringType is received.
PARSER_ASSERT_OR_ERROR(itParams.remaining == 1, parser_value_out_of_range)
tx->numparams = 1;
break;
}
case CborInvalidType:
default:
return parser_unexpected_type;
}
}
tx->method = methodValue;
Expand Down
29 changes: 12 additions & 17 deletions tests/expected_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,18 @@ std::vector<std::string> GenerateExpectedUIOutput(const Json::Value &json, bool)

addTo(answer, "6 | Nonce : {}", nonce);

switch (method) {
case 0:
addTo(answer, "7 | Method : Transfer", method);
break;
case 23:
case 2:
default:
addTo(answer, "7 | Method : {}", method);

int paramIdx = 1;
for(auto value : params) {
std::string paramText = "Params |" + std::to_string(paramIdx) + "| ";
auto paramsAddress = FormatAddress(8 + paramIdx - 1, paramText, value.asString());
answer.insert(answer.end(), paramsAddress.begin(), paramsAddress.end());
paramIdx++;
}
break;
if (method != 0) {
addTo(answer, "7 | Method : {}", method);
} else {
addTo(answer, "7 | Method : Transfer", method);
}

int paramIdx = 1;
for(auto value : params) {
std::string paramText = "Params |" + std::to_string(paramIdx) + "| ";
auto paramsAddress = FormatAddress(8 + paramIdx - 1, paramText, value.asString());
answer.insert(answer.end(), paramsAddress.begin(), paramsAddress.end());
paramIdx++;
}

return answer;
Expand Down
2 changes: 1 addition & 1 deletion tests/testvectors/manual.json
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
"numparams": 1,
"params": ["01dfe49184d46adc8f89d44638beb45f78fcad2590"]
},
"encoded_tx_hex": "8A004300EC075501DFE49184D46ADC8F89D44638BEB45F78FCAD259001401A000F4240430009C4430009C41757815501DFE49184D46ADC8F89D44638BEB45F78FCAD2590"
"encoded_tx_hex": "8A004300EC075501DFE49184D46ADC8F89D44638BEB45F78FCAD259001401A000F4240430009C4430009C4175501DFE49184D46ADC8F89D44638BEB45F78FCAD2590"
},
{
"description": "Sign proposal",
Expand Down
Binary file modified tests_zemu/snapshots/s-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit df5835d

Please sign in to comment.