From fbd5ecb985b6114e45ca20913480802026e058aa Mon Sep 17 00:00:00 2001 From: potatodepaulo Date: Tue, 28 May 2019 10:19:17 -0700 Subject: [PATCH 01/12] update nearlib to 0.7.1 in blank project --- blank_project/src/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blank_project/src/index.html b/blank_project/src/index.html index 62185654..53488562 100755 --- a/blank_project/src/index.html +++ b/blank_project/src/index.html @@ -10,7 +10,7 @@ Contract says:

- + From 6d9c4136035db3520dc0f6eafe6a520802368393 Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Tue, 4 Jun 2019 11:05:01 -0700 Subject: [PATCH 02/12] Nearlib 0.8 --- blank_project/src/index.html | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/blank_project/src/index.html b/blank_project/src/index.html index 62185654..6eb6202e 100755 --- a/blank_project/src/index.html +++ b/blank_project/src/index.html @@ -10,7 +10,7 @@ Contract says:

- + diff --git a/package.json b/package.json index ae85bc42..8582bae8 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "assemblyscript": "github:nearprotocol/assemblyscript", "jest-environment-node": "^24.5.0", "ncp": "^2.0.0", - "nearlib": "^0.7.3", + "nearlib": "^0.8", "rimraf": "^2.6.3", "yargs": "^13.2.1" }, From 8da5fa078b0dc0bde63433711f85d7ceaea0d934 Mon Sep 17 00:00:00 2001 From: potatodepaulo Date: Tue, 4 Jun 2019 12:02:51 -0700 Subject: [PATCH 03/12] change calls to use positional arguments over flags --- README.md | 5 +++-- bin/near | 4 ++-- get-config.js | 2 +- gulp-utils.js | 1 + gulpfile.js | 30 ++++++++++++++++++++++++++++++ index.js | 14 +++++++------- test/new_project.sh | 18 +++++++++++++++--- 7 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 gulpfile.js diff --git a/README.md b/README.md index e5c7c7fc..2d158f4b 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,9 @@ near ``` ### Commands: ```Bash - near create_account # create a developer account - near deploy # deploy your smart contract + near create_account # create a developer account + near new_project [dir] + near deploy # deploy your smart contract near call [args] # submits transaction, can change state, account required near view [args] # cannot change state, account is contract name ``` diff --git a/bin/near b/bin/near index a09472a1..62e5ad67 100755 --- a/bin/near +++ b/bin/near @@ -60,7 +60,7 @@ const build = { }; const createAccount = { - command: 'create_account', + command: 'create_account ', desc: 'create a developer account', builder: (yargs) => yargs .option('accountId', { @@ -84,7 +84,7 @@ const clean = { }; const newProject = { - command: 'new_project', + command: 'new_project [projectDir]', desc: 'create a new blank project', builder: (yargs) => yargs .option('projectDir', { diff --git a/get-config.js b/get-config.js index 07c9d4db..a77b293e 100644 --- a/get-config.js +++ b/get-config.js @@ -1,6 +1,6 @@ module.exports = function getConfig() { - const configPath = process.cwd() + '/src/config'; + const configPath = process.cwd() + '/src/config.js'; try { return require(configPath)(process.env.NODE_ENV || 'development'); } catch (e) { diff --git a/gulp-utils.js b/gulp-utils.js index 0f50ece6..b1018e23 100644 --- a/gulp-utils.js +++ b/gulp-utils.js @@ -1,3 +1,4 @@ +// FUTURE PEOPLE: This file is called "gulp-utils" but it's not related to the deprecated library called "gulp-utils". Don't panic. function generateBindings(inputFile, outputFile, callback) { const asc = getAsc(); asc.main([ diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 00000000..024cd8ef --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,30 @@ +const gulp = require("gulp"); +const nearUtils = require("near-shell/gulp-utils"); + +gulp.task("build:model", callback => { + nearUtils.generateBindings("model.ts", "../out/model.near.ts", callback); +}); + +gulp.task("build:bindings", ["build:model"], callback => { + nearUtils.generateBindings("main.ts", "../out/main.near.ts", callback); +}); + +gulp.task("build", ["build:bindings"], callback => { + nearUtils.compile("../out/main.near.ts", "../out/main.wasm", callback); +}); + +gulp.task("default", ["build"]); + +// TODO: Extract all following boilerplate into library + +// This task is not required when running the project locally. Its purpose is to set up the +// AssemblyScript compiler when a new project has been loaded in WebAssembly Studio. +gulp.task("project:load", () => { + const utils = require("@wasm/studio-utils"); + utils.eval(utils.project.getFile("setup.js").getData(), { + logLn, + project, + monaco, + fileTypeForExtension, + }); +}); diff --git a/index.js b/index.js index 26b976f8..aafcc11e 100755 --- a/index.js +++ b/index.js @@ -10,14 +10,14 @@ ncp.limit = 16; // TODO: Fix promisified wrappers to handle error properly -exports.newProject = async function() { +exports.newProject = async function(options) { // Need to wait for the copy to finish, otherwise next tasks do not find files. - const projectDir = yargs.argv.projectDir; + const projectDir = options.projectDir; const sourceDir = __dirname + "/blank_project"; console.log(`Copying files to new project directory (${projectDir}) from template source (${sourceDir}).`); const copyDirFn = () => { return new Promise(resolve => { - ncp (sourceDir, yargs.argv.projectDir, response => resolve(response)); + ncp (sourceDir, options.projectDir, response => resolve(response)); })}; await copyDirFn(); console.log('Copying project files complete.') @@ -35,7 +35,7 @@ exports.clean = async function() { // Only works for dev environments exports.createDevAccount = async function(options) { const keyPair = await KeyPair.fromRandomSeed(); - + let accountId = options.accountId; options.useDevAccount = true; options.deps = { keyStore: new InMemoryKeyStore(), @@ -43,10 +43,10 @@ exports.createDevAccount = async function(options) { }; await neardev.connect(options); - await options.deps.createAccount(options.accountId, keyPair.getPublicKey()); + await options.deps.createAccount(accountId, keyPair.getPublicKey()); const keyStore = new UnencryptedFileSystemKeyStore('./', options.networkId); - keyStore.setKey(options.accountId, keyPair); - console.log("Create account complete."); + keyStore.setKey(accountId, keyPair); + console.log("Create account complete for " + accountId); }; async function connect(options) { diff --git a/test/new_project.sh b/test/new_project.sh index ee5db1b4..6182f28c 100755 --- a/test/new_project.sh +++ b/test/new_project.sh @@ -1,10 +1,22 @@ #!/bin/sh set -ex -rm -rf tmp-project +# remove temporary blank project +rm -rf test/tmp-project +cd test/ +# test generating new project in cwd mkdir tmp-project cd tmp-project -../bin/near new_project +../../bin/near new_project npm install npm uninstall near-shell -npm install ../ +npm install ../../ NODE_ENV=development npm run test +cd .. +rm -rf tmp-project +# test generating new project in new dir +../bin/near new_project 'tmp-project' +cd tmp-project +npm install +npm uninstall near-shell +npm install ../../ +NODE_ENV=development npm run test \ No newline at end of file From 56ae73a57cfcbc6afc4fec150e2fc8f06626fdc9 Mon Sep 17 00:00:00 2001 From: potatodepaulo Date: Tue, 4 Jun 2019 13:46:07 -0700 Subject: [PATCH 04/12] delete generated gulpfile --- gulpfile.js | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 gulpfile.js diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 024cd8ef..00000000 --- a/gulpfile.js +++ /dev/null @@ -1,30 +0,0 @@ -const gulp = require("gulp"); -const nearUtils = require("near-shell/gulp-utils"); - -gulp.task("build:model", callback => { - nearUtils.generateBindings("model.ts", "../out/model.near.ts", callback); -}); - -gulp.task("build:bindings", ["build:model"], callback => { - nearUtils.generateBindings("main.ts", "../out/main.near.ts", callback); -}); - -gulp.task("build", ["build:bindings"], callback => { - nearUtils.compile("../out/main.near.ts", "../out/main.wasm", callback); -}); - -gulp.task("default", ["build"]); - -// TODO: Extract all following boilerplate into library - -// This task is not required when running the project locally. Its purpose is to set up the -// AssemblyScript compiler when a new project has been loaded in WebAssembly Studio. -gulp.task("project:load", () => { - const utils = require("@wasm/studio-utils"); - utils.eval(utils.project.getFile("setup.js").getData(), { - logLn, - project, - monaco, - fileTypeForExtension, - }); -}); From d020ca18dc86580ec999d6d7e5350f1378acfa93 Mon Sep 17 00:00:00 2001 From: potatodepaulo Date: Tue, 4 Jun 2019 16:56:42 -0700 Subject: [PATCH 05/12] minor refactor, update nearlib and make tests better --- README.md | 2 +- blank_project/src/index.html | 2 +- index.js | 2 +- test/new_project.sh | 14 ++++++++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2d158f4b..abe7b26e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ near ### Commands: ```Bash near create_account # create a developer account - near new_project [dir] + near new_project [dir] # generate a new project from template near deploy # deploy your smart contract near call [args] # submits transaction, can change state, account required near view [args] # cannot change state, account is contract name diff --git a/blank_project/src/index.html b/blank_project/src/index.html index 53488562..9c022ede 100755 --- a/blank_project/src/index.html +++ b/blank_project/src/index.html @@ -10,7 +10,7 @@ Contract says:

- + diff --git a/index.js b/index.js index aafcc11e..7674c9a2 100755 --- a/index.js +++ b/index.js @@ -35,7 +35,7 @@ exports.clean = async function() { // Only works for dev environments exports.createDevAccount = async function(options) { const keyPair = await KeyPair.fromRandomSeed(); - let accountId = options.accountId; + const { accountId } = options; options.useDevAccount = true; options.deps = { keyStore: new InMemoryKeyStore(), diff --git a/test/new_project.sh b/test/new_project.sh index 6182f28c..123a8171 100755 --- a/test/new_project.sh +++ b/test/new_project.sh @@ -1,5 +1,9 @@ #!/bin/sh set -ex + +RED='\033[0;31m' +GREEN='\033[0;32m' + # remove temporary blank project rm -rf test/tmp-project cd test/ @@ -16,7 +20,9 @@ rm -rf tmp-project # test generating new project in new dir ../bin/near new_project 'tmp-project' cd tmp-project -npm install -npm uninstall near-shell -npm install ../../ -NODE_ENV=development npm run test \ No newline at end of file +FILE=package.json +if test -f "$FILE"; then + echo "${GREEN}$FILE exists. Have a cookie!" +else + echo "${RED}ERROR: file not found." +fi \ No newline at end of file From 6b88ab9e3fa567297c69da8783f7256f9a52f5df Mon Sep 17 00:00:00 2001 From: potatodepaulo Date: Tue, 4 Jun 2019 17:13:41 -0700 Subject: [PATCH 06/12] tell CI to fail on failure of test --- test/new_project.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/new_project.sh b/test/new_project.sh index 123a8171..818bcc4d 100755 --- a/test/new_project.sh +++ b/test/new_project.sh @@ -25,4 +25,5 @@ if test -f "$FILE"; then echo "${GREEN}$FILE exists. Have a cookie!" else echo "${RED}ERROR: file not found." + exit 1 fi \ No newline at end of file From 33360cf5f6ac14292abd4cb1857460973b1b8407 Mon Sep 17 00:00:00 2001 From: potatodepaulo Date: Tue, 4 Jun 2019 17:27:26 -0700 Subject: [PATCH 07/12] remove .js from config --- get-config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get-config.js b/get-config.js index a77b293e..07c9d4db 100644 --- a/get-config.js +++ b/get-config.js @@ -1,6 +1,6 @@ module.exports = function getConfig() { - const configPath = process.cwd() + '/src/config.js'; + const configPath = process.cwd() + '/src/config'; try { return require(configPath)(process.env.NODE_ENV || 'development'); } catch (e) { From b90d61f3a066faa330116e140ade00068c8ee412 Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Tue, 4 Jun 2019 17:33:08 -0700 Subject: [PATCH 08/12] package-lock.json --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5e139f98..ddd63d0f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1649,9 +1649,9 @@ "integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=" }, "nearlib": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/nearlib/-/nearlib-0.7.3.tgz", - "integrity": "sha512-X7+7dVlvpSXEdX2y/V3kGs4dCmLUsZVcQPcjtKopuMtagt75kXpzGecPZbodlpylscTHxBmE4iIvIfKmPMIH4g==", + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/nearlib/-/nearlib-0.8.0.tgz", + "integrity": "sha512-l14FjKSDC95GaoDsJQJwmdTJYvBDjSx6kk6XtTUj0GBJhL2OBz7/oEvxBM0uXFORjJi+x0ku9rvUywUHD8n2RA==", "requires": { "bs58": "^4.0.1", "error-polyfill": "^0.1.2", From 6e8361cf7b38382c7fd1ea24656a9728ca63d686 Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Tue, 4 Jun 2019 17:38:04 -0700 Subject: [PATCH 09/12] 0.5.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index ddd63d0f..59bc1432 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "near-shell", - "version": "0.4.1", + "version": "0.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8582bae8..2902c8c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "near-shell", - "version": "0.4.1", + "version": "0.5.0", "description": "Command line utilities to interact with near blockchain", "main": "index.js", "scripts": { From 4a7cd4931c0880688d7e2b112ed16afb9d22b92f Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Tue, 4 Jun 2019 20:14:53 -0700 Subject: [PATCH 10/12] Allow passing token amount with scheduled function call --- bin/near | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/near b/bin/near index 62e5ad67..5fcf8e0c 100755 --- a/bin/near +++ b/bin/near @@ -30,7 +30,12 @@ const deploy = { const scheduleFunctionCall = { command: 'call [args]', desc: 'schedule smart contract call which can modify state', - builder: (yargs) => yargs, + builder: (yargs) => yargs + .option('amount', { + desc: 'Number of tokens to attach', + type: 'string', + default: '1000000000' + }), handler: (argv) => exitOnError(main.scheduleFunctionCall(argv)) }; From 1ca504f7af42744bccc4fcac306d7f588084fd1b Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Tue, 4 Jun 2019 20:31:05 -0700 Subject: [PATCH 11/12] Add command to send tokens --- bin/near | 8 ++++++++ index.js | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/bin/near b/bin/near index 5fcf8e0c..90a1bf76 100755 --- a/bin/near +++ b/bin/near @@ -46,6 +46,13 @@ const callViewFunction = { handler: (argv) => exitOnError(main.callViewFunction(argv)) }; +const sendTokens = { + command: 'send ', + desc: 'send tokens to given receiver', + builder: (yargs) => yargs, + handler: (argv) => exitOnError(main.sendTokens(argv)) +}; + const { spawn } = require('child_process'); const build = { command: 'build', @@ -129,6 +136,7 @@ yargs // eslint-disable-line .command(deploy) .command(scheduleFunctionCall) .command(callViewFunction) + .command(sendTokens) .command(clean) .command(newProject) .config(config) diff --git a/index.js b/index.js index 7674c9a2..2787d390 100755 --- a/index.js +++ b/index.js @@ -93,6 +93,13 @@ exports.scheduleFunctionCall = async function(options) { options.contractName, options.methodName, JSON.parse(options.args || '{}')))); }; +exports.sendTokens = async function(options) { + console.log(`Sending ${options.amount} NEAR to ${options.receiver}`); + const near = await connect(options); + await near.waitForTransactionResult( + await near.sendTokens(options.amount, options.accountId, options.receiver)); +}; + exports.callViewFunction = async function(options) { console.log(`View call: ${options.contractName}.${options.methodName}(${options.args || ''})`); const near = await connect(options); From baf598a1684eaed648ab7b1cea2c21c53a762b9f Mon Sep 17 00:00:00 2001 From: Vladimir Grichina Date: Wed, 5 Jun 2019 01:47:34 -0700 Subject: [PATCH 12/12] 0.6.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 59bc1432..3542e5b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "near-shell", - "version": "0.5.0", + "version": "0.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2902c8c9..3a5a56ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "near-shell", - "version": "0.5.0", + "version": "0.6.0", "description": "Command line utilities to interact with near blockchain", "main": "index.js", "scripts": {