-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2848393
commit 927bf2b
Showing
4 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
} | ||
} | ||
} |