Skip to content

Commit

Permalink
add support to sns set dissolve delay
Browse files Browse the repository at this point in the history
Closes #212
  • Loading branch information
carlosala committed Aug 4, 2023
1 parent 8632327 commit 35bcce4
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/src/candid/candid_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extern "C" {
#include <zxerror.h>
#include "coin.h"

#define YEAR_2100_IN_SECONDS 4102444800

typedef enum {
Null = -1,
Bool = -2,
Expand Down
2 changes: 1 addition & 1 deletion app/src/candid/nns_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ __Z_INLINE parser_error_t readOperationSetDissolveTimestamp(parser_context_t *ct
// Read SetDissolvedTimestamp
CHECK_PARSER_ERR(readCandidNat64(ctx, &operation->setDissolveTimestamp.dissolve_timestamp_seconds))

if (operation->setDissolveTimestamp.dissolve_timestamp_seconds >= 4102444800) {
if (operation->setDissolveTimestamp.dissolve_timestamp_seconds >= YEAR_2100_IN_SECONDS) {
return parser_value_out_of_range;
}

Expand Down
20 changes: 20 additions & 0 deletions app/src/candid/sns_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,26 @@ __Z_INLINE parser_error_t readSNSCommandNeuronConfigure(parser_context_t *ctx, c
return parser_unexpected_number_items;
}
break;
case hash_operation_SetDissolvedTimestamp:
CHECK_PARSER_ERR(getCandidTypeFromTable(txn, txn->element.implementation))
CHECK_PARSER_ERR(readCandidRecordLength(txn))
if (txn->txn_length != 1) {
return parser_unexpected_number_items;
}
txn->element.variant_index = 0;
CHECK_PARSER_ERR(readCandidInnerElement(txn, &txn->element))
if (txn->element.field_hash != hash_dissolve_timestamp_seconds || txn->element.implementation != Nat64) {
return parser_unexpected_type;
}

// Read SetDissolvedTimestamp
CHECK_PARSER_ERR(readCandidNat64(ctx, &operation->setDissolveTimestamp.dissolve_timestamp_seconds))

if (operation->setDissolveTimestamp.dissolve_timestamp_seconds >= YEAR_2100_IN_SECONDS) {
return parser_value_out_of_range;
}
break;

default:
ZEMU_LOGF(100, "Unimplemented operation | Hash: %llu\n", operation->hash)
return parser_unexpected_value;
Expand Down
3 changes: 2 additions & 1 deletion app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ parser_error_t getManageNeuronType(const parser_tx_t *v, manageNeuron_e *mn_type
}
switch (command->configure.operation.hash) {
case hash_operation_SetDissolvedTimestamp:
*mn_type = Configure_SetDissolvedTimestamp;
*mn_type = isSNS ? SNS_Configure_SetDissolveDelay : Configure_SetDissolvedTimestamp;
break;
case hash_operation_LeaveNeuronsFund:
*mn_type = Configure_LeaveNeuronsFundCandid;
Expand Down Expand Up @@ -757,6 +757,7 @@ uint8_t getNumItemsManageNeurons(__Z_UNUSED const parser_context_t *c, const par
case Configure_SetDissolvedTimestamp: {
return 3;
}
case SNS_Configure_SetDissolveDelay:
case RegisterVote :
case RegisterVoteCandid:
case DisburseCandid:
Expand Down
52 changes: 52 additions & 0 deletions app/src/parser_print_candid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,56 @@ static parser_error_t parser_getItemSNSStakeMaturity(uint8_t displayIdx,
return parser_no_data;
}

static parser_error_t parser_getItemSNSSetDissolveDelay(uint8_t displayIdx,
char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {
*pageCount = 1;

if (displayIdx == 0) {
snprintf(outKey, outKeyLen, "Transaction type");
pageString(outVal, outValLen, "Set Dissolve Delay", pageIdx, pageCount);
return parser_ok;
}

if (displayIdx == 1) {
const uint8_t *canisterId = (uint8_t*) &parser_tx_obj.tx_fields.call.canister_id.data;
const uint8_t canisterIdSize = (uint8_t) parser_tx_obj.tx_fields.call.canister_id.len;

snprintf(outKey, outKeyLen, "Canister Id");
return print_principal(canisterId, canisterIdSize, outVal, outValLen, pageIdx, pageCount);
}

if (displayIdx == 2) {
snprintf(outKey, outKeyLen, "Neuron Id ");
return page_hexstring_with_delimiters(parser_tx_obj.tx_fields.call.data.sns_manageNeuron.subaccount.p,
parser_tx_obj.tx_fields.call.data.sns_manageNeuron.subaccount.len,
outVal, outValLen, pageIdx, pageCount);
}

if (displayIdx == 3) {
snprintf(outKey, outKeyLen, "Dissolve Time");
uint64_t dissolve_timestamp_seconds = parser_tx_obj.tx_fields.call.data.sns_manageNeuron.command.configure.operation.setDissolveTimestamp.dissolve_timestamp_seconds;

timedata_t td = {0};
zxerr_t zxerr = decodeTime(&td, dissolve_timestamp_seconds);
if (zxerr != zxerr_ok) {
return parser_unexpected_value;
}

char tmpBuffer[30] = {0};
// YYYYmmdd HH:MM:SS
snprintf(tmpBuffer, sizeof(tmpBuffer), "%04d-%02d-%02d %02d:%02d:%02d UTC",
td.tm_year, td.tm_mon, td.tm_day,
td.tm_hour, td.tm_min, td.tm_sec
);

pageString(outVal, outValLen, tmpBuffer, pageIdx, pageCount);
return parser_ok;
}
return parser_no_data;
}

__Z_INLINE parser_error_t parser_getItemManageNeuron(const parser_context_t *ctx,
uint8_t displayIdx,
char *outKey, uint16_t outKeyLen,
Expand Down Expand Up @@ -1182,6 +1232,8 @@ __Z_INLINE parser_error_t parser_getItemManageNeuron(const parser_context_t *ctx
return parser_getItemDisburseSNS(displayIdx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount);
case SNS_StakeMaturity:
return parser_getItemSNSStakeMaturity(displayIdx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount);
case SNS_Configure_SetDissolveDelay:
return parser_getItemSNSSetDissolveDelay(displayIdx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount);

default:
return parser_no_data;
Expand Down
1 change: 1 addition & 0 deletions app/src/parser_txdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ typedef enum {
SNS_Configure_StopDissolving = 3003,
SNS_Disburse = 3004,
SNS_StakeMaturity = 3005,
SNS_Configure_SetDissolveDelay = 3006,
} manageNeuron_e;

typedef enum {
Expand Down

0 comments on commit 35bcce4

Please sign in to comment.