Skip to content

Commit

Permalink
update and add types
Browse files Browse the repository at this point in the history
  • Loading branch information
ShankarWarang committed Oct 9, 2023
1 parent f1cbe46 commit 9be6cba
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/src/substrate_methods_V2.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ typedef struct {

#define PD_CALL_IDENTITY_SET_SUBS_V2 2
typedef struct {
pd_VecTupleAccountIdData_t subs;
pd_VecTupleAccountIdData_V2_t subs;
} pd_identity_set_subs_V2_t;

#define PD_CALL_IDENTITY_CLEAR_IDENTITY_V2 3
Expand All @@ -744,7 +744,7 @@ typedef struct {

#define PD_CALL_IDENTITY_CANCEL_REQUEST_V2 5
typedef struct {
pd_RegistrarIndex_t reg_index;
pd_RegistrarIndex_V2_t reg_index;
} pd_identity_cancel_request_V2_t;

#define PD_CALL_IDENTITY_SET_FEE_V2 6
Expand All @@ -762,14 +762,14 @@ typedef struct {
#define PD_CALL_IDENTITY_SET_FIELDS_V2 8
typedef struct {
pd_CompactRegistrarIndex_t index;
pd_IdentityFields_t fields;
pd_IdentityFields_V2_t fields;
} pd_identity_set_fields_V2_t;

#define PD_CALL_IDENTITY_PROVIDE_JUDGEMENT_V2 9
typedef struct {
pd_Compactu32_t reg_index;
pd_AccountIdLookupOfT_t target;
pd_JudgementBalanceOfT_t judgement;
pd_JudgementBalanceOfT_V2_t judgement;
pd_Hash_t identity;
} pd_identity_provide_judgement_V2_t;

Expand Down
101 changes: 101 additions & 0 deletions app/src/substrate_types_V2.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,21 @@ parser_error_t _readIdentityFields_V2(parser_context_t* c, pd_IdentityFields_V2_
return parser_not_supported;
}

parser_error_t _readIdentityInfo(parser_context_t* c, pd_IdentityInfo_t* v)
{
CHECK_INPUT()
CHECK_ERROR(_readVecTupleDataData(c, &v->additional));
CHECK_ERROR(_readData(c, &v->display));
CHECK_ERROR(_readData(c, &v->legal));
CHECK_ERROR(_readData(c, &v->web));
CHECK_ERROR(_readData(c, &v->riot));
CHECK_ERROR(_readData(c, &v->email));
CHECK_ERROR(_readOptionu8_array_20(c, &v->pgp_fingerprint));
CHECK_ERROR(_readData(c, &v->image));
CHECK_ERROR(_readData(c, &v->twitter));
return parser_ok;
}

parser_error_t _readJudgementBalanceOfT_V2(parser_context_t* c, pd_JudgementBalanceOfT_V2_t* v)
{
return parser_not_supported;
Expand Down Expand Up @@ -1257,6 +1272,92 @@ parser_error_t _toStringIdentityFields_V2(
return parser_print_not_supported;
}

parser_error_t _toStringIdentityInfo(
const pd_IdentityInfo_t* v,
char* outValue,
uint16_t outValueLen,
uint8_t pageIdx,
uint8_t* pageCount)
{
CLEAN_AND_CHECK()

// First measure number of pages
uint8_t pages[9] = { 0 };
CHECK_ERROR(_toStringVecTupleDataData(&v->additional, outValue, outValueLen, 0, &pages[0]))
CHECK_ERROR(_toStringData(&v->display, outValue, outValueLen, 0, &pages[1]))
CHECK_ERROR(_toStringData(&v->legal, outValue, outValueLen, 0, &pages[2]))
CHECK_ERROR(_toStringData(&v->web, outValue, outValueLen, 0, &pages[3]))
CHECK_ERROR(_toStringData(&v->riot, outValue, outValueLen, 0, &pages[4]))
CHECK_ERROR(_toStringData(&v->email, outValue, outValueLen, 0, &pages[5]))
CHECK_ERROR(_toStringOptionu8_array_20(&v->pgp_fingerprint, outValue, outValueLen, 0, &pages[6]))
CHECK_ERROR(_toStringData(&v->image, outValue, outValueLen, 0, &pages[7]))
CHECK_ERROR(_toStringData(&v->twitter, outValue, outValueLen, 0, &pages[8]))

*pageCount = 0;
for (uint8_t i = 0; i < (uint8_t)sizeof(pages); i++) {
*pageCount += pages[i];
}

if (pageIdx > *pageCount) {
return parser_display_idx_out_of_range;
}

if (pageIdx < pages[0]) {
CHECK_ERROR(_toStringVecTupleDataData(&v->additional, outValue, outValueLen, pageIdx, &pages[0]))
return parser_ok;
}
pageIdx -= pages[0];

if (pageIdx < pages[1]) {
CHECK_ERROR(_toStringData(&v->display, outValue, outValueLen, pageIdx, &pages[1]))
return parser_ok;
}
pageIdx -= pages[1];

if (pageIdx < pages[2]) {
CHECK_ERROR(_toStringData(&v->legal, outValue, outValueLen, pageIdx, &pages[2]))
return parser_ok;
}
pageIdx -= pages[2];

if (pageIdx < pages[3]) {
CHECK_ERROR(_toStringData(&v->web, outValue, outValueLen, pageIdx, &pages[3]))
return parser_ok;
}
pageIdx -= pages[3];

if (pageIdx < pages[4]) {
CHECK_ERROR(_toStringData(&v->riot, outValue, outValueLen, pageIdx, &pages[4]))
return parser_ok;
}
pageIdx -= pages[4];

if (pageIdx < pages[5]) {
CHECK_ERROR(_toStringData(&v->email, outValue, outValueLen, pageIdx, &pages[5]))
return parser_ok;
}
pageIdx -= pages[5];

if (pageIdx < pages[6]) {
CHECK_ERROR(_toStringOptionu8_array_20(&v->pgp_fingerprint, outValue, outValueLen, pageIdx, &pages[6]))
return parser_ok;
}
pageIdx -= pages[6];

if (pageIdx < pages[7]) {
CHECK_ERROR(_toStringData(&v->image, outValue, outValueLen, pageIdx, &pages[7]))
return parser_ok;
}
pageIdx -= pages[7];

if (pageIdx < pages[8]) {
CHECK_ERROR(_toStringData(&v->twitter, outValue, outValueLen, pageIdx, &pages[8]))
return parser_ok;
}

return parser_display_idx_out_of_range;
}

parser_error_t _toStringJudgementBalanceOfT_V2(
const pd_JudgementBalanceOfT_V2_t* v,
char* outValue,
Expand Down
12 changes: 12 additions & 0 deletions app/src/substrate_types_V2.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ typedef struct {
uint8_t _NOT_IMPLEMENTED__DO_NOT_USE;
} pd_IdentityFields_V2_t;

typedef struct {
pd_VecTupleDataData_t additional;
pd_Data_t display;
pd_Data_t legal;
pd_Data_t web;
pd_Data_t riot;
pd_Data_t email;
pd_Optionu8_array_20_t pgp_fingerprint;
pd_Data_t image;
pd_Data_t twitter;
} pd_IdentityInfo_t;

typedef struct {
// TODO: Not implemented
uint8_t _NOT_IMPLEMENTED__DO_NOT_USE;
Expand Down

0 comments on commit 9be6cba

Please sign in to comment.