8000 Fix bug with `near call` passing --amount as gas by vgrichina · Pull Request #229 · near/near-cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

Fix bug with near call passing --amount as gas #229

Merged
merged 3 commits into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions bin/near-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,6 @@ const deploy = {
handler: exitOnError(main.deploy)
};

const scheduleFunctionCall = {
command: 'call <contractName> <methodName> [args]',
desc: 'schedule smart contract call which can modify state',
builder: (yargs) => yargs
.option('amount', {
desc: 'Number of tokens to attach',
type: 'string',
default: '0.0000000001'
}),
handler: exitOnError(main.scheduleFunctionCall)
};

const callViewFunction = {
command: 'view <contractName> <methodName> [args]',
desc: 'make smart contract call which can view state',
Expand Down Expand Up @@ -188,7 +176,7 @@ yargs // eslint-disable-line
.command(require('../commands/tx-status'))
.command(build)
.command(deploy)
.command(scheduleFunctionCall)
.command(require('../commands/call'))
.command(callViewFunction)
.command(sendMoney)
.command(clean)
Expand Down
37 changes: 37 additions & 0 deletions commands/call.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const nearlib = require('nearlib');
const { utils } = nearlib;
const exitOnError = require('../utils/exit-on-error');
const connect = require('../utils/connect');
const inspectResponse = require('../utils/inspect-response');

module.exports = {
command: 'call <contractName> <methodName> [args]',
desc: 'schedule smart contract call which can modify state',
builder: (yargs) => yargs
.option('gas', {
desc: 'Max amount of gas this call can use',
type: 'string',
default: '100000000000000'
})
.option('amount', {
desc: 'Number of tokens to attach',
type: 'string',
default: '0'
}),
handler: exitOnError(scheduleFunctionCall)
};

async function scheduleFunctionCall(options) {
console.log(`Scheduling a call: ${options.contractName}.${options.methodName}(${options.args || ''})` +
(options.amount && options.amount != '0' ? ` with attached ${utils.format.parseNearAmount(options.amount)} NEAR` : ''));
const near = await connect(options);
const account = await near.account(options.accountId);
const functionCallResponse = await account.functionCall(
options.contractName,
options.methodName,
JSON.parse(options.args || '{}'),
options.gas,
utils.format.parseNearAmount(options.amount));
const result = nearlib.providers.getTransactionLastResult(functionCallResponse);
console.log(inspectResponse(result));
}
15 changes: 0 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const rimraf = require('rimraf');
const readline = require('readline');
const URL = require('url').URL;

const nearjs = require('nearlib');
const { KeyPair, keyStores, utils } = require('nearlib');
const UnencryptedFileSystemKeyStore = keyStores.UnencryptedFileSystemKeyStore;

Expand Down Expand Up @@ -36,20 +35,6 @@ exports.deploy = async function(options) {
await account.deployContract(contractData);
};

exports.scheduleFunctionCall = async function(options) {
console.log(`Scheduling a call: ${options.contractName}.${options.methodName}(${options.args || ''})` +
(options.amount ? ` with attached ${utils.format.parseNearAmount(options.amount)} NEAR` : ''));
const near = await connect(options);
const account = await near.account(options.accountId);
const functionCallResponse = await account.functionCall(
options.contractName,
options.methodName,
JSON.parse(options.args || '{}'),
utils.format.parseNearAmount(options.amount));
const result = nearjs.providers.getTransactionLastResult(functionCallResponse);
console.log(inspectResponse(result));
};

exports.callViewFunction = async function(options) {
console.log(`View call: ${options.contractName}.${options.methodName}(${options.args || ''})`);
const near = await connect(options);
Expand Down
0