Colony Event Metadata Parser
Metadata format versions
ColonyDapp should support legacy Metadata formats.
Therefore, when parsing (in ColonyDapp) it is necessary to check the Metadata format version and support V1 & later versions.
const metadataVersion = getEventMetadataVersion(ipfsMetadata);
if (metadataVersion === 1) {
...
}
else {
....
}
Parsing
To retrieve MetaData from IPFS. (String to Object)
const colonyMetadata = getColonyMetadataFromResponse(ipfsDataJSON);
const domainMetadata = getDomainMetadataFromResponse(ipfsDataJSON);
const annotation = getAnnotationMsgFromResponse(ipfsDataJSON);
const colonyMetadata = getColonyMetadataFromResponse(ipfsMetadata);
avatarHash = colonyMetadata?.colonyAvatarHash;
response = await ipfs.getString(avatarHash);
avatarObject = { image: getColonyAvatarImage(response) };
const response = await ipfsWithFallback.getString(agreementHash);
const agreement = getNameValueFromMisc('agreement', response);
Deserialising
Preparing Metadata to send to IPFS. (Object to String)
const metadataForIPFS = getStringForMetadataColony({
colonyDisplayName,
colonyAvatarHash: colonyAvatarIpfsHash
colonyTokens,
verifiedAddresses,
isWhitelistActivated,
});
colonyMetadataIpfsHash = yield call(ipfsUpload, metadataForIPFS);
domainMetadataIpfsHash = yield call(
ipfsUpload,
getStringForMetadataDomain({
domainName,
domainColor,
domainPurpose,
}),
ipfsHash = yield call(
ipfsUpload,
getStringForMetadataAnnotation({
annotationMsg: annotationMessage || '',
}),
);
colonyAvatarIpfsHash = yield call(
ipfsUpload,
getStringForColonyAvatarImage(colonyAvatarImage),
);
let agreementHash = '';
if (payload.agreement) {
const miscMetadata = {
name: 'agreement',
value: payload?.agreement,
};
agreementHash = yield call(
ipfsUpload,
getStringForMetadataMisc(miscMetadata),
);
}
License
GPL-3.0