Skip to content

Commit

Permalink
Instructions for query abstract command
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoAD committed Jan 20, 2022
1 parent c7ed4e3 commit a6a740a
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default class AbstractCommand extends TerraCommand {
help: this.abstractHelp,
}

// TODO: The contract address should come from a specific flag
const address = this.args[0]
return operations[this.opts.action](this.params, address)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,43 @@ export const instructionToCommand = (instruction: AbstractInstruction<any, any>)
}
}
}

export interface InspectInstruction<Input, OnchainData> {
instruction: {
contract: string
function: string
}
inspect: (input: Input, data: OnchainData) => boolean
makeInput: (flags: any) => Promise<Input>
}

export const instructionToInspectCommand = <Input, OnchainData>(
inspectInstruction: InspectInstruction<Input, OnchainData>,
) => {
const id = `${inspectInstruction.instruction.contract}:inspect`
return class Command extends TerraCommand {
static id = id
command: AbstractCommand

constructor(flags, args) {
super(flags, args)
}

execute = async (): Promise<Result<TransactionResponse>> => {
const abstractCommand = await makeAbstractCommand(id, this.flags, this.args)
abstractCommand.invokeMiddlewares(abstractCommand, abstractCommand.middlewares)

const generatedData = await inspectInstruction.makeInput(this.flags)
const { data } = await abstractCommand.execute()
const inspection = inspectInstruction.inspect(generatedData, data)
return {
data: inspection,
responses: [
{
contract: this.args[0],
},
],
} as Result<TransactionResponse>
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { getRDD } from '../../../../lib/rdd'
import { InspectInstruction, instructionToInspectCommand } from '../../../abstract/wrapper'
import { getOffchainConfigInput, OffchainConfig } from '../setConfig'

type Input = {
description: string
decimals: string | number
minAnswer: string | number
maxAnswer: string | number
transmitters: string[]
billingAccessController: string
requesterAccessController: string
link: string
offchainConfig: OffchainConfig
}

type OnchainData = any

const makeInput = async (flags: any): Promise<Input> => {
if (flags.input) return flags.input as Input
const rdd = getRDD(flags.rdd)
const info = rdd.contracts[flags.state]
const aggregatorOperators: string[] = info.oracles.map((o) => o.operator)
const transmitters = aggregatorOperators.map((operator) => rdd.operators[operator].ocrNodeAddress[0])
const billingAccessController = flags.billingAccessController || process.env.BILLING_ACCESS_CONTROLLER
const requesterAccessController = flags.requesterAccessController || process.env.REQUESTER_ACCESS_CONTROLLER
const link = flags.link || process.env.LINK
const offchainConfig = getOffchainConfigInput(rdd, flags.state)
return {
description: info.name,
decimals: info.decimals,
minAnswer: info.minSubmissionValue,
maxAnswer: info.maxSubmissionValue,
transmitters,
billingAccessController,
requesterAccessController,
link,
offchainConfig,
}
}

const inspect = (input: Input, data: OnchainData): boolean => {
console.log(data)
console.log(input)
return true
}

const instruction: InspectInstruction<Input, OnchainData> = {
instruction: {
contract: 'ocr2',
function: '', // latest_config_details
},
makeInput,
inspect,
}

export default instructionToInspectCommand(instruction)
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type OffchainConfig = {
configPublicKeys: string[]
}

const getOffchainConfigInput = (rdd: any, contract: string): OffchainConfig => {
export const getOffchainConfigInput = (rdd: any, contract: string): OffchainConfig => {
const aggregator = rdd.contracts[contract]
const config = aggregator.config

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,29 @@ export default class DeployOCR2Flow extends FlowCommand<TransactionResponse> {
}

this.flow = [
{
name: 'Upload Contracts',
command: UploadContractCode,
},
{
name: 'Deploy LINK',
command: DeployLink,
id: this.stepIds.LINK,
},
{
name: 'Deploy Billing Access Controller',
command: 'access_controller:deploy',
id: this.stepIds.BILLING_ACCESS_CONTROLLER,
},
{
name: 'Deploy Request Access Controller',
command: 'access_controller:deploy',
id: this.stepIds.REQUEST_ACCESS_CONTROLLER,
},
{
name: 'Set environment',
exec: this.setEnvironment,
},
// {
// name: 'Upload Contracts',
// command: UploadContractCode,
// },
// {
// name: 'Deploy LINK',
// command: DeployLink,
// id: this.stepIds.LINK,
// },
// {
// name: 'Deploy Billing Access Controller',
// command: 'access_controller:deploy',
// id: this.stepIds.BILLING_ACCESS_CONTROLLER,
// },
// {
// name: 'Deploy Request Access Controller',
// command: 'access_controller:deploy',
// id: this.stepIds.REQUEST_ACCESS_CONTROLLER,
// },
// {
// name: 'Set environment',
// exec: this.setEnvironment,
// },
{
name: 'Deploy OCR 2',
command: DeployOCR2,
Expand Down
10 changes: 10 additions & 0 deletions packages-ts/gauntlet-terra-contracts/src/lib/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ export const serializeOffchainConfig = async (input: OffchainConfig): Promise<Bu
return Buffer.from(proto.encode('offchainreporting2_config.OffchainConfigProto', offchainConfig))
}

export const deserializeConfig = (buffer: Buffer): any => {
const proto = new Proto.Protobuf({ descriptor: descriptor })
const offchain = proto.decode('offchainreporting2_config.OffchainConfigProto', buffer)
const reportingPluginConfig = proto.decode(
'offchainreporting2_config.ReportingPluginConfig',
offchain.reportingPluginConfig,
)
return { ...offchain, reportingPluginConfig }
}

// constructs a SharedSecretEncryptions from
// a set of SharedSecretEncryptionPublicKeys, the sharedSecret, and a cryptographic randomness source
const generateSecretEncryptions = async (
Expand Down
5 changes: 5 additions & 0 deletions packages-ts/gauntlet-terra-contracts/src/lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ ajv.addFormat('uint64', {
validate: (x) => !isNaN(x),
})

ajv.addFormat('uint32', {
type: 'number',
validate: (x) => !isNaN(x),
})

export default ajv

const jtd = new JTD()
Expand Down

0 comments on commit a6a740a

Please sign in to comment.