Skip to content

Commit

Permalink
feat(AENS): extend name ttl command
Browse files Browse the repository at this point in the history
  • Loading branch information
nduchak committed Apr 10, 2020
1 parent ab12bac commit 63c99ae
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 11 deletions.
31 changes: 22 additions & 9 deletions bin/aecli-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ program

// ## Initialize `claim` command
//
// You can use this command to `claim` AENS name. Name must end on `.test`.
// You can use this command to `claim` AENS name. Name must end on `.chain`.
//
// Example: `aecli name claim ./myWalletKeyFile --password testpass testname.test`
// Example: `aecli name claim ./myWalletKeyFile --password testpass testname.chain`
//
// This command send `pre-claim` transaction, wait until one block was mined, after that sent `claim` and `update` transaction's
//
Expand All @@ -63,7 +63,7 @@ program
//
// You can use this command to `pre-claim` AENS name
//
// Example: `aecli name pre-claim ./myWalletKeyFile --password testpass testname.aet`
// Example: `aecli name pre-claim ./myWalletKeyFile --password testpass testname.chain`
//
// This command build and send `pre-claim` transaction.
// And wait until it will be mined. You can force waiting by using `--waitMined false` option. Default: true
Expand All @@ -78,9 +78,9 @@ program

// ## Initialize `claim` command
//
// You can use this command to `claim` AENS name. Name must end on `.test`.
// You can use this command to `claim` AENS name. Name must end on `.chain`.
//
// Example: `aecli name claim ./myWalletKeyFile --password testpass testname.test`
// Example: `aecli name claim ./myWalletKeyFile --password testpass testname.chain`
//
// This command send `pre-claim` transaction, wait until one block was mined, after that sent `claim` and `update` transaction's
//
Expand All @@ -95,9 +95,9 @@ program

// ## Initialize `claim` command
//
// You can use this command to `claim` AENS name. Name must end on `.test`.
// You can use this command to `claim` AENS name. Name must end on `.chain`.
//
// Example: `aecli name claim ./myWalletKeyFile --password testpass testname.test`
// Example: `aecli name claim ./myWalletKeyFile --password testpass testname.chain`
//
// This command send `pre-claim` transaction, wait until one block was mined, after that sent `claim` and `update` transaction's
//
Expand All @@ -109,11 +109,11 @@ program
.action(async (walletPath, name, nameFee, ...arguments) => await AENS.nameBid(walletPath, name, nameFee, utils.cli.getCmdFromArguments(arguments)))


// ## Initialize `claim` command
// ## Initialize `update` command
//
// You can use this command to `update` pointer of AENS name.
//
// Example: `aecli name update ./myWalletKeyFile --password testpass testname.test ak_qwe23dffasfgdesag323`
// Example: `aecli name update ./myWalletKeyFile --password testpass testname.chain ak_qwe23dffasfgdesag323`
program
.command('update <wallet_path> <name> [addresses...]')
.option('-M, --no-waitMined', 'Do not wait until transaction will be mined')
Expand All @@ -124,6 +124,19 @@ program
.action(async (walletPath, name, addresses, ...arguments) => await AENS.updateName(walletPath, name, addresses, utils.cli.getCmdFromArguments(arguments)))


// ## Initialize `extend` command
//
// You can use this command to `extend` ttl of AENS name.
//
// Example: `aecli name extend ./myWalletKeyFile --password testpass testname.chain 100`
program
.command('extend <wallet_path> <name> <nameTtl')
.option('-M, --no-waitMined', 'Do not wait until transaction will be mined')
.option('--clientTtl [clientTtl]', 'Client ttl.', utils.constant.CLIENT_TTL)
.description('Extend name ttl')
.action(async (walletPath, name, nameTtl, ...arguments) => await AENS.extendName(walletPath, name, nameTtl, utils.cli.getCmdFromArguments(arguments)))


// ## Initialize `revoke` command
//
// You can use this command to `destroy` AENS name.
Expand Down
37 changes: 37 additions & 0 deletions bin/commands/aens.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,42 @@ async function updateName (walletPath, domain, addresses, options) {
}
}

// ##Extend `name` ttl function
async function extendName (walletPath, domain, nameTtl, options) {
const { ttl, fee, nonce, waitMined, json, clientTtl } = options

try {
// Validate `name`
validateName(domain)
// Get `keyPair` by `walletPath`, decrypt using password and initialize `Ae` client with this `keyPair`
const client = await initClientByWalletFile(walletPath, options)

await handleApiError(async () => {
// Check if that `name` is unavailable and we can update it
const name = await updateNameStatus(domain)(client)
if (isAvailable(name)) {
print(`Domain is ${name.status} and cannot be extended`)
exit(1)
}

// Create `updateName` transaction
const updateTx = await client.aensUpdate(domain, [], { ttl, fee, nonce, waitMined, nameTtl, extendPointers: true })
if (waitMined) {
printTransaction(
updateTx,
json
)
} else {
print('Transaction send to the chain. Tx hash: ' + updateTx.hash)
}
exit()
})
} catch (e) {
printError(e.message)
exit(1)
}
}

// ##Transfer `name` function
async function transferName (walletPath, domain, address, options) {
const { ttl, fee, nonce, waitMined, json } = options
Expand Down Expand Up @@ -312,6 +348,7 @@ export const AENS = {
preClaim,
revokeName,
updateName,
extendName,
claim,
transferName,
nameBid,
Expand Down
2 changes: 1 addition & 1 deletion test/cli/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const walletName = 'test.wallet'

plan(1000000000)

describe.only('CLI Account Module', function () {
describe('CLI Account Module', function () {
configure(this)
let sig
let sigFromFile
Expand Down
11 changes: 10 additions & 1 deletion test/cli/aens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function randomName (length, namespace = '.chain') {
return randomString(length).toLowerCase() + namespace
}

describe.only('CLI AENS Module', function () {
describe('CLI AENS Module', function () {
configure(this)
const { publicKey } = generateKeyPair()
let wallet
Expand Down Expand Up @@ -102,6 +102,15 @@ describe.only('CLI AENS Module', function () {
isUpdatedNode.should.be.equal(true)
nameResult.status.should.equal('CLAIMED')
})
it('extend name ttl', async () => {
const height = await wallet.height()
const extendTx = JSON.parse(await execute(['name', 'extend', WALLET_NAME, name2, 50, '--password', 'test', '--json']))
const nameResult = JSON.parse(await execute(['inspect', name2, '--json']))
const isExtended = (nameResult.ttl - 50) >= height
isExtended.should.be.equal(true)
extendTx.blockHeight.should.be.gt(0)
nameResult.status.should.equal('CLAIMED')
})
it('Fail spend by name on invalid input', async () => {
const amount = 100000009
const error = await execute(['account', 'spend', WALLET_NAME, '--password', 'test', 'sdasdaasdas', amount, '--json'])
Expand Down

0 comments on commit 63c99ae

Please sign in to comment.