Skip to content

Commit

Permalink
Revert "fix: add detail param, default to no detail"
Browse files Browse the repository at this point in the history
This reverts commit 79ebec7.
  • Loading branch information
nick-bisonai committed Feb 7, 2024
1 parent 79ebec7 commit 7e8fae2
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 104 deletions.
2 changes: 1 addition & 1 deletion cli/src/datafeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function bulkRemoveHandler() {

const listeners = await listenerListHandler()({})
const reporters = await reporterListHandler()({})
const delegatorReporters = await delegatorReporterListHandler()({})
const delegatorReporters = await delegatorReporterListHandler()()
const delegatorContracts = await contractListHandler()()
const delegatorFunctions = await functionListHandler()()

Expand Down
44 changes: 20 additions & 24 deletions cli/src/delegator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import { command, number as cmdnumber, option, string as cmdstring, subcommands } from 'cmd-ts'
import { ORAKL_NETWORK_API_URL, ORAKL_NETWORK_DELEGATOR_URL } from './settings'
import { buildUrl, detailOptionalOption, idOption, isOraklDelegatorHealthy } from './utils'
import { buildUrl, idOption, isOraklDelegatorHealthy } from './utils'

const AGGREGATOR_ENDPOINT = buildUrl(ORAKL_NETWORK_API_URL, 'aggregator')

Expand Down Expand Up @@ -70,7 +70,7 @@ export function delegatorSub() {

const reporterList = command({
name: 'reporterList',
args: { detail: detailOptionalOption },
args: {},
handler: reporterListHandler()
})

Expand Down Expand Up @@ -292,38 +292,34 @@ export function organizationRemoveHandler() {
}

export function reporterListHandler() {
async function wrapper({ detail }: { detail?: string }) {
async function wrapper() {
if (!(await isOraklDelegatorHealthy())) return

try {
const endpoint = buildUrl(ORAKL_NETWORK_DELEGATOR_URL, `reporter`)
const result = (await axios.get(endpoint)).data

if (detail && detail?.toLowerCase() === 'true') {
const printResult: any[] = []
const aggregatorUrl = new URL(AGGREGATOR_ENDPOINT)
const aggregatorResult = (await axios.get(aggregatorUrl.toString())).data
for (const reporter of result) {
if (!reporter.contract) {
printResult.push({ ...reporter })
continue
}

const aggregator = aggregatorResult.find(
(aggregator) => aggregator.address === reporter.contract[0]
)
if (aggregator) {
printResult.push({ ...reporter, name: aggregator.name })
} else {
printResult.push({ ...reporter })
}
const printResult: any[] = []
const aggregatorUrl = new URL(AGGREGATOR_ENDPOINT)
const aggregatorResult = (await axios.get(aggregatorUrl.toString())).data

for (const reporter of result) {
if (!reporter.contract) {
printResult.push({ ...reporter })
continue
}

console.log(printResult)
} else {
console.log(result)
const aggregator = aggregatorResult.find(
(aggregator) => aggregator.address === reporter.contract[0]
)
if (aggregator) {
printResult.push({ ...reporter, name: aggregator.name })
} else {
printResult.push({ ...reporter })
}
}

console.log(printResult)
return result
} catch (e) {
console.error('Delegator Reporter was not listed. Reason:')
Expand Down
52 changes: 19 additions & 33 deletions cli/src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { LISTENER_SERVICE_HOST, LISTENER_SERVICE_PORT, ORAKL_NETWORK_API_URL } f
import {
buildUrl,
chainOptionalOption,
detailOptionalOption,
idOption,
isOraklNetworkApiHealthy,
isServiceHealthy,
Expand All @@ -26,8 +25,7 @@ export function listenerSub() {
name: 'list',
args: {
chain: chainOptionalOption,
service: serviceOptionalOption,
detail: detailOptionalOption
service: serviceOptionalOption
},
handler: listHandler(true)
})
Expand Down Expand Up @@ -123,45 +121,33 @@ export function listenerSub() {
}

export function listHandler(print?: boolean) {
async function wrapper({
chain,
service,
detail
}: {
chain?: string
service?: string
detail?: string
}) {
async function wrapper({ chain, service }: { chain?: string; service?: string }) {
if (!(await isOraklNetworkApiHealthy())) return

try {
const result = (await axios.get(LISTENER_ENDPOINT, { data: { chain, service } }))?.data

const printResult: any[] = []
const aggregatorUrl = new URL(AGGREGATOR_ENDPOINT)
const aggregatorResult = (await axios.get(aggregatorUrl.toString())).data
if (print) {
if (detail && detail?.toLowerCase() === 'true') {
const printResult: any[] = []
const aggregatorUrl = new URL(AGGREGATOR_ENDPOINT)
const aggregatorResult = (await axios.get(aggregatorUrl.toString())).data
for (const listener of result) {
if (listener.service != 'DATA_FEED') {
printResult.push({ ...listener })
continue
}

const aggregator = aggregatorResult.find(
(aggregator) => aggregator.address === listener.address
)
if (aggregator) {
printResult.push({ ...listener, name: aggregator.name })
} else {
printResult.push({ ...listener })
}
for (const listener of result) {
if (listener.service != 'DATA_FEED') {
printResult.push({ ...listener })
continue
}

console.dir(printResult, { depth: null })
} else {
console.dir(result, { depth: null })
const aggregator = aggregatorResult.find(
(aggregator) => aggregator.address === listener.address
)
if (aggregator) {
printResult.push({ ...listener, name: aggregator.name })
} else {
printResult.push({ ...listener })
}
}

console.dir(printResult, { depth: null })
}
return result
} catch (e) {
Expand Down
52 changes: 19 additions & 33 deletions cli/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { command, option, string as cmdstring, subcommands } from 'cmd-ts'
import {
buildUrl,
chainOptionalOption,
detailOptionalOption,
idOption,
isOraklNetworkApiHealthy,
isServiceHealthy,
Expand All @@ -28,8 +27,7 @@ export function reporterSub() {
name: 'list',
args: {
chain: chainOptionalOption,
service: serviceOptionalOption,
detail: detailOptionalOption
service: serviceOptionalOption
},
handler: listHandler(true)
})
Expand Down Expand Up @@ -146,45 +144,33 @@ export function reporterSub() {
}

export function listHandler(print?: boolean) {
async function wrapper({
chain,
service,
detail
}: {
chain?: string
service?: string
detail?: string
}) {
async function wrapper({ chain, service }: { chain?: string; service?: string }) {
if (!(await isOraklNetworkApiHealthy())) return

try {
const result = (await axios.get(REPORTER_ENDPOINT, { data: { chain, service } }))?.data

const printResult: any[] = []
const aggregatorUrl = new URL(AGGREGATOR_ENDPOINT)
const aggregatorResult = (await axios.get(aggregatorUrl.toString())).data
if (print) {
if (detail && detail.toLowerCase() === 'true') {
const printResult: any[] = []
const aggregatorUrl = new URL(AGGREGATOR_ENDPOINT)
const aggregatorResult = (await axios.get(aggregatorUrl.toString())).data
for (const reporter of result) {
if (reporter.service != 'DATA_FEED') {
printResult.push({ ...reporter })
continue
}

const aggregator = aggregatorResult.find(
(aggregator) => aggregator.address === reporter.oracleAddress
)
if (aggregator) {
printResult.push({ ...reporter, name: aggregator.name })
} else {
printResult.push({ ...reporter })
}
for (const reporter of result) {
if (reporter.service != 'DATA_FEED') {
printResult.push({ ...reporter })
continue
}

console.dir(printResult, { depth: null })
} else {
console.dir(result, { depth: null })
const aggregator = aggregatorResult.find(
(aggregator) => aggregator.address === reporter.oracleAddress
)
if (aggregator) {
printResult.push({ ...reporter, name: aggregator.name })
} else {
printResult.push({ ...reporter })
}
}

console.dir(printResult, { depth: null })
}
return result
} catch (e) {
Expand Down
5 changes: 0 additions & 5 deletions cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import { number as cmdnumber, option, optional, string as cmdstring } from 'cmd-
import { open as openFile, readFile } from 'node:fs/promises'
import { ORAKL_NETWORK_API_URL, ORAKL_NETWORK_DELEGATOR_URL } from './settings'

export const detailOptionalOption = option({
type: optional(cmdstring),
long: 'detail'
})

export const chainOptionalOption = option({
type: optional(cmdstring),
long: 'chain'
Expand Down
16 changes: 8 additions & 8 deletions cli/test/datafeed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('CLI datafeed', function () {
afterEach(async () => {
const afterAdapterList = await adapterListHandler()()
const afterAggregatorList = await aggregatorListHandler()({})
const afterDelegatorReporterList = await delegatorReporterListHandler()({})
const afterDelegatorReporterList = await delegatorReporterListHandler()()
const afterContractList = await contractListHandler()()
const afterListenerList = await listenerListHandler()({})
const afterReporterList = await reporterListHandler()({})
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('CLI datafeed', function () {
test('datafeed bulk insert with default values', async function () {
const beforeAdapterList = await adapterListHandler()()
const beforeAggregatorList = await aggregatorListHandler()({})
const beforeDelegatorReporterList = await delegatorReporterListHandler()({})
const beforeDelegatorReporterList = await delegatorReporterListHandler()()
const beforeContractList = await contractListHandler()()
const beforeListenerList = await listenerListHandler()({})
const beforeReporterList = await reporterListHandler()({})
Expand All @@ -111,7 +111,7 @@ describe('CLI datafeed', function () {

const afterAdapterList = await adapterListHandler()()
const afterAggregatorList = await aggregatorListHandler()({})
const afterDelegatorReporterList = await delegatorReporterListHandler()({})
const afterDelegatorReporterList = await delegatorReporterListHandler()()
const afterContractList = await contractListHandler()()
const afterListenerList = await listenerListHandler()({})
const afterReporterList = await reporterListHandler()({})
Expand All @@ -131,7 +131,7 @@ describe('CLI datafeed', function () {
test('datafeed bulk insert', async function () {
const beforeAdapterList = await adapterListHandler()()
const beforeAggregatorList = await aggregatorListHandler()({})
const beforeDelegatorReporterList = await delegatorReporterListHandler()({})
const beforeDelegatorReporterList = await delegatorReporterListHandler()()
const beforeContractList = await contractListHandler()()
const beforeListenerList = await listenerListHandler()({})
const beforeReporterList = await reporterListHandler()({})
Expand All @@ -143,7 +143,7 @@ describe('CLI datafeed', function () {

const afterAdapterList = await adapterListHandler()()
const afterAggregatorList = await aggregatorListHandler()({})
const afterDelegatorReporterList = await delegatorReporterListHandler()({})
const afterDelegatorReporterList = await delegatorReporterListHandler()()
const afterContractList = await contractListHandler()()
const afterListenerList = await listenerListHandler()({})
const afterReporterList = await reporterListHandler()({})
Expand All @@ -163,7 +163,7 @@ describe('CLI datafeed', function () {
test('datafeed bulk removal', async function () {
const beforeAdapterList = await adapterListHandler()()
const beforeAggregatorList = await aggregatorListHandler()({})
const beforeDelegatorReporterList = await delegatorReporterListHandler()({})
const beforeDelegatorReporterList = await delegatorReporterListHandler()()
const beforeContractList = await contractListHandler()()
const beforeListenerList = await listenerListHandler()({})
const beforeReporterList = await reporterListHandler()({})
Expand All @@ -175,7 +175,7 @@ describe('CLI datafeed', function () {

const afterAdapterList = await adapterListHandler()()
const afterAggregatorList = await aggregatorListHandler()({})
const afterDelegatorReporterList = await delegatorReporterListHandler()({})
const afterDelegatorReporterList = await delegatorReporterListHandler()()
const afterContractList = await contractListHandler()()
const afterListenerList = await listenerListHandler()({})
const afterReporterList = await reporterListHandler()({})
Expand All @@ -193,7 +193,7 @@ describe('CLI datafeed', function () {

await bulkRemoveHandler()({ data: DATAFEED_BULK_0 })

const afterDeleteDelegatorReporterList = await delegatorReporterListHandler()({})
const afterDeleteDelegatorReporterList = await delegatorReporterListHandler()()
const afterDeleteContractList = await contractListHandler()()
const afterDeleteListenerList = await listenerListHandler()({})
const afterDeleteReporterList = await reporterListHandler()({})
Expand Down

0 comments on commit 7e8fae2

Please sign in to comment.