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

impr: delphioracle upsert #5

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .env-sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DATABASE_URL=postgres://user:pass@localhost:5432/chaingraph?sslmode=disable
WS_URL=ws://127.0.0.1:8080
RPC_URL=http://127.0.0.1:8888
RPC_URL=<http://127.0.0.1:8888>
DELPHIORACLE_PRODUCERS=eosiodetroit,criptolions1,ivote4eosusa,eostitanprod,alohaeosprod,teamgreymass
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"@blockmatic/eosio-ship-reader": "^0.5.0",
"@eoscafe/hyperion": "^3.3.2",
"@eosrio/node-abieos": "^2.1.1",
"@greymass/eosio": "^0.6.4",
"@wharfkit/antelope": "^0.10.0",
"@greymass/eosio": "^0.7.0",
"@wharfkit/antelope": "^1.0.7",
"bluebird": "^3.7.2",
"eos-common": "^0.8.1",
"isomorphic-fetch": "^3.0.0",
Expand Down
2 changes: 2 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ export interface EosioReaderConfig {

export interface Config {
database_url: string
delphioracle_producers: string[]
hyperion_url: string
reader: EosioReaderConfig
}

export const config: Config = {
database_url: env.get('DATABASE_URL').required().asString(),
delphioracle_producers: env.get('DELPHIORACLE_PRODUCERS').required().asArray(),
reader: {
chain: 'eos',
chain_id:
Expand Down
47 changes: 28 additions & 19 deletions src/database/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { logger } from '../lib/logger'
import {
ChainGraphAction,
ChainGraphBlock,
ChainGraphTableRow,
ChainGraphTransaction,
} from '../types'
import { db } from './db'
import {
createDeleteTableRowsQuery,
Expand All @@ -7,35 +12,39 @@ import {
createUpsertTableRowsQuery,
createUpsertTransactionsQuery,
} from './queries'
import {
ChainGraphAction,
ChainGraphBlock,
ChainGraphTableRow,
ChainGraphTransaction,
} from '../types'

export * from './db'

const runQuery = async (query: string) => {
logger.info(query)
// logger.info(query)
return db.none(query)
}

export const upsertBlocks = async (blocks: ChainGraphBlock[]) =>
runQuery(createUpsertBlocksQuery(blocks))
export const upsertBlocks = async (blocks: ChainGraphBlock[]) => {
if (!blocks.length) return Promise.resolve()
return runQuery(createUpsertBlocksQuery(blocks))
}

export const upsertTableRows = async (tableRows: ChainGraphTableRow[]) =>{
console.log('upsertTableRows', tableRows)
runQuery(createUpsertTableRowsQuery(tableRows))}
export const upsertTableRows = async (tableRows: ChainGraphTableRow[]) => {
// console.log('upsertTableRows', tableRows)
if (!tableRows.length) return Promise.resolve()
return runQuery(createUpsertTableRowsQuery(tableRows))
}

export const deleteTableRows = async (tableRows: ChainGraphTableRow[]) =>
runQuery(createDeleteTableRowsQuery(tableRows))
export const deleteTableRows = async (tableRows: ChainGraphTableRow[]) => {
if (!tableRows.length) return Promise.resolve()
return runQuery(createDeleteTableRowsQuery(tableRows))
}

export const upsertTransactions = async (
transactions: ChainGraphTransaction[],
) => runQuery(createUpsertTransactionsQuery(transactions))
) => {
if (!transactions.length) return Promise.resolve()
return runQuery(createUpsertTransactionsQuery(transactions))
}

export const upsertActions = async (actions: ChainGraphAction[]) =>{
console.log('upsertActions', actions)
runQuery(createUpsertActionsQuery(actions))
export const upsertActions = async (actions: ChainGraphAction[]) => {
// console.log('upsertActions', actions)
if (!actions.length) return Promise.resolve()
return runQuery(createUpsertActionsQuery(actions))
}
20 changes: 8 additions & 12 deletions src/indexer/load-history.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { logger } from '../lib/logger'
import uniqBy from 'lodash.uniqby'
import pThrottle from 'p-throttle'
import { whilst } from '../lib/promises'
import { MappingsReader } from '../mappings'
import { config } from '../config'
import { upsertActions, upsertBlocks, upsertTransactions } from '../database'
import { HyperionAction, hyperion } from '../lib/hyperion'
import { logger } from '../lib/logger'
import { whilst } from '../lib/promises'
import {
ChainGraphAction,
ChainGraphActionWhitelist,
ChainGraphBlock,
ChainGraphTransaction,
} from '../types'
import { hyperion, HyperionAction } from '../lib/hyperion'
import { config } from '../config'
import { WhitelistReader } from '../whitelist'

type UpsertCollections = {
Expand Down Expand Up @@ -112,9 +111,7 @@ export const loadActionHistory = async (account: string, filter: string) => {
})

const loadHyperionPages = async () => {
const filter_page = `filter: ${account}:${filter}, limit: ${hyperionPageSize}, skip: ${
hyperionPageSize * page
}, page ${page}`
const filter_page = `filter: ${account}:${filter}, limit: ${hyperionPageSize}, skip: ${hyperionPageSize * page}, page ${page}`
logger.info(`Loading action history from Hyperion for ${filter_page}`)

try {
Expand All @@ -128,8 +125,7 @@ export const loadActionHistory = async (account: string, filter: string) => {
morePages = false
return false
} catch (error) {
logger.error(error)
logger.info('hyperion request failed')
logger.error('Hyperion request failed: ', error)
return process.exit(0) // keep trying
}
}
Expand All @@ -146,7 +142,7 @@ export const loadHistory = async (whitelistReader: WhitelistReader) => {
.map(({ contract: code, actions }) => {
// if wildcard we need reformat for hyperion
if (actions[0] === '*') return [{ code, action: '*' }]

return (actions as ChainGraphActionWhitelist[]).map(({ action }) => {
return {
code,
Expand All @@ -157,7 +153,7 @@ export const loadHistory = async (whitelistReader: WhitelistReader) => {
.flat()

await Promise.all(
actionFilters.map(async ({action, code}) => loadActionHistory(code, action),
actionFilters.map(async ({ action, code }) => loadActionHistory(code, action),
),
)
} catch (error) {
Expand Down
Loading