Skip to content

Commit 654d79e

Browse files
chore: update-upload-and-transaction-code
1 parent 4e7a30f commit 654d79e

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

developer/light-curate.md

+46-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,51 @@ const pinFiles = async (
7979
}
8080
return [cids, inconsistentCids];
8181
};
82+
83+
84+
/**
85+
* Send file to IPFS network via The Graph hosted IPFS node
86+
* @param data - The raw data from the file to upload.
87+
* @returns ipfs response. Should include the hash and path of the stored item.
88+
*/
89+
export const publishToGraph = async (fileName, data) => {
90+
const url = `${process.env.GRAPH_IPFS_ENDPOINT}/api/v0/add?wrap-with-directory=true`;
91+
92+
const payload = new FormData();
93+
payload.append("file", new Blob([data]), fileName);
94+
95+
const response = await fetch(url, {
96+
method: "POST",
97+
body: payload,
98+
});
99+
100+
if (!response.ok) {
101+
throw new Error(
102+
`HTTP error! status: ${response.status}, Failed to pin to graph`
103+
);
104+
}
105+
106+
const result = parseNewlineSeparatedJSON(await response.text());
107+
108+
return result.map(({ Name, Hash }) => ({
109+
hash: Hash,
110+
path: `/${Name}`,
111+
}));
112+
};
113+
114+
/**
115+
* @description parses json from stringified json's seperated by new line
116+
*/
117+
const parseNewlineSeparatedJSON = (text) => {
118+
const lines = text.trim().split("\n");
119+
return lines.map((line) => JSON.parse(line));
120+
};
121+
122+
export const areCidsConsistent = (filebaseCid, graphResult) => {
123+
const graphCid = graphResult[1].hash;
124+
return graphCid === filebaseCid;
125+
};
126+
82127
```
83128

84129
The JSON file for the object is composed of the its metadata and fields.
@@ -162,7 +207,7 @@ const tx = await gtcr.addItem(ipfsEvidencePath, {
162207

163208
> We break down this section into two as list views and details view have different requirements.
164209
165-
Fetchin items is best done via the subgraph we provide. If you deployed an list using the factory, it already has a subgraph deployed and available [here](https://thegraph.com/explorer/subgraphs/9hHo5MpjpC1JqfD3BsgFnojGurXRHTrHWcUcZPPCo6m8?view=Query&chain=arbitrum-one).
210+
Fetching items is best done via the subgraph we provide. If you deployed a list using the factory, it already has a subgraph deployed and available [here](https://thegraph.com/explorer/subgraphs/9hHo5MpjpC1JqfD3BsgFnojGurXRHTrHWcUcZPPCo6m8?view=Query&chain=arbitrum-one).
166211

167212
#### List
168213

0 commit comments

Comments
 (0)