|
| 1 | +/******************************************************************************* |
| 2 | + * (c) 2018 - 2025 Zondax AG |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + ********************************************************************************/ |
| 16 | + |
| 17 | +#include "common_reader.h" |
| 18 | + |
| 19 | +parser_error_t read_amount(parser_context_t *ctx, amount_t *amount) { |
| 20 | + CHECK_INPUT(ctx); |
| 21 | + CHECK_INPUT(amount); |
| 22 | + |
| 23 | + CHECK_ERROR(read_u64(ctx, &amount->lo)); |
| 24 | + CHECK_ERROR(read_u64(ctx, &amount->hi)); |
| 25 | + print_u64_hex("amount:", amount->lo); |
| 26 | + print_u64_hex("amount:", amount->hi); |
| 27 | + |
| 28 | + print_u64("amount:", amount->lo); |
| 29 | + print_u64("amount:", amount->hi); |
| 30 | + |
| 31 | + return parser_ok; |
| 32 | +} |
| 33 | + |
| 34 | +parser_error_t read_token_id(parser_context_t *ctx, token_id_t *token_id) { |
| 35 | + CHECK_INPUT(ctx); |
| 36 | + CHECK_INPUT(token_id); |
| 37 | + |
| 38 | + token_id->token.len = TOKEN_ID_SIZE; |
| 39 | + token_id->token.ptr = ctx->buffer + ctx->offset; |
| 40 | + CTX_CHECK_AND_ADVANCE(ctx, TOKEN_ID_SIZE) |
| 41 | + |
| 42 | + print_buffer(&token_id->token, "token_id"); |
| 43 | + |
| 44 | + return parser_ok; |
| 45 | +} |
| 46 | + |
| 47 | +parser_error_t read_address(parser_context_t *ctx, address_t *address) { |
| 48 | + CHECK_INPUT(ctx); |
| 49 | + CHECK_INPUT(address); |
| 50 | + |
| 51 | + // TODO: check this value, MultiAddress enum? |
| 52 | + uint8_t unknown = 0; |
| 53 | + CHECK_ERROR(read_u8(ctx, &unknown)); |
| 54 | + print_u8("unknown", unknown); |
| 55 | + |
| 56 | + address->address.len = ADDRESS_SIZE; |
| 57 | + address->address.ptr = ctx->buffer + ctx->offset; |
| 58 | + CTX_CHECK_AND_ADVANCE(ctx, ADDRESS_SIZE); |
| 59 | + |
| 60 | + print_buffer(&address->address, "address"); |
| 61 | + |
| 62 | + return parser_ok; |
| 63 | +} |
| 64 | + |
| 65 | +parser_error_t read_coins(parser_context_t *ctx, coins_t *coins) { |
| 66 | + CHECK_INPUT(ctx); |
| 67 | + CHECK_INPUT(coins); |
| 68 | + |
| 69 | + CHECK_ERROR(read_amount(ctx, &coins->amount)); |
| 70 | + CHECK_ERROR(read_token_id(ctx, &coins->token_id)); |
| 71 | + |
| 72 | + return parser_ok; |
| 73 | +} |
| 74 | + |
| 75 | +parser_error_t read_gas(parser_context_t *ctx, gas_t *gas) { |
| 76 | + CHECK_INPUT(ctx); |
| 77 | + CHECK_INPUT(gas); |
| 78 | + |
| 79 | + for (int i = 0; i < GAS_DIMENSIONS; i++) { |
| 80 | + CHECK_ERROR(read_u64(ctx, &gas->gas[i])); |
| 81 | + print_u64_hex("gas[%d]:", gas->gas[i]); |
| 82 | + print_u64("gas[%d]:", gas->gas[i]); |
| 83 | + } |
| 84 | + |
| 85 | + return parser_ok; |
| 86 | +} |
| 87 | + |
| 88 | +parser_error_t read_gas_u128(parser_context_t *ctx, gas_u128_t *gas) { |
| 89 | + CHECK_INPUT(ctx); |
| 90 | + CHECK_INPUT(gas); |
| 91 | + |
| 92 | + for (int i = 0; i < GAS_DIMENSIONS; i++) { |
| 93 | + CHECK_ERROR(read_amount(ctx, &gas->gas[i])); |
| 94 | + } |
| 95 | + |
| 96 | + return parser_ok; |
| 97 | +} |
0 commit comments