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

Commit

Permalink
Merge pull request #1082 from near/simplify-and-reorgazine
Browse files Browse the repository at this point in the history
[v4.0.0] Reorganize, Reduce and Enhance
  • Loading branch information
gagdiez authored Feb 8, 2024
2 parents d7fa5a7 + 4114ab6 commit b9038a0
Show file tree
Hide file tree
Showing 81 changed files with 3,549 additions and 7,521 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "12"
node-version: "16"
- name: Install modules
run: yarn
- name: Run tests
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
## [unreleased]
- ...

## `4.0.0` [01-23-2024]
- Reorganized code to simplify its maintenance.
- New: Fixed `create-account` can now create `TLA`, `sub-accounts` and `.testnet/.near` accounts.
- New: Added `--useFaucet` option to `create-account` command, allowing to fund the account using a faucet.
- Fix: Default wallet is now `MyNearWallet` install of `NearWallet`
- Fix: Removed unnecessary options from commands, e.g. `view` now does not take an `--accountId` or `--masterAccount`.
- Fix: Fixed `--networkId` flag, now it works in all relevant commands.
- Breaking: removed `x-api` option.
- Breaking: removed `stake` command.
- Breaking: removed all `evm` commands.
- Breaking: Removed all `Ledger` support.
- Breaking: removed all `validator` commands.
- Breaking: removed `dev-deploy` command. Users must now create an account (can fund it with a faucet) and deploy to it.
- Breaking: changed `generate-key` command. Now it needs the `--saveImplicit` flag to save the key.
- Breaking: removed `walletUrl`, `nodeUrl` and `helperUrl` options.

## `3.0.0` [11-30-2021]
- Breaking change: added prompts to `delete-key` command. [PR](https://github.com/near/near-cli/pull/890)
- Breaking change: added prompts to `deploy` command. [PR](https://github.com/near/near-cli/pull/883)
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# CODEOWNERS: https://help.github.com/articles/about-codeowners/

@volovyks @thisisjoshford @gagdiez
@volovyks @thisisjoshford @gagdiez
1,213 changes: 260 additions & 953 deletions README.md

Large diffs are not rendered by default.

291 changes: 19 additions & 272 deletions bin/near-cli.js
Original file line number Diff line number Diff line change
@@ -1,285 +1,32 @@
const yargs = require('yargs');
const main = require('../');
const exitOnError = require('../utils/exit-on-error');
const chalk = require('chalk');
const { DEFAULT_FUNCTION_CALL_GAS } = require('near-api-js');

// For account:

const login = {
command: 'login',
desc: 'logging in through NEAR protocol wallet',
builder: (yargs) => yargs
.option('walletUrl', {
desc: 'URL of wallet to use',
type: 'string',
required: false
}),
handler: exitOnError(main.login)
};

const viewAccount = {
command: 'state <accountId>',
desc: 'view account state',
builder: (yargs) => yargs
.option('accountId', {
desc: 'Account to view',
type: 'string',
required: true
}),
handler: exitOnError(main.viewAccount)
};

const deleteAccount = {
command: 'delete <accountId> <beneficiaryId>',
desc: 'delete an account and transfer Near tokens to beneficiary account.',
builder: (yargs) => yargs
.option('accountId', {
desc: 'Account to delete',
type: 'string',
required: true
})
.option('beneficiaryId', {
desc: 'Account to transfer funds to',
type: 'string',
required: true
}),
handler: exitOnError(main.deleteAccount)
};

const keys = {
command: 'keys <accountId>',
desc: 'view account public keys',
builder: (yargs) => yargs
.option('accountId', {
desc: 'Account to view',
type: 'string',
required: true
}),
handler: exitOnError(main.keys)
};

const sendMoney = {
command: 'send <sender> <receiver> <amount>',
desc: 'send tokens to given receiver',
builder: (yargs) => yargs
.option('amount', {
desc: 'Amount of NEAR tokens to send',
type: 'string',
}),
handler: exitOnError(main.sendMoney)
};

const stake = {
command: 'stake [accountId] [stakingKey] [amount]',
desc: 'create staking transaction',
builder: (yargs) => yargs
.option('accountId', {
desc: 'Account to stake on',
type: 'string',
required: true,
})
.option('stakingKey', {
desc: 'Public key to stake with (base58 encoded)',
type: 'string',
required: true,
})
.option('amount', {
desc: 'Amount to stake',
type: 'string',
required: true,
}),
handler: exitOnError(main.stake)
};

// For contract:
const deploy = {
command: 'deploy [accountId] [wasmFile] [initFunction] [initArgs] [initGas] [initDeposit]',
// command: 'deploy',
desc: 'deploy your smart contract',
builder: (yargs) => yargs
.option('wasmFile', {
desc: 'Path to wasm file to deploy',
type: 'string',
default: './out/main.wasm'
})
.option('initFunction', {
desc: 'Initialization method',
type: 'string',
})
.option('initArgs', {
desc: 'Initialization arguments',
})
.option('initGas', {
desc: 'Gas for initialization call',
type: 'number',
default: DEFAULT_FUNCTION_CALL_GAS
})
.option('initDeposit', {
desc: 'Deposit in Ⓝ to send for initialization call',
type: 'string',
default: '0'
})
.alias({
'accountId': ['account_id', 'contractName', 'contract_name'],
}),
handler: exitOnError(main.deploy)
};

const callViewFunction = {
command: 'view <contractName> <methodName> [args]',
desc: 'make smart contract call which can view state',
builder: (yargs) => yargs
.option('args', {
desc: 'Arguments to the view call, in JSON format (e.g. \'{"param_a": "value"}\')',
type: 'string',
default: null
})
.alias({
'contractName': ['accountId'],
}),
handler: exitOnError(main.callViewFunction)
};

const clean = {
command: 'clean',
desc: 'clean the build environment',
builder: (yargs) => yargs
.option('outDir', {
desc: 'build directory',
type: 'string',
default: './out'
}),
handler: exitOnError(main.clean)
};

let config = require('../get-config')();
yargs // eslint-disable-line
.strict()
.middleware(require('../utils/check-version'))
.scriptName('near')
.option('nodeUrl', {
desc: 'NEAR node URL',
type: 'string',
default: config.nodeUrl
})
.option('headers', {
hidden: true,
desc: 'headers for NEAR RPC server calls',
type: 'string',
})
.option('networkId', {
desc: 'NEAR network ID, allows using different keys based on network',
type: 'string',
default: config.networkId
})
.option('helperUrl', {
desc: 'NEAR contract helper URL',
type: 'string',
})
.option('keyPath', {
desc: 'Path to master account key',
type: 'string',
})
.option('accountId', {
desc: 'Unique identifier for the account',
type: 'string',
})
.option('useLedgerKey', {
desc: 'Use Ledger for signing with given HD key path',
type: 'string',
default: "44'/397'/0'/0'/1'"
})
.options('seedPhrase', {
desc: 'Seed phrase mnemonic',
type: 'string',
required: false
})
.options('seedPath', {
desc: 'HD path derivation',
type: 'string',
default: "m/44'/397'/0'",
required: false
})
.option('walletUrl', {
desc: 'Website for NEAR Wallet',
type: 'string'
})
.option('contractName', {
desc: 'Account name of contract',
type: 'string'
})
.option('masterAccount', {
desc: 'Master account used when creating new accounts',
type: 'string'
})
.option('helperAccount', {
desc: 'Expected top-level account for a network',
type: 'string'
})
.option('explorerUrl', {
hidden: true,
desc: 'Base url for explorer',
type: 'string',
})
.option('verbose', {
desc: 'Prints out verbose output',
type: 'boolean',
alias: 'v',
default: false
})
.option('force', {
desc: 'Forcefully execute the desired action even if it is unsafe to do so',
type: 'boolean',
default: false,
alias: 'f'
})
.middleware(require('../middleware/initial-balance'))
.middleware(require('../utils/check-version'))
.middleware(require('../middleware/print-options'))
.middleware(require('../middleware/key-store'))
.middleware(require('../middleware/ledger'))
.middleware(require('../middleware/abi'))
.middleware(require('../middleware/seed-phrase'))
.middleware(require('../middleware/x-api-key'))
.command(require('../commands/create-account').createAccountCommand)
.command(require('../commands/create-account').createAccountCommandDeprecated)
.command(viewAccount)
.command(deleteAccount)
.command(keys)
.command(require('../commands/tx-status'))
.command(deploy)
.command(require('../commands/dev-deploy'))
.command(require('../commands/call'))
.command(callViewFunction)
.command(require('../commands/view-state'))
.command(sendMoney)
.command(clean)
.command(stake)
.command(login)
.command(require('../commands/repl'))
.command(require('../commands/generate-key'))
.command(require('../commands/add-key'))
.command(require('../commands/delete-key'))
.command(require('../commands/validators'))
.command(require('../commands/proposals'))
.command(require('../commands/evm-call'))
.command(require('../commands/evm-dev-init'))
.command(require('../commands/evm-view'))
.command(require('../commands/set-x-api-key'))
.command(require('../commands/js'))
.config(config)
.alias({
'accountId': ['account_id'],
'nodeUrl': 'node_url',
'networkId': ['network_id'],
'wasmFile': 'wasm_file',
'projectDir': 'project_dir',
'outDir': 'out_dir',
})
.command(require('../commands/credentials/add'))
.command(require('../commands/keys/add'))
.command(require('../commands/contract/call'))
.command(require('../commands/account/create'))
.command(require('../commands/account/delete'))
.command(require('../commands/keys/delete'))
.command(require('../commands/contract/deploy'))
.command(require('../commands/credentials/generate'))
.command(require('../commands/keys/list'))
.command(require('../commands/account/login'))
.command(require('../commands/transactions/send'))
.command(require('../commands/account/state'))
.command(require('../commands/contract/storage'))
.command(require('../commands/transactions/status'))
.command(require('../commands/contract/view'))
.command(require('../commands/deprecated'))
.option('verbose', { alias: ['v'], desc: 'Prints out verbose output', type: 'boolean', default: false })
.showHelpOnFail(true)
.recommendCommands()
.demandCommand(1, chalk`Pass {bold --help} to see all available commands and options.`)
.usage(chalk`Usage: {bold $0 <command> [options]}`)
.epilogue(chalk`Check out our epic whiteboard series: {bold http://near.ai/wbs}`)
.wrap(null)
.argv;
.argv;
Loading

0 comments on commit b9038a0

Please sign in to comment.