From 7c11ce35293822a66865779903f6334c39ba2275 Mon Sep 17 00:00:00 2001 From: trevorjtclarke Date: Tue, 15 Feb 2022 14:00:16 -0800 Subject: [PATCH 1/3] added new arg base64file to support loading base64 blob from file into CLI args --- README.md | 1 + commands/call.js | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43d621e2..2fb0b730 100644 --- a/README.md +++ b/README.md @@ -1312,6 +1312,7 @@ With NEAR REPL you have complete access to [`near-api-js`](https://github.com/ne | `--contractName` | Account name of contract [string] | | `--masterAccount` | Master account used when creating new accounts [string] | | `--helperAccount` | Expected top-level account for a network [string] | +| `--base64file` | Load a base64-encoded BLOB file into the args sent to a function call [string] | | `-v, --verbose` | Prints out verbose output [boolean] [default: false] | |`-f, --force` | Forcefully execute the desired action even if it is unsafe to do so [boolean] [default: false]| diff --git a/commands/call.js b/commands/call.js index 35cb6234..b03f1a6c 100644 --- a/commands/call.js +++ b/commands/call.js @@ -1,3 +1,4 @@ +const { readFileSync } = require('fs'); const { DEFAULT_FUNCTION_CALL_GAS, providers, utils } = require('near-api-js'); const exitOnError = require('../utils/exit-on-error'); const connect = require('../utils/connect'); @@ -39,6 +40,11 @@ module.exports = { required: true, desc: 'Unique identifier for the account that will be used to sign this call', type: 'string' + }) + .option('base64file', { + desc: 'Load a base64-encoded BLOB file into the args sent to a function call.', + type: 'string', + default: false }), handler: exitOnError(scheduleFunctionCall) }; @@ -51,7 +57,19 @@ async function scheduleFunctionCall(options) { 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 || '{}'); + let parsedArgs; + // load args rare order first + if (options.base64file) { + try { + let fileargs = await readFileSync(options.base64file); + parsedArgs = Buffer.from(fileargs, 'base64'); + console.log(`Loaded base64 args file, size ${parsedArgs.length}`); + } catch (e) { + console.log('Could not load base64 file!'); + } + } + if (!parsedArgs && options.base64) parsedArgs = Buffer.from(readFileSync(options.args), 'base64'); + if (!parsedArgs) parsedArgs = JSON.parse(options.args || '{}'); console.log('Doing account.functionCall()'); try { const functionCallResponse = await account.functionCall({ From c3810575b5c3daf6bd27f4d71345a507c5f17b00 Mon Sep 17 00:00:00 2001 From: trevorjtclarke Date: Tue, 15 Feb 2022 15:14:36 -0800 Subject: [PATCH 2/3] Throw upon failed file load --- commands/call.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/call.js b/commands/call.js index b03f1a6c..77cc7435 100644 --- a/commands/call.js +++ b/commands/call.js @@ -65,7 +65,7 @@ async function scheduleFunctionCall(options) { parsedArgs = Buffer.from(fileargs, 'base64'); console.log(`Loaded base64 args file, size ${parsedArgs.length}`); } catch (e) { - console.log('Could not load base64 file!'); + throw new Error('Could not load base64 file!'); } } if (!parsedArgs && options.base64) parsedArgs = Buffer.from(readFileSync(options.args), 'base64'); From 913914edf401ba8204e1e185e70768201a4fa7e5 Mon Sep 17 00:00:00 2001 From: trevorjtclarke Date: Thu, 17 Feb 2022 10:10:53 -0800 Subject: [PATCH 3/3] Trigger travis