From 056437e79d30b62cd07e3a1ed3a67b2f291c679e Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Tue, 21 May 2019 00:21:26 -0700 Subject: [PATCH] Implemented call_view_function command --- bin/near | 8 ++++++++ index.js | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/bin/near b/bin/near index f577c086..a6ed452c 100755 --- a/bin/near +++ b/bin/near @@ -34,6 +34,13 @@ const scheduleFunctionCall = { handler: (argv) => exitOnError(main.scheduleFunctionCall(argv)) }; +const callViewFunction = { + command: 'call_view_function [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', @@ -111,6 +118,7 @@ yargs // eslint-disable-line .command(build) .command(deploy) .command(scheduleFunctionCall) + .command(callViewFunction) .command(clean) .command(newProject) .config(config) diff --git a/index.js b/index.js index 578969ee..0bad3be5 100755 --- a/index.js +++ b/index.js @@ -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 || '{}')))); }; \ No newline at end of file