Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: populate multiple chains in big query tokenInfo table #284

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions scripts/update-bq.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
/* eslint-disable no-console */

import { BigQuery } from '@google-cloud/bigquery'
import jsonData from '../src/data/mainnet/celo-tokens-info.json'
import { NetworkId } from '../src/types'
import { getTokensInfoByNetworkIds } from '../src/tokens-info'

const bigquery = new BigQuery()

const projectId = 'celo-mobile-mainnet' // we don't index testnet data
const datasetId = 'address_metadata'
const tableId = 'tokens_info'
const fieldsToKeep = ['address', 'decimals', 'name', 'symbol'] as const

const rows = jsonData.map((entry) => {
const row: Record<string, string | number> = {}
fieldsToKeep.forEach((field) => {
row[field] = entry[field]
})
const fieldsToKeep = [
'address',
'decimals',
'name',
'symbol',
'tokenId',
'networkId',
] as const

const tokensInfo = getTokensInfoByNetworkIds([
NetworkId['celo-mainnet'],
NetworkId['ethereum-mainnet'],
])

const rows = Object.entries(tokensInfo).map(([_, tokenInfo]) => {
const row: Record<string, string | number | boolean | null> = {}
fieldsToKeep.forEach((field) => (row[field] = tokenInfo[field] || null))
MuckT marked this conversation as resolved.
Show resolved Hide resolved
return row
})

Expand Down