Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into validator-list
Browse files Browse the repository at this point in the history
  • Loading branch information
ilblackdragon committed May 6, 2020
2 parents e9c7986 + a70696e commit 9237cd1
Show file tree
Hide file tree
Showing 19 changed files with 835 additions and 391 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ node_js:
- 12
env:
- NODE_ENV=ci
- NODE_ENV=ci-staging
- NODE_ENV=ci-betanet
cache: yarn
script:
- yarn lint
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NEAR Shell command line interface

[![Build Status](https://travis-ci.com/nearprotocol/near-shell.svg?branch=master)](https://travis-ci.com/nearprotocol/near-shell)
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/nearprotocol/near-shell)
[![Build Status](https://travis-ci.com/near/near-shell.svg?branch=master)](https://travis-ci.com/near/near-shell)
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/near/near-shell)

NEAR Shell is a Node.js application that relies on [`nearlib`](https://github.com/nearprotocol/nearlib) to generate secure keys, connect to the NEAR platform and send transactions to the network on your behalf.

Expand Down
15 changes: 2 additions & 13 deletions bin/near-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,11 @@ const callViewFunction = {
handler: exitOnError(main.callViewFunction)
};

const { spawn } = require('child_process');

const build = {
command: 'build',
desc: 'build your smart contract',
handler: () => {
const gulp = spawn('gulp', [], {shell: process.platform == 'win32'});
gulp.stdout.on('data', function (data) {
console.log(data.toString());
});
gulp.stderr.on('data', function (data) {
console.log(data.toString());
});
gulp.on('exit', function (code) {
process.exit(code);
});
}
handler: exitOnError(main.build)
};

const clean = {
Expand Down
3 changes: 3 additions & 0 deletions commands/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { utils } = nearlib;
const exitOnError = require('../utils/exit-on-error');
const connect = require('../utils/connect');
const inspectResponse = require('../utils/inspect-response');
const eventtracking = require('../utils/eventtracking');

module.exports = {
command: 'call <contractName> <methodName> [args]',
Expand All @@ -22,6 +23,7 @@ module.exports = {
};

async function scheduleFunctionCall(options) {
await eventtracking.track(eventtracking.EVENT_ID_SCHEDULE_FN_CALL_START, { node: options.nodeUrl });
console.log(`Scheduling a call: ${options.contractName}.${options.methodName}(${options.args || ''})` +
(options.amount && options.amount != '0' ? ` with attached ${options.amount} NEAR` : ''));
const near = await connect(options);
Expand All @@ -34,4 +36,5 @@ async function scheduleFunctionCall(options) {
utils.format.parseNearAmount(options.amount));
const result = nearlib.providers.getTransactionLastResult(functionCallResponse);
console.log(inspectResponse(result));
await eventtracking.track(eventtracking.EVENT_ID_SCHEDULE_FN_CALL_END, { node: options.nodeUrl, success: true });
}
3 changes: 3 additions & 0 deletions commands/create-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const exitOnError = require('../utils/exit-on-error');
const connect = require('../utils/connect');
const { KeyPair } = require('near-api-js');
const eventtracking = require('../utils/eventtracking');

module.exports = {
command: 'create_account <accountId>',
Expand Down Expand Up @@ -31,6 +32,7 @@ module.exports = {
};

async function createAccount(options) {
await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_START, { nodeUrl: options.nodeUrl });
// NOTE: initialBalance is passed as part of config here, parsed in middleware/initial-balance
let near = await connect(options);
let keyPair;
Expand All @@ -46,4 +48,5 @@ async function createAccount(options) {
await near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair);
}
console.log(`Account ${options.accountId} for network "${options.networkId}" was created.`);
await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_END, { node: options.nodeUrl, success: true });
}
9 changes: 6 additions & 3 deletions commands/dev-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const { KeyPair } = require('near-api-js');
const exitOnError = require('../utils/exit-on-error');
const connect = require('../utils/connect');
const { readFile, writeFile } = require('fs').promises;
const eventtracking = require('../utils/eventtracking');

module.exports = {
command: 'dev-deploy [wasmFile]',
desc: 'deploy your smart contract using temporary account (TestNet only)',
builder: (yargs) => yargs
.option('wasmFile',{
.option('wasmFile', {
desc: 'Path to wasm file to deploy',
type: 'string',
default: './out/main.wasm'
Expand All @@ -29,6 +30,7 @@ module.exports = {
};

async function devDeploy(options) {
await eventtracking.track(eventtracking.EVENT_ID_DEV_DEPLOY_START, { node: options.nodeUrl });
const { nodeUrl, helperUrl, masterAccount, wasmFile } = options;

if (!helperUrl && !masterAccount) {
Expand All @@ -43,13 +45,14 @@ async function devDeploy(options) {
const account = await near.account(accountId);
await account.deployContract(contractData);
console.log(`Done deploying to ${accountId}`);
await eventtracking.track(eventtracking.EVENT_ID_DEV_DEPLOY_END, { node: options.nodeUrl, success: true });
}

async function createDevAccountIfNeeded({ near, keyStore, networkId, init }) {
// TODO: once examples and create-near-app use the dev-account.env file, we can remove the creation of dev-account
// https://github.com/nearprotocol/near-shell/issues/287
const accountFilePath = `${keyStore.keyDir}/dev-account`;
const accountFilePathEnv = `${keyStore.keyDir}/dev-account.env`;
const accountFilePath = 'neardev/dev-account';
const accountFilePathEnv = 'neardev/dev-account.env';
if (!init) {
try {
// throws if either file is missing
Expand Down
5 changes: 4 additions & 1 deletion commands/generate-key.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const KeyPair = require('near-api-js').KeyPair;
const exitOnError = require('../utils/exit-on-error');
const eventtracking = require('../utils/eventtracking');

module.exports = {
command: 'generate-key <account-id>',
desc: 'generate key ',
builder: (yargs) => yargs,
handler: exitOnError(async (argv) => {
await eventtracking.track(eventtracking.EVENT_ID_GENERATE_KEY_START, { network: argv.networkId });
let near = await require('../utils/connect')(argv);
if (argv.accountId) {
const { deps: { keyStore }} = near.config;
const { deps: { keyStore } } = near.config;
const existingKey = await keyStore.getKey(argv.networkId, argv.accountId);
if (existingKey) {
console.log(`Account has existing key pair with ${existingKey.publicKey} public key`);
Expand All @@ -18,5 +20,6 @@ module.exports = {
console.log(`Generated key pair with ${keyPair.publicKey} public key`);
}
}
await eventtracking.track(eventtracking.EVENT_ID_GENERATE_KEY_END, { network: argv.networkId, success: true });
})
};
3 changes: 3 additions & 0 deletions commands/tx-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const exitOnError = require('../utils/exit-on-error');
const connect = require('../utils/connect');
const inspectResponse = require('../utils/inspect-response');
const bs58 = require('bs58');
const eventtracking = require('../utils/eventtracking');

module.exports = {
command: 'tx-status <hash>',
Expand All @@ -13,6 +14,7 @@ module.exports = {
required: true
}),
handler: exitOnError(async (argv) => {
await eventtracking.track(eventtracking.EVENT_ID_TX_STATUS_START, { node: argv.nodeUrl });
const near = await connect(argv);

const hashParts = argv.hash.split(':');
Expand All @@ -33,5 +35,6 @@ module.exports = {
const status = await near.connection.provider.txStatus(bs58.decode(hash), accountId);
console.log(`Transaction ${accountId}:${hash}`);
console.log(inspectResponse(status));
await eventtracking.track(eventtracking.EVENT_ID_TX_STATUS_END, { node: argv.nodeUrl, success: true });
})
};
6 changes: 4 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function getConfig(env) {
switch (env) {

case 'production':
case 'mainnet':
return {
networkId: 'mainnet',
nodeUrl: 'https://rpc.mainnet.nearprotocol.com',
Expand All @@ -12,6 +13,7 @@ function getConfig(env) {
helperUrl: 'https://helper.mainnet.nearprotocol.com',
};
case 'development':
case 'testnet':
return {
networkId: 'default',
nodeUrl: 'https://rpc.testnet.nearprotocol.com',
Expand Down Expand Up @@ -51,10 +53,10 @@ function getConfig(env) {
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
};
case 'ci-staging':
case 'ci-betanet':
return {
networkId: 'shared-test-staging',
nodeUrl: 'http://staging-shared-test.nearprotocol.com:3030',
nodeUrl: 'http://rpc.ci-betanet.nearprotocol.com',
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
};
Expand Down
10 changes: 7 additions & 3 deletions get-config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@

module.exports = function getConfig() {
const configPath = process.cwd() + '/src/config';
const nearEnv = process.env.NEAR_ENV || process.env.NODE_ENV || 'development';
try {
const config = require(configPath)(process.env.NODE_ENV || 'development');
const config = require(configPath)(nearEnv);
return config;
} catch (e) {
if (e.code == 'MODULE_NOT_FOUND') {
if(process.env.NEAR_DEBUG) console.warn(`[WARNING] Didn't find config at ${configPath}, using default shell config`);
const defaultConfig = require('./config')(process.env.NODE_ENV || 'development');
if (process.env.NEAR_DEBUG) {
// TODO: Use debug module instead, see https://github.com/near/near-api-js/pull/250
console.warn(`[WARNING] Didn't find config at ${configPath}, using default shell config`);
}
const defaultConfig = require('./config')(nearEnv);
return defaultConfig;
}
throw e;
Expand Down
Loading

0 comments on commit 9237cd1

Please sign in to comment.