Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Implemented call_view_function command
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrichina committed May 21, 2019
1 parent 92e60ce commit 056437e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bin/near
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ const scheduleFunctionCall = {
handler: (argv) => exitOnError(main.scheduleFunctionCall(argv))
};

const callViewFunction = {
command: 'call_view_function <contractName> <methodName> [args]',
desc: 'make smart contract call which can view state',
builder: (yargs) => yargs,
handler: (argv) => exitOnError(main.callViewFunction(argv))
};

const { spawn } = require('child_process');
const build = {
command: 'build',
Expand Down Expand Up @@ -111,6 +118,7 @@ yargs // eslint-disable-line
.command(build)
.command(deploy)
.command(scheduleFunctionCall)
.command(callViewFunction)
.command(clean)
.command(newProject)
.config(config)
Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,11 @@ exports.scheduleFunctionCall = async function(options) {
console.log('Result:', await near.waitForTransactionResult(
await near.scheduleFunctionCall(options.amount, options.accountId,
options.contractName, options.methodName, JSON.parse(options.args || '{}'))));
};

exports.callViewFunction = async function(options) {
console.log(`View call: ${options.contractName}.${options.methodName}(${options.args || ''})`);
const near = await connect(options);
console.log('Result:', await near.waitForTransactionResult(
await near.callViewFunction(options.contractName, options.methodName, JSON.parse(options.args || '{}'))));
};

0 comments on commit 056437e

Please sign in to comment.