Skip to content

Commit

Permalink
Merge pull request #93 from aeternity/release/2.3.0
Browse files Browse the repository at this point in the history
Release 2.3.0
  • Loading branch information
nduchak authored Aug 5, 2019
2 parents a08d1b6 + f847234 commit b722783
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 27 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# 2.3.0 (2019-08-05)


### Bug Fixes

* **Account:** Fix --json for account commands. Add proper error code to AENS commands. ([#90](https://github.com/aeternity/aepp-cli-js/issues/90)) ([7de13eb](https://github.com/aeternity/aepp-cli-js/commit/7de13eb))
* **CLI:** Fix exit codes around the CLI ([#84](https://github.com/aeternity/aepp-cli-js/issues/84)) ([c775e1d](https://github.com/aeternity/aepp-cli-js/commit/c775e1d))


### Features

* **sdk:** Update sdk version to 4.3.0 ([#92](https://github.com/aeternity/aepp-cli-js/issues/92)) ([454385d](https://github.com/aeternity/aepp-cli-js/commit/454385d))



# 2.2.0 (2019-07-16)


Expand Down
68 changes: 56 additions & 12 deletions bin/commands/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async function sign (walletPath, tx, options) {
printUnderscored('Unsigned', tx)
printUnderscored('Signed', signedTx)
}
process.exit(0)
})
} catch (e) {
printError(e.message)
Expand Down Expand Up @@ -77,6 +78,7 @@ async function spend (walletPath, receiver, amount, options) {
json
? print({ tx })
: printTransaction(tx, json)
process.exit(0)
})
} catch (e) {
printError(e.message)
Expand Down Expand Up @@ -109,6 +111,7 @@ async function transferFunds (walletPath, receiver, percentage, options) {
} else {
printTransaction(tx, json)
}
process.exit(0)
})
} catch (e) {
printError(e.message)
Expand All @@ -128,6 +131,7 @@ async function getBalance (walletPath, options) {
printUnderscored('Balance', await client.balance(keypair.publicKey, { height: +height, hash }))
printUnderscored('ID', await client.address())
printUnderscored('Nonce', nonce)
process.exit(0)
}
)
} catch (e) {
Expand All @@ -138,19 +142,31 @@ async function getBalance (walletPath, options) {
// ## Get `address` function
// This function allow you retrieve account `public` and `private` keys
async function getAddress (walletPath, options) {
const { privateKey, forcePrompt = false } = options
const { privateKey, forcePrompt = false, json } = options
try {
// Get `keyPair` by `walletPath`, decrypt using password and initialize `Ae` client with this `keyPair`
const { client, keypair } = await initClientByWalletFile(walletPath, { ...options, accountOnly: true }, true)

await handleApiError(
async () => {
printUnderscored('Address', await client.address())
if (privateKey) {
if (forcePrompt || await prompt(PROMPT_TYPE.confirm, { message: 'Are you sure you want print your secret key?' })) {
printUnderscored('Secret Key', keypair.secretKey)
if (json) {
if (privateKey) {
if (forcePrompt || await prompt(PROMPT_TYPE.confirm, { message: 'Are you sure you want print your secret key?' })) {
printUnderscored('Secret Key', keypair.secretKey)
print({ publicKey: await client.address(), secretKey: keypair.secretKey})
}
} else {
print({ publicKey: await client.address() })
}
} else {
printUnderscored('Address', await client.address())
if (privateKey) {
if (forcePrompt || await prompt(PROMPT_TYPE.confirm, { message: 'Are you sure you want print your secret key?' })) {
printUnderscored('Secret Key', keypair.secretKey)
}
}
}
process.exit(0)
}
)
} catch (e) {
Expand All @@ -161,16 +177,26 @@ async function getAddress (walletPath, options) {
// ## Get `nonce` function
// This function allow you retrieve account `nonce`
async function getAccountNonce (walletPath, options) {
const { json } = options
try {
// Get `keyPair` by `walletPath`, decrypt using password and initialize `Ae` client with this `keyPair`
const { client, keypair } = await initClientByWalletFile(walletPath, options, true)

await handleApiError(
async () => {
const nonce = await client.getAccountNonce(keypair.publicKey)
printUnderscored('ID', keypair.publicKey)
printUnderscored('Nonce', nonce - 1)
printUnderscored('Next Nonce', nonce)
if (json) {
print({
id: keypair.publicKey,
nonce: nonce - 1,
nextNonce: nonce
})
} else {
printUnderscored('ID', keypair.publicKey)
printUnderscored('Nonce', nonce - 1)
printUnderscored('Next Nonce', nonce)
}
process.exit(0)
}
)
} catch (e) {
Expand All @@ -180,9 +206,18 @@ async function getAccountNonce (walletPath, options) {

// ## Create secure `wallet` file
// This function allow you to generate `keypair` and write it to secure `ethereum` like key-file
async function createSecureWallet (walletPath, { output, password, overwrite }) {
async function createSecureWallet (walletPath, { output, password, overwrite, json }) {
try {
await generateSecureWallet(walletPath, { output, password, overwrite })
const { publicKey, path } = await generateSecureWallet(walletPath, { output, password, overwrite })
if (json) {
print({
publicKey,
path
})
} else {
printUnderscored('Address', publicKey)
printUnderscored('Path', path)
}
process.exit(0)
} catch (e) {
printError(e.message)
Expand All @@ -191,9 +226,18 @@ async function createSecureWallet (walletPath, { output, password, overwrite })

// ## Create secure `wallet` file from `private-key`
// This function allow you to generate `keypair` from `private-key` and write it to secure `ethereum` like key-file
async function createSecureWalletByPrivKey (walletPath, priv, { output, password, overwrite }) {
async function createSecureWalletByPrivKey (walletPath, priv, { output, password, overwrite, json }) {
try {
await generateSecureWalletFromPrivKey(walletPath, priv, { output, password, overwrite })
const { publicKey, path } = await generateSecureWalletFromPrivKey(walletPath, priv, { output, password, overwrite })
if (json) {
print({
publicKey,
path
})
} else {
printUnderscored('Address', publicKey)
printUnderscored('Path', path)
}
process.exit(0)
} catch (e) {
printError(e.message)
Expand Down
5 changes: 5 additions & 0 deletions bin/commands/aens.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async function claim (walletPath, domain, options) {

print(`Name ${domain} claimed`)
printUnderscored('Transaction hash', hash)
process.exit(0)
})
} catch (e) {
printError(e.message)
Expand Down Expand Up @@ -93,6 +94,7 @@ async function transferName (walletPath, domain, address, options) {
const transferTX = await client.aensTransfer(name.id, address, { ttl, nameTtl, nonce })
print('Transfer Success')
printUnderscored('Transaction hash', transferTX.hash)
process.exit(0)
})
} catch (e) {
printError(e.message)
Expand Down Expand Up @@ -128,6 +130,7 @@ async function updateName (walletPath, domain, address, options) {
const updateNameTx = await client.aensUpdate(name.id, address, { ttl, nameTtl, nonce })
print('Update Success')
printUnderscored('Transaction Hash', updateNameTx.hash)
process.exit(0)
})
} catch (e) {
printError(e.message)
Expand Down Expand Up @@ -157,6 +160,7 @@ async function revokeName (walletPath, domain, options) {
const revokeTx = await client.aensRevoke(name.id, { ttl, nonce })
print('Revoke Success')
printUnderscored('Transaction hash', revokeTx.hash)
process.exit(0)
})
} catch (e) {
printError(e.message)
Expand All @@ -177,6 +181,7 @@ async function lookUp (domain, options) {
await updateNameStatus(domain)(client),
json
)
process.exit(0)
})
} catch (e) {
printError(e.message)
Expand Down
6 changes: 2 additions & 4 deletions bin/utils/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export async function generateSecureWallet (name, { output = '', password, overw

writeFile(path.join(output, name), JSON.stringify(await dump(name, password, secretKey)))

printUnderscored('Address', Crypto.aeEncodeKey(publicKey))
printUnderscored('Path', path.resolve(process.cwd(), path.join(output, name)))
return { publicKey: Crypto.aeEncodeKey(publicKey), path: path.resolve(process.cwd(), path.join(output, name)) }
}

// Generate `keypair` from `PRIVATE KEY` encrypt it using password and to `ethereum` keystore file
Expand All @@ -56,8 +55,7 @@ export async function generateSecureWalletFromPrivKey (name, priv, { output = ''

writeFile(path.join(output, name), JSON.stringify(encryptedKeyPair))

printUnderscored('Address', Crypto.aeEncodeKey(keys.publicKey))
printUnderscored('Path', path.resolve(process.cwd(), path.join(output, name)))
return { publicKey: Crypto.aeEncodeKey(keys.publicKey), path: path.resolve(process.cwd(), path.join(output, name)) }
}

// Get account file by path, decrypt it using password and return `keypair`
Expand Down
23 changes: 16 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@aeternity/aepp-cli",
"version": "2.2.0",
"version": "2.3.0",
"description": "Aeternity command line interface",
"bin": {
"aecli": "./bin/aecli.js"
},
"dependencies": {
"@aeternity/aepp-sdk": "^4.2.0",
"@aeternity/aepp-sdk": "^4.3.0",
"child_process": "^1.0.2",
"commander": "^2.19.0",
"esm": "^3.0.84",
Expand Down
4 changes: 2 additions & 2 deletions test/cli/chain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('CLI Chain Module', function () {
parseInt(res.block_height).should.be.a('number')
})
it('STATUS', async () => {
let wallet = await BaseAe()
const wallet = await BaseAe()
wallet.setKeypair(generateKeyPair())

const { nodeVersion } = await wallet.api.getStatus()
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('CLI Chain Module', function () {
isValid.should.equal(true)
})
it('NETWORK ID', async () => {
const nodeNetworkId = wallet.nodeNetworkId
const nodeNetworkId = wallet.getNetworkId()
const { network_id } = parseBlock(await execute(['chain', 'network_id']))
nodeNetworkId.should.equal(network_id)
})
Expand Down

0 comments on commit b722783

Please sign in to comment.