Skip to content

Commit

Permalink
[#1856] fix bugs that occur when parsing nested metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dyczka committed Oct 3, 2024
1 parent 8b90452 commit 352f929
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions govtool/frontend/src/consts/dRepActions/jsonContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const CIP_119 =
"https://github.com/cardano-foundation/CIPs/blob/master/CIP-0119/README.md#";

export const DREP_CONTEXT = {
"@language": "en-us",
CIP100:
"https://github.com/cardano-foundation/CIPs/blob/master/CIP-0100/README.md#",
CIP119: CIP_119,
Expand Down
2 changes: 1 addition & 1 deletion govtool/metadata-validation/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class AppService {
if (hashedMetadata !== hash) {
// Optionally validate on a parsed metadata
const hashedParsedMetadata = blake.blake2bHex(
JSON.stringify(parsedData),
JSON.stringify(parsedData, null, 2),
undefined,
32,
);
Expand Down
9 changes: 5 additions & 4 deletions govtool/metadata-validation/src/utils/getFieldValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export const getFieldValue = (
body: Record<string, unknown>,
field: string,
): unknown => {
if (body[field] && body[field]['@value']) {
return body[field]['@value'];
const fieldValue = body[field];
if (fieldValue.hasOwnProperty('@value')) {
return fieldValue['@value'];
}

if (body[field]) {
return body[field];
if (fieldValue) {
return fieldValue;
}

return undefined;
Expand Down
7 changes: 6 additions & 1 deletion govtool/metadata-validation/src/utils/parseMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ export const parseMetadata = (body: Record<string, unknown>) => {
const metadata = {};

Object.keys(body).forEach((key) => {
metadata[key] = getFieldValue(body, key);
if (key === 'references') {
const parsedReferences = (body[key] as Record<string, unknown>[]).map((reference) => parseMetadata(reference));
metadata[key] = parsedReferences;
} else {
metadata[key] = getFieldValue(body, key);
}
});
return metadata;
};

0 comments on commit 352f929

Please sign in to comment.