-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto-add rpc providers from chainlist
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
git checkout master | ||
git pull | ||
ts-node src/util/updateProviderList.ts | ||
npm run test | ||
if [[ $? -ne 0 ]] ; then | ||
echo "Unit test failed, fix it before publishing new version" | ||
exit 1 | ||
fi | ||
npm version patch | ||
git push | ||
rm -rf build | ||
rm LICENSE | ||
npm publish | ||
git checkout master -- LICENSE | ||
git checkout master -- src/providers.json | ||
git push --tags |
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,30 @@ | ||
|
||
import providerList from '../providers.json' | ||
import fs from 'fs' | ||
import fetch from "node-fetch"; | ||
|
||
function fetchJson(url: string) { | ||
return fetch(url).then((res) => res.json()); | ||
} | ||
|
||
async function main() { | ||
let chainData = await fetchJson('https://chainid.network/chains.json') | ||
const existingChainIds = new Set(Object.values(providerList).map(i => i.chainId)) | ||
const existingChainNames = new Set(Object.keys(providerList)) | ||
chainData = chainData | ||
.filter((i: any) => i.rpc.length) | ||
.filter((i: any) => !i.status || i.status === 'active') | ||
.filter((i: any) => i.shortName) | ||
.filter((i: any) => !existingChainIds.has(i.chainId)) | ||
.filter((i: any) => !existingChainNames.has(i.shortName)) | ||
const newList = {...providerList} as any | ||
chainData.forEach((i: any) => { | ||
newList[i.shortName.toLowerCase()] = { | ||
rpc: i.rpc, | ||
chainId: i.chainId | ||
} | ||
}) | ||
fs.writeFileSync(__dirname+'/../providers.json', JSON.stringify(newList)) | ||
} | ||
|
||
main() |