Skip to content

Commit

Permalink
support opt bool on listNeurons
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Jul 19, 2024
1 parent 35170ac commit aeea253
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/src/candid/candid_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ parser_error_t readCandidListNeurons(parser_tx_t *tx, const uint8_t *input, uint
CHECK_PARSER_ERR(getCandidTypeFromTable(&txn, tx->candid_rootType))

CHECK_PARSER_ERR(readCandidRecordLength(&txn))
if (txn.txn_length != 2) {
if (txn.txn_length != 3) {
return parser_unexpected_value;
}
txn.element.variant_index = 0;
Expand All @@ -86,6 +86,17 @@ parser_error_t readCandidListNeurons(parser_tx_t *tx, const uint8_t *input, uint

txn.element.variant_index = 1;
CHECK_PARSER_ERR(readCandidInnerElement(&txn, &txn.element))
CHECK_PARSER_ERR(readCandidOptional(&txn))
if (txn.txn_type != Opt || txn.element.implementation != Bool) {
return parser_unexpected_type;
}

// reset txn
CHECK_PARSER_ERR(getCandidTypeFromTable(&txn, tx->candid_rootType))
CHECK_PARSER_ERR(readCandidRecordLength(&txn))

txn.element.variant_index = 2;
CHECK_PARSER_ERR(readCandidInnerElement(&txn, &txn.element))
if (txn.element.field_hash != hash_include_neurons_readable_by_caller ||
txn.element.implementation != Bool) {
return parser_unexpected_type;
Expand All @@ -101,6 +112,11 @@ parser_error_t readCandidListNeurons(parser_tx_t *tx, const uint8_t *input, uint
CHECK_PARSER_ERR(readCandidNat64(&ctx, &tmp_neuron_id))
}

CHECK_PARSER_ERR(readCandidByte(&ctx, &val->has_include_empty_neurons_readable_by_caller))
if(val->has_include_empty_neurons_readable_by_caller) {
CHECK_PARSER_ERR(readCandidByte(&ctx, &val->include_empty_neurons_readable_by_caller))
}

CHECK_PARSER_ERR(readCandidByte(&ctx, &val->include_neurons_readable_by_caller))
return parser_ok;
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/candid/candid_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ typedef struct {
uint8_t neuron_ids_size;
const uint8_t *neuron_ids_ptr;

uint8_t has_include_empty_neurons_readable_by_caller;
uint8_t include_empty_neurons_readable_by_caller;
uint8_t include_neurons_readable_by_caller;
} candid_ListNeurons_t;

Expand Down

0 comments on commit aeea253

Please sign in to comment.