-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
132 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import {githubHybridCacheAdapter} from '../src/adapter/githubHybrid'; | ||
import {localCacheAdapter} from '../src/adapter/localCache'; | ||
import {customStorageProvider} from '../src/providers/customStorageProvider'; | ||
import {refreshCache} from '../src/common/refreshCache'; | ||
import {fileSystemStorage} from '../dist/fileSystem'; | ||
|
||
refreshCache(githubHybridCacheAdapter(localCacheAdapter)); | ||
const provider = customStorageProvider(fileSystemStorage); | ||
|
||
refreshCache(provider); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const ISSUES_FETCHING_PAYLOAD = 'ISSUES_FETCHING_PAYLOAD'; | ||
export const ISSUES_FETCHING_PROPOSAL = 'ISSUES_FETCHING_PROPOSAL'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {type GovernanceCacheAdapterWithSync} from '..'; | ||
import {ISSUES_FETCHING_PAYLOAD, ISSUES_FETCHING_PROPOSAL} from '../errors'; | ||
|
||
export const customStorageProvider = ( | ||
adapter: GovernanceCacheAdapterWithSync, | ||
): GovernanceCacheAdapterWithSync => ({ | ||
async getPayload(args) { | ||
let cache = await adapter.getPayload(args); | ||
if (!cache) { | ||
await adapter.syncPayloadsCache(args); | ||
cache = await adapter.getPayload(args); | ||
if (!cache) throw new Error(ISSUES_FETCHING_PAYLOAD); | ||
} | ||
return cache; | ||
}, | ||
async getProposal(args) { | ||
let cache = await adapter.getProposal(args); | ||
if (!cache) { | ||
await adapter.syncProposalCache(args); | ||
cache = await adapter.getProposal(args); | ||
if (!cache) throw new Error(ISSUES_FETCHING_PROPOSAL); | ||
} | ||
return cache; | ||
}, | ||
syncPayloadsCache(args) { | ||
return adapter.syncPayloadsCache(args); | ||
}, | ||
syncProposalCache(args) { | ||
return adapter.syncProposalCache(args); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type {GovernanceCacheAdapter} from '..'; | ||
import {ISSUES_FETCHING_PAYLOAD, ISSUES_FETCHING_PROPOSAL} from '../errors'; | ||
|
||
export const fallbackProvider = <T extends GovernanceCacheAdapter>( | ||
...providers: T[] | ||
): GovernanceCacheAdapter => ({ | ||
async getPayload(args) { | ||
for (let i = 0; i < providers.length; i++) { | ||
try { | ||
const response = providers[i].getPayload(args); | ||
return response; | ||
} catch (e) { | ||
console.log('falling back to next provider'); | ||
} | ||
} | ||
throw new Error(ISSUES_FETCHING_PAYLOAD); | ||
}, | ||
async getProposal(args) { | ||
for (let i = 0; i < providers.length; i++) { | ||
try { | ||
const response = await providers[i].getProposal(args); | ||
return response; | ||
} catch (e) { | ||
console.log('falling back to next provider'); | ||
} | ||
} | ||
throw new Error(ISSUES_FETCHING_PROPOSAL); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Hybrid adapter that tries to fetch via github pages | ||
* If github pages doesn't contain the desired data it will fallback to the supplied adapter | ||
*/ | ||
import type {GovernanceCacheAdapter, PayloadCacheRaw, ProposalCacheRaw} from '..'; | ||
import {formatPayloadLogs} from '../common/payloadsController'; | ||
import {formatProposalLogs} from '../common/governance'; | ||
|
||
function getPath() { | ||
return 'https://bgd-labs.github.io/v3-governance-cache/cache/'; | ||
} | ||
|
||
export const githubPagesCacheAdapter: GovernanceCacheAdapter = { | ||
async getPayload({chainId, payloadsController, payloadId}) { | ||
const path = `${chainId.toString()}/${payloadsController}/payloads/${payloadId}.json`; | ||
const cache = (await (await fetch(getPath() + path)).json()) as PayloadCacheRaw; | ||
return {payload: cache.payload!, logs: formatPayloadLogs(cache.events)}; | ||
}, | ||
async getProposal({chainId, governance, proposalId}) { | ||
const path = `${chainId.toString()}/${governance}/proposals/${proposalId}.json`; | ||
console.log(path); | ||
const cache = (await (await fetch(getPath() + path)).json()) as ProposalCacheRaw; | ||
return {proposal: cache.proposal!, logs: formatProposalLogs(cache.events), ipfs: cache.ipfs!}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters