-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c4cb9c
commit ad569fa
Showing
4 changed files
with
209 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,78 @@ | ||
#!/usr/bin/env node | ||
|
||
const commandLineArgs = require('command-line-args'); | ||
const nearLib = require('nearlib'); | ||
const gulp = require('gulp'); | ||
const gulpfile = require('./gulpfile') // import the gulp file | ||
const yargs = require('yargs'); | ||
|
||
require('yargs') // eslint-disable-line | ||
.command('build', 'build your smart contract', (yargs) => { | ||
const deploy = { | ||
command: 'deploy', | ||
desc: 'deploy your smart contract', | ||
builder: (yargs) => yargs | ||
.option('contract_name', { | ||
desc: 'Contract name', | ||
type: 'string', | ||
required: true | ||
}) | ||
.option('node_url', { | ||
desc: 'Near node url', | ||
type: 'string', | ||
default: 'http://localhost:3030' | ||
}) | ||
.option('account_id', { | ||
desc: 'Your developer account id. If you have only one account, that one will be selected by default', | ||
type: 'string', | ||
}) | ||
, | ||
handler: (argv) => { | ||
if (gulp.task('deploy')) { | ||
const result = gulp.task('deploy')(argv); | ||
} else { | ||
throw "Unexpected error: deploy task not found in gulpfile." | ||
} | ||
} | ||
}; | ||
|
||
}, (argv) => { | ||
if (argv.verbose) console.info(`build contract on :${argv.port}`) | ||
const build = { | ||
command: 'build', | ||
desc: 'build your smart contract', | ||
builder: (yargs) => yargs, | ||
handler: (argv) => { | ||
if (gulp.task('build')) { | ||
const result = gulp.task('build')(); | ||
} else { | ||
throw "Unexpected error: build task not found in gulpfile." | ||
} | ||
} | ||
}; | ||
|
||
const createAccount = { | ||
command: 'create_account', | ||
desc: 'create a developer account', | ||
builder: (yargs) => yargs | ||
.option('node_url', { | ||
desc: 'Near node url', | ||
type: 'string', | ||
default: 'http://localhost:3030' | ||
}) | ||
.option('account_id', { | ||
desc: 'Unique identifier for the new account', | ||
type: 'string', | ||
required: true | ||
}) | ||
, | ||
handler: (argv) => { | ||
if (gulp.task('createDevAccount')) { | ||
const result = gulp.task('createDevAccount')(argv); | ||
} else { | ||
throw "Unexpected error: createDevAccount task not found in gulpfile." | ||
} | ||
}) | ||
.command('deploy', 'deploy your smart contract', (yargs) => { | ||
yargs | ||
.positional('contract_name', { | ||
describe: 'Name of the contract to deploy', | ||
default: 'default' | ||
}) | ||
}, (argv) => { | ||
if (argv.verbose) console.info(`deploy contract`) | ||
console.log('NOT IMPLEMENTED YET') | ||
}) | ||
} | ||
}; | ||
|
||
yargs // eslint-disable-line | ||
.command(createAccount) | ||
.command(build) | ||
.command(deploy) | ||
.demandCommand(1, 'Please enter a command') | ||
.argv; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const fs = require('fs'); | ||
const keyDir = './neardev'; | ||
const keyFile = 'devkey.json'; | ||
const KeyPair = require('nearlib/signing/key_pair') | ||
|
||
/** | ||
* Unencrypted file system key store. | ||
*/ | ||
class UnencryptedFileSystemKeyStore { | ||
constructor() {} | ||
|
||
async setKey(accountId, keypair) { | ||
if (!fs.existsSync(keyDir)){ | ||
fs.mkdirSync(keyDir); | ||
} | ||
const keyFileContent = { | ||
public_key: keypair.getPublicKey(), | ||
secret_key: keypair.getSecretKey(), | ||
account_id: accountId | ||
}; | ||
const writeResult = await fs.writeFileSync(this.getKeyFilePath(), JSON.stringify(keyFileContent)); | ||
} | ||
|
||
async getKey(accountId) { | ||
// Find keys/account id | ||
if (!fs.existsSync(this.getKeyFilePath())) { | ||
throw 'Key lookup failed. Please make sure you set up an account.'; | ||
} | ||
const rawKey = JSON.parse(fs.readFileSync(this.getKeyFilePath())); | ||
if (!rawKey.public_key || !rawKey.secret_key || !rawKey.account_id) { | ||
throw 'Deployment failed. neardev/devkey.json format problem. Please make sure file contains public_key, secret_key, and account_id".'; | ||
} | ||
if (rawKey.account_id != accountId) { | ||
throw 'Deployment failed. Keystore contains data for wrong account.'; | ||
} | ||
const result = new KeyPair(rawKey.public_key, rawKey.secret_key); | ||
return result; | ||
} | ||
|
||
/** | ||
* Returns all account ids. | ||
*/ | ||
async getAccountIds() { | ||
if (!fs.existsSync(this.getKeyFilePath())) { | ||
return []; | ||
} | ||
const rawKey = JSON.parse(fs.readFileSync(this.getKeyFilePath())); | ||
if (!rawKey.public_key || !rawKey.secret_key || !rawKey.account_id) { | ||
return []; | ||
} | ||
return [rawKey.account_id]; | ||
} | ||
|
||
async clear() { | ||
this.keys = {}; | ||
} | ||
|
||
// TODO: make this configurable | ||
getKeyFilePath() { | ||
return keyDir + "/" + keyFile; | ||
} | ||
} | ||
|
||
module.exports = UnencryptedFileSystemKeyStore; |