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 #182 from nearprotocol/revert-yifang-merge
Browse files Browse the repository at this point in the history
Revert yifang merge
  • Loading branch information
vgrichina authored Nov 5, 2019
2 parents 8a5c1e2 + aad11c3 commit c4ea792
Show file tree
Hide file tree
Showing 22 changed files with 520 additions and 178 deletions.
31 changes: 10 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,23 @@ near <command>

### Commands

For account:
```bash
near login # create a developer account
near create_account <accountId> # create a developer account with masterAccount, publicKey and initialBalance
near view <accountId> # view account state
near keys <accountId> # view account public keys
near send <sender> <receiver> <amount> # send tokens to given receiver
near stake <accountId> <stakingKey> <amount> # create staking transaction (stakingKey is base58 encoded)
near delete <accountId> <beneficiaryId> # delete an account and transfer funds to beneficiary account
```

For smart contract:
```bash
near create_account <accountId> # create a developer account
near state <accountId> # view account
near tx-status <hash> # lookup transaction status by hash
near build # build your smart contract
near deploy # deploy your smart contract
near call <contractName> <methodName> # schedule smart contract call which
[args] # can modify state
near view <contractName> <methodName> # make smart contract call which can
[args] # view state
near clean # clean the smart contract build locally(remove ./out )
```
near state <accountId> # view account
near send <receiver> <amount> # send tokens to given receiver
near clean # clean the build environment
near new_project [projectDir] # create a new blank project
near stake [accountId] [publicKey] [amount] # create staking transaction
near login # create a developer account

For transactions:
```bash
near tx-status <hash> # lookup transaction status by hash
```

### Options
Expand All @@ -59,7 +51,4 @@ For transactions:
| --helperUrl | NEAR contract helper URL | [string] | |
| --keyPath | Path to master account key | [string] | |
| --homeDir | Where to look for master account | [string] |"~/.near" |
| --accountId, --account_id | Unique identifier for the account | [string] [required]| |
| --masterAccount | Account used to create requested account. | [string] [required]| |
| --publicKey | Public key to initialize the account with | [string] [required]| |
| --initialBalance | Number of tokens to transfer to newly account | [string] [required]| |
| --accountId, --account_id | Unique identifier for the account | [string] | |
182 changes: 96 additions & 86 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,65 @@ const yargs = require('yargs');
const main = require('../');
const exitOnError = require('../utils/exit-on-error');

// For account:
const deploy = {
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'
})
.alias({
'accountId': ['account_id', 'contractName', 'contract_name'],
}),
handler: exitOnError(main.deploy)
};

const scheduleFunctionCall = {
command: 'call <contractName> <methodName> [args]',
desc: 'schedule smart contract call which can modify state',
builder: (yargs) => yargs
.option('amount', {
desc: 'Number of tokens to attach',
type: 'string',
default: '1000000000'
}),
handler: exitOnError(main.scheduleFunctionCall)
};

const callViewFunction = {
command: 'view <contractName> <methodName> [args]',
desc: 'make smart contract call which can view state',
builder: (yargs) => yargs,
handler: exitOnError(main.callViewFunction)
};

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

const { spawn } = require('child_process');
const build = {
command: 'build',
desc: 'build your smart contract',
handler: () => {
const gulp = spawn('gulp');
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);
});
}
};

const createAccount = {
command: 'create_account <accountId>',
desc: 'create a developer account',
Expand Down Expand Up @@ -38,7 +96,7 @@ const login = {
};

const viewAccount = {
command: 'view <accountId>',
command: 'state <accountId>',
desc: 'view account',
builder: (yargs) => yargs
.option('accountId', {
Expand All @@ -50,7 +108,7 @@ const viewAccount = {
};

const deleteAccount = {
command: 'delete <accountId> <beneficiaryId>',
command: 'delete_account <accountId> <beneficiaryId>',
desc: 'delete an account and transfer funds to beneficiary account.',
builder: (yargs) => yargs
.option('accountId', {
Expand Down Expand Up @@ -78,89 +136,6 @@ const keys = {
handler: exitOnError(main.keys)
};

const sendMoney = {
command: 'send <sender> <receiver> <amount>',
desc: 'send tokens to given receiver',
builder: (yargs) => yargs,
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', {
descr: 'Public key to stake with (base58 encoded)',
type: 'string',
required: true,
})
.option('amount', {
descr: 'Amount to stake',
type: 'string',
required: true,
}),
handler: exitOnError(main.stake)
};

// For contract:
const deploy = {
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'
})
.alias({
'accountId': ['account_id', 'contractName', 'contract_name'],
}),
handler: exitOnError(main.deploy)
};

const scheduleFunctionCall = {
command: 'call <contractName> <methodName> [args]',
desc: 'schedule smart contract call which can modify state',
builder: (yargs) => yargs
.option('amount', {
desc: 'Number of tokens to attach',
type: 'string',
default: '1000000000'
}),
handler: exitOnError(main.scheduleFunctionCall)
};

const callViewFunction = {
command: 'view <contractName> <methodName> [args]',
desc: 'make smart contract call which can view state',
builder: (yargs) => yargs,
handler: exitOnError(main.callViewFunction)
};

const { spawn } = require('child_process');
const build = {
command: 'build',
desc: 'build your smart contract',
handler: () => {
const gulp = spawn('gulp');
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);
});
}
};

// For transaction:
const txStatus = {
command: 'tx-status <hash>',
desc: 'lookup transaction status by hash',
Expand All @@ -185,6 +160,40 @@ const clean = {
handler: exitOnError(main.clean)
};

const newProject = {
command: 'new_project [projectDir]',
desc: 'create a new blank project',
builder: (yargs) => yargs
.option('projectDir', {
desc: 'project directory',
type: 'string',
default: '.'
}),
handler: exitOnError(main.newProject)
};

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

let config = require('../get-config')();
yargs // eslint-disable-line
.scriptName('near')
Expand Down Expand Up @@ -227,6 +236,7 @@ yargs // eslint-disable-line
.command(viewAccount)
.command(sendMoney)
.command(clean)
.command(newProject)
.command(stake)
.command(login)
.command(require('../commands/repl'))
Expand Down
2 changes: 2 additions & 0 deletions blank_project/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package-lock.json linguist-generated=true -diff
yarn.lock linguist-generated=true -diff
6 changes: 6 additions & 0 deletions blank_project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Greeter example in AssemblyScript

## Description

The contract implements a single function to return a greeting.
For instructions on how to run this project, please follow our online tutorial https://docs.nearprotocol.com/quick-start/local-development
32 changes: 32 additions & 0 deletions blank_project/assembly/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//@nearfile
import { near, context, storage, logging } from "near-runtime-ts";
import { Greeter } from "./model";

// --- contract code goes below

// It's good to use common constant, but not required.
const LAST_SENDER_KEY = "last_sender";

// This is our change method. It modifies the state of the contract by
// storing the account_id of the sender under the key "last_sender" on the blockchain
export function sayHi(): void {
// context.sender is the account_id of the user who sent this call to the contract
// It's provided by the Blockchain runtime. For now we just store it in a local variable.
let sender = context.sender;
// `near` class contains some helper functions, e.g. logging.
// Logs are not persistently stored on the blockchain, but produced by the blockchain runtime.
// It's helpful to use logs for debugging your functions or when you need to get some info
// from the change methods (since change methods don't return values to the front-end).
logging.log(sender + " says \"Hello mate!\"");
// storage is a helper class that allows contracts to modify the persistent state
// and read from it. setString allows you to persitently store a string value for a given string key.
// We'll store the last sender of this contract who called this method.
storage.setString(LAST_SENDER_KEY, sender);
}

// This is our view method. It returns the last account_id of a sender who called `sayHi`.
// It reads value from the persistent store under the key "last_sender" and returns it.
export function whoSaidHi(): string | null {
// getString returns a string value for a given string key.
return storage.getString(LAST_SENDER_KEY);
}
13 changes: 13 additions & 0 deletions blank_project/assembly/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@nearfile
// Basic data model
export class Greeter {
text: string;

constructor(text: string) {
this.text = text;
}

greet(userId: string): string {
return "Hello, " + userId;
}
}
6 changes: 6 additions & 0 deletions blank_project/assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../node_modules/assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
}
11 changes: 11 additions & 0 deletions blank_project/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const gulp = require('gulp');
const nearUtils = require('near-shell/gulp-utils');

function build_wasm(done){
nearUtils.compile('./assembly/main.ts', './out/main.wasm', done);
}

const build = gulp.series(build_wasm);


exports.default = build;
1 change: 1 addition & 0 deletions blank_project/neardev/shared-test-staging/test.near.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"account_id":"test.near","private_key":"ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw"}
1 change: 1 addition & 0 deletions blank_project/neardev/shared-test/test.near.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"account_id":"test.near","private_key":"ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw"}
4 changes: 4 additions & 0 deletions blank_project/out/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
30 changes: 30 additions & 0 deletions blank_project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "hello_world_ts",
"description": "",
"version": "0.0.1",
"scripts": {
"build": "mkdir -p out/ && gulp",
"deploy:contract": "near deploy",
"deploy:pages": "gh-pages -d src",
"deploy": "npm run build && npm run deploy:contract && npm run deploy:pages",
"prestart": "npm run build && npm run deploy:contract",
"start": "serve src",
"test": "npm run build && jest test --env=near-shell/test_environment"
},
"devDependencies": {
"gh-pages": "^2.1.1",
"gulp": "^4.0.2",
"jest": "^24.8.0",
"jest-environment-node": "^24.8.0",
"near-runtime-ts": "^0.5.1",
"near-shell": "github:nearprotocol/near-shell"
},
"wasmStudio": {
"name": "Hello World Example",
"description": "The contract implements a single function to return \"Hello, World!\" using AssemblyScript",
"icon": "typescript-lang-file-icon"
},
"dependencies": {
"serve": "^11.0.1"
}
}
File renamed without changes.
Loading

0 comments on commit c4ea792

Please sign in to comment.