diff --git a/src/providers/thegraph.ts b/src/providers/thegraph.ts new file mode 100644 index 0000000..e018dcd --- /dev/null +++ b/src/providers/thegraph.ts @@ -0,0 +1,21 @@ +import { create } from 'ipfs-http-client'; + +export const provider = 'thegraph'; +const client = create({ + url: 'https://api.thegraph.com/ipfs/api/v0', + timeout: 10e3 +}); + +export async function set(data: Buffer | object) { + const input = data instanceof Buffer ? data : JSON.stringify(data); + const result = await client.add(input, { + pin: true + }); + const cid = result.cid.toV0().toString(); + + return { cid, provider }; +} + +export function isConfigured() { + return true; +} diff --git a/src/providers/utils.ts b/src/providers/utils.ts index cd72d0a..9d3850a 100644 --- a/src/providers/utils.ts +++ b/src/providers/utils.ts @@ -1,6 +1,7 @@ import * as fleek from './fleek'; import * as infura from './infura'; import * as pinata from './pinata'; +import * as thegraph from './thegraph'; import * as web3storage from './web3storage'; import * as fourEverland from './4everland'; @@ -10,10 +11,14 @@ export const IMAGE_PROVIDERS = ['fleek', 'infura', 'pinata', '4everland']; // List of providers used for pinning json export const JSON_PROVIDERS = ['fleek', 'infura', 'web3storage', '4everland']; +// List of providers used for pinning data for EVM networks +export const EVM_PROVIDERS = ['thegraph']; + export const providersMap = { fleek, infura, pinata, web3storage, + thegraph, '4everland': fourEverland }; diff --git a/src/rpc.ts b/src/rpc.ts index d08c3c9..1c4d625 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -3,7 +3,7 @@ import { capture } from '@snapshot-labs/snapshot-sentry'; import { MAX, rpcError, rpcSuccess } from './utils'; import { set as setAws } from './aws'; import uploadToProviders from './providers/'; -import { JSON_PROVIDERS } from './providers/utils'; +import { JSON_PROVIDERS, EVM_PROVIDERS } from './providers/utils'; const router = express.Router(); @@ -18,7 +18,9 @@ router.post('/', async (req, res) => { const size = Buffer.from(JSON.stringify(params)).length; if (size > MAX) return rpcError(res, 400, 'File too large', id); - const result = await uploadToProviders(JSON_PROVIDERS, 'json', params); + const providers = + req.query.type === 'evm' ? [...JSON_PROVIDERS, ...EVM_PROVIDERS] : JSON_PROVIDERS; + const result = await uploadToProviders(providers, 'json', params); try { await setAws(result.cid, params); } catch (e: any) {