Skip to content

Commit

Permalink
feat: queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ericHgorski committed May 8, 2023
1 parent 2848393 commit 927bf2b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 5 deletions.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ npm unlink terrain
* [`terrain deploy CONTRACT`](#terrain-deploy-contract)
* [`terrain help [COMMAND]`](#terrain-help-command)
* [`terrain new NAME`](#terrain-new-name)
* [`terrain query CONTRACT-ADDRESS QUERY`](#terrain-query-contract-address-query)
* [`terrain sync-refs`](#terrain-sync-refs)
* [`terrain task:new [TASK]`](#terrain-tasknew-task)
* [`terrain task:run [TASK]`](#terrain-taskrun-task)
Expand Down Expand Up @@ -599,8 +600,8 @@ Migrate the contract.
```
USAGE
$ terrain contract:migrate [CONTRACT] [--no-rebuild] [--signer <value>] [--network mainnet|testnet|local] [--prefix
juno|terra] [--instance-id <value>] [--code-id <value>] [--config-path <value>] [--refs-path <value>] [--keys-path
$ terrain contract:migrate [CONTRACT] [--no-rebuild] [--instance-id <value>] [--code-id <value>] [--signer <value>]
[--network mainnet|testnet|local] [--prefix juno|terra] [--config-path <value>] [--refs-path <value>] [--keys-path
<value>]
FLAGS
Expand Down Expand Up @@ -816,6 +817,36 @@ EXAMPLES
_See code: [src/commands/new.ts](https://github.com/terra-money/terrain/blob/v0.7.0/src/commands/new.ts)_
## `terrain query CONTRACT-ADDRESS QUERY`
Query contracts on the interchain
```
USAGE
$ terrain query [CONTRACT-ADDRESS] [QUERY] [--signer <value>] [--network mainnet|testnet|local] [--prefix
juno|terra] [--config-path <value>] [--refs-path <value>] [--keys-path <value>]
FLAGS
--config-path=<value> [default: ./config.terrain.json]
--keys-path=<value> [default: ./keys.terrain.js]
--network=<option> [default: local] network to deploy to from config.terrain.json
<options: mainnet|testnet|local>
--prefix=<option> [default: terra] address prefix of target chain
<options: juno|terra>
--refs-path=<value> [default: ./refs.terrain.json]
--signer=<value> [default: test1]
DESCRIPTION
Query contracts on the interchain
EXAMPLES
$ terrain query terra1..fx9fs '{"get_count": {}}'
$ terrain query test '{"get_count": {}}' --network testnet --prefix juno
```
_See code: [src/commands/query.ts](https://github.com/terra-money/terrain/blob/v0.7.0/src/commands/query.ts)_
## `terrain sync-refs`
Sync configuration with frontend app.
Expand Down
4 changes: 2 additions & 2 deletions src/commands/contract/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Command, flags } from '@oclif/command';
import { Command } from '@oclif/command';
import { LCDClient } from '@terra-money/feather.js';
import { loadConfig, loadConnections } from '../../config';
import { migrate, storeCode } from '../../lib/deployment';
Expand All @@ -12,9 +12,9 @@ export default class ContractMigrate extends Command {

static flags = {
'no-rebuild': flag.noRebuild,
...flag.tx,
'instance-id': flag.instanceId,
'code-id': flag.codeId,
...flag.tx,
...flag.terrainPaths,
};

Expand Down
2 changes: 1 addition & 1 deletion src/commands/contract/updateAdmin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Command, flags } from '@oclif/command';
import { Command } from '@oclif/command';
import * as YAML from 'yaml';
import { LCDClient, MsgUpdateContractAdmin } from '@terra-money/feather.js';
import { cli } from 'cli-ux';
Expand Down
45 changes: 45 additions & 0 deletions src/commands/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Command } from '@oclif/command';
import { LCDClient } from '@terra-money/feather.js';
import { loadConnections } from '../config';
import * as flag from '../lib/flag';
import TerrainCLI from '../TerrainCLI';

export default class Query extends Command {
static description = 'Query contracts on the interchain';

static examples = [
'$ terrain query terra1..fx9fs \'{"get_count": {}}\'',
'$ terrain query test \'{"get_count": {}}\' --network testnet --prefix juno',
];

static flags = {
...flag.tx,
...flag.terrainPaths,
};

static args = [{ name: 'contract-address', required: true },
{
name: 'query', required: true, description: 'Query to be performed in JSON format', type: 'string',
}];

async run() {
const { args, flags } = this.parse(Query);

const connections = loadConnections(flags['config-path'], flags.prefix);
const connection = connections(flags.network);
const lcd = new LCDClient({ [connection.chainID]: connection });

try {
const res = await lcd.wasm.contractQuery(args['contract-address'], JSON.parse(args.query));
TerrainCLI.success(`Query Result:\n \n ${JSON.stringify(res)}`);
} catch (error) {
if (error instanceof SyntaxError) {
TerrainCLI.error('There was an error with your query. Make sure you have single quotes around your query and double quotes around query keys.');
// @ts-ignore

Check warning

Code scanning / ESLint

Disallow `@ts-<directive>` comments or require descriptions after directives Warning

Do not use "@ts-ignore" because it alters compilation errors.
} else if (error?.response?.data.message) {
// @ts-ignore

Check warning

Code scanning / ESLint

Disallow `@ts-<directive>` comments or require descriptions after directives Warning

Do not use "@ts-ignore" because it alters compilation errors.
TerrainCLI.error(`There was an error with your query \n\n ${error.response.data.message}`);
}
}
}
}

0 comments on commit 927bf2b

Please sign in to comment.