Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add deposit yocto #822

Merged
merged 2 commits into from Jul 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions commands/call.js
Expand Up @@ -19,6 +19,11 @@ module.exports = {
default: '0',
alias: 'amount'
})
.option('depositYocto', {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we should add a separate option here.
And we definitely should not use it as a flag.
@mikedotexe I do not understand the motivation in your comment here: #751 (comment)

I would say, that we need to design it the next way:
near call ... ... --deposit 000000001 it would be in N, for backward compatibility + deprecation warning.
near call ... ... deposit 1N
near call ... ... deposit 1yN for deposit in yoctoNEAR

If we know for sure that deposit is always in yoctoNEAR, then let's do it the next way:
near call ... ... --depositYocto 1 + add deprecation warning for --deposit
This one will be less flexible.

+, if we will have --deposit and --depositYocto at the same time we should not allow to specify them both (there is a conflicting functionality in yargs).

@ChaoticTempest please, provide an example of this option usage in the description.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PR description or somewhere else?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's put it there :)

desc: 'Number of tokens to attach (in yocto NEAR) to a function call',
type: 'string',
default: null,
})
.option('base64', {
desc: 'Treat arguments as base64-encoded BLOB.',
type: 'boolean',
Expand All @@ -39,8 +44,10 @@ module.exports = {

async function scheduleFunctionCall(options) {
await checkCredentials(options.accountId, options.networkId, options.keyStore);
const deposit = options.depositYocto != null ? options.depositYocto : utils.format.parseNearAmount(options.deposit);
console.log(`Scheduling a call: ${options.contractName}.${options.methodName}(${options.args || ''})` +
(options.deposit && options.deposit != '0' ? ` with attached ${options.deposit} NEAR` : ''));
(deposit && deposit != '0' ? ` with attached ${utils.format.formatNearAmount(deposit)} NEAR` : ''));

const near = await connect(options);
const account = await near.account(options.accountId);
const parsedArgs = options.base64 ? Buffer.from(options.args, 'base64') : JSON.parse(options.args || '{}');
Expand All @@ -49,7 +56,7 @@ async function scheduleFunctionCall(options) {
methodName: options.methodName,
args: parsedArgs,
gas: options.gas,
attachedDeposit: utils.format.parseNearAmount(options.deposit),
attachedDeposit: deposit,
});
const result = providers.getTransactionLastResult(functionCallResponse);
inspectResponse.prettyPrintResponse(functionCallResponse, options);
Expand Down