Validation Function
In order to validate the results produced we must define a validation function. This function is passed to the built in validate node function and is run on every node running the task, details can be found here. In this case we are checking the submission value from every node which is a CID and then requesting that CID from IPFS, we check to make sure that content matches the content of this node result. If the content matches and the content is signed correctly then the node is valid and the function returns true, other wise the function returns false.
* @description Using to validate an individual node. Returns true if node is valid
async function validateNode(node) {
console.log("Validating Node", node);
const cid = node.submission_value;
const res = await client.get(cid);
const { data, error } = await namespace.verifySignedData(res, node.submitterPubkey);
const quoteOfTheDay = getQuoteOfTheDay();
// If
// CID does not point to hosted data
// Or data is signed incorrectly
// Or if that data does not match the quote of the day
// -> Then the node is invalid
if (!res.ok || error || data != quoteOfTheDay) {
return false;
} else {
return true;
Copy link