Skip to content

Commit

Permalink
Merge branch 'nightshade'
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrichina committed Jul 17, 2019
2 parents a588052 + c586996 commit 54c5feb
Show file tree
Hide file tree
Showing 20 changed files with 329 additions and 111 deletions.
3 changes: 1 addition & 2 deletions .gitignore
@@ -1,5 +1,4 @@
.DS_Store
node_modules
tmp-project
neardev/

neardev/*
4 changes: 3 additions & 1 deletion .gitlab-ci.yml
Expand Up @@ -5,6 +5,8 @@ stages:

run_tests:
stage: test
tags:
- gcloud
script:
- yarn
- yarn test
- NODE_ENV=ci yarn test
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -16,6 +16,7 @@ near <command>
### Commands:
```Bash
near create_account <account_id> # create a developer account
near state <account_id> # view account
near new_project [dir] # generate a new project from template
near deploy # deploy your smart contract
near call <contractName> <methodName> [args] # submits transaction, can change state, account required
Expand Down
77 changes: 66 additions & 11 deletions bin/near
Expand Up @@ -46,13 +46,6 @@ const callViewFunction = {
handler: (argv) => exitOnError(main.callViewFunction(argv))
};

const viewAccount = {
command: 'view_account <accountId>',
desc: 'view given account/contract state',
builder: (yargs) => yargs,
handler: (argv) => exitOnError(main.viewAccount(argv))
};

const sendTokens = {
command: 'send <receiver> <amount>',
desc: 'send tokens to given receiver',
Expand Down Expand Up @@ -87,7 +80,38 @@ const createAccount = {
type: 'string',
required: true
}),
handler: (argv) => exitOnError(main.createDevAccount(argv))
handler: (argv) => exitOnError(main.createAccount(argv))
};

const login = {
command: 'login',
desc: 'create a developer account',
builder: (yargs) => yargs,
handler: (argv) => exitOnError(main.login(argv))
};

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

const txStatus = {
command: 'tx-status <hash>',
desc: 'lookup transaction status by hash',
builder: (yargs) => yargs
.option('hash', {
desc: 'base58-encoded hash',
type: 'string',
required: true
}),
handler: (argv) => exitOnError(main.txStatus(argv))
};

const clean = {
Expand All @@ -114,6 +138,28 @@ const newProject = {
handler: (argv) => exitOnError(main.newProject(argv))
};

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: (argv) => exitOnError(main.stake(argv))
}

let config = require('../get-config')();
yargs // eslint-disable-line
.option('nodeUrl', {
Expand All @@ -130,15 +176,22 @@ yargs // eslint-disable-line
desc: 'NEAR contract helper URL',
type: 'string',
})
.option('useDevAccount', {
desc: 'Forces use of special "developer" account (only works on local node)',
type: 'boolean',
.option('keyPath', {
desc: 'Path to master account key',
type: 'string',
})
.option('homeDir', {
desc: 'Where to look for master account, default is ~/.near',
type: 'string',
default: `${process.env.HOME}/.near`,
})
.option('accountId', {
desc: 'Unique identifier for the account',
type: 'string',
})
.command(createAccount)
.command(viewAccount)
.command(txStatus)
.command(build)
.command(deploy)
.command(scheduleFunctionCall)
Expand All @@ -147,6 +200,8 @@ yargs // eslint-disable-line
.command(sendTokens)
.command(clean)
.command(newProject)
.command(stake)
.command(login)
.config(config)
.alias({
'accountId': ['account_id'],
Expand Down
3 changes: 0 additions & 3 deletions blank_project/assembly/main.ts
@@ -1,6 +1,3 @@
import "allocator/arena";
export { memory };

import { context, storage, near } from "./near";

import { Greeter } from "./model.near";
Expand Down
1 change: 0 additions & 1 deletion blank_project/neardev/devkey.json

This file was deleted.

1 change: 1 addition & 0 deletions blank_project/neardev/shared-test/test.near.json
@@ -0,0 +1 @@
{"account_id":"test.near","private_key":"ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw"}
7 changes: 4 additions & 3 deletions blank_project/package.json
Expand Up @@ -12,13 +12,14 @@
"test": "npm run build && jest test --env=near-shell/test_environment"
},
"devDependencies": {
"assemblyscript-json": "github:nearprotocol/assemblyscript-json",
"assemblyscript-json": "github:nearprotocol/assemblyscript-json#update-as",
"gh-pages": "^2.0.1",
"gulp": "^3",
"jest": "^22.4.4",
"jest-environment-node": "^24.5.0",
"near-runtime-ts": "github:nearprotocol/near-runtime-ts",
"near-shell": "github:nearprotocol/near-shell"
"near-runtime-ts": "github:nearprotocol/near-runtime-ts#update-as",
"near-shell": "github:nearprotocol/near-shell#nightshade",
"bignum": "github:MaxGraey/bignum.wasm"
},
"wasmStudio": {
"name": "Hello World Example",
Expand Down
25 changes: 21 additions & 4 deletions blank_project/src/config.js
Expand Up @@ -8,16 +8,33 @@
case 'development':
return {
networkId: 'default',
nodeUrl: 'https://studio.nearprotocol.com/devnet',
helperUrl: 'https://studio.nearprotocol.com/contract-api',
nodeUrl: 'http://34.94.33.164:3030',
contractName: CONTRACT_NAME,
walletUrl: 'https://wallet.nearprotocol.com',
};
case 'local':
return {
networkId: 'local',
nodeUrl: 'http://localhost:3030',
keyPath: '~/.near/validator_key.json',
contractName: CONTRACT_NAME,
initialBalance: 100000,
};
case 'test':
return {
networkId: 'local',
nodeUrl: 'http://localhost:3030',
contractName: CONTRACT_NAME
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
initialBalance: 100000,
};
case 'test-remote':
case 'ci':
return {
networkId: 'shared-test',
nodeUrl: 'http://34.94.13.241:3030',
contractName: CONTRACT_NAME,
masterAccount: 'test.near',
};
default:
throw Error(`Unconfigured environment '${env}'. Can be configured in src/config.js.`);
Expand All @@ -30,4 +47,4 @@
} else {
window.nearConfig = cookieConfig && cookieConfig.nearPages ? cookieConfig : getConfig(DEFAULT_ENV);
}
})();
})();
2 changes: 1 addition & 1 deletion blank_project/src/index.html
Expand Up @@ -10,7 +10,7 @@
Contract says:
<h1 id="contract-message"></h1>
</div>
<script src="https://cdn.jsdelivr.net/npm/nearlib@0.8/dist/nearlib.js"></script>
<script src="https://cdn.jsdelivr.net/npm/nearlib@0.10/dist/nearlib.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
<script src="./config.js"></script>
<script src="./main.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion blank_project/src/main.js
Expand Up @@ -4,7 +4,7 @@

async function initContract() {
// Initializing connection to the NEAR DevNet.
window.near = await nearlib.dev.connect(nearConfig);
window.near = await nearlib.connect(nearConfig);

// Initializing our contract APIs by contract name and configuration.
window.contract = await near.loadContract(nearConfig.contractName, {
Expand Down
4 changes: 2 additions & 2 deletions blank_project/src/test.js
Expand Up @@ -11,8 +11,8 @@ describe("Greeter", function() {
if (window.testSettings === undefined) {
window.testSettings = {};
}
near = await nearlib.dev.connect(testSettings);
accountId = testSettings.accountId ? testSettings.accountId : nearlib.dev.myAccountId;
near = await nearlib.connect(testSettings);
accountId = testSettings.accountId;
const contractName = testSettings.contractName ?
testSettings.contractName :
(new URL(window.location.href)).searchParams.get("contractName");
Expand Down
6 changes: 4 additions & 2 deletions get-config.js
Expand Up @@ -2,9 +2,11 @@
module.exports = function getConfig() {
const configPath = process.cwd() + '/src/config';
try {
return require(configPath)(process.env.NODE_ENV || 'development');
const config = require(configPath)(process.env.NODE_ENV || 'development');
console.log(config);
return config;
} catch (e) {
console.log(`[WARNING] Didn't find config at ${configPath}\n`);
return {};
}
}
}
17 changes: 14 additions & 3 deletions gulp-utils.js
Expand Up @@ -17,7 +17,8 @@ function compile(inputFile, outputFile, callback) {
"--baseDir", "assembly",
"--binaryFile", outputFile,
"--sourceMap",
"--measure"
"--measure",
"--runtime", "stub"
], callback);
}

Expand All @@ -39,7 +40,7 @@ function getAsc() {

const logLn = process.browser ? window.logLn : console.log;
return main(args, options || {
stdout: process.stdout || asc.createMemoryStream(),
stdout: process.stdout || asc.createMemoryStream(logLn),
stderr: process.stderr || asc.createMemoryStream(logLn),
readFile: (filename, baseDir) => {
baseDir = pathModule.relative(process.cwd(), baseDir);
Expand All @@ -56,12 +57,22 @@ function getAsc() {
"assembly/near.ts" : "./node_modules/near-runtime-ts/near.ts",
"assembly/json/encoder.ts" : "./node_modules/assemblyscript-json/assembly/encoder.ts",
"assembly/json/decoder.ts" : "./node_modules/assemblyscript-json/assembly/decoder.ts",
}
"bignum/integer/u128.ts" : "./node_modules/bignum/assembly/integer/u128.ts",
};
if (path in mapping) {
path = mapping[path]
} else if (path.startsWith("assembly/node_modules/bignum/assembly")) {
// TODO: resolve two ways of importing bignum due to need to test near-runtime-ts separately
path = path.replace("assembly", ".");
} else if (path.startsWith("assembly/bignum")) {
path = path.replace("assembly/bignum", "./node_modules/bignum/assembly");
}
}

if (!fs.existsSync(path)) {
return null;
}

return fs.readFileSync(path).toString("utf8");
},
writeFile: (filename, contents) => {
Expand Down

0 comments on commit 54c5feb

Please sign in to comment.