Skip to content

Commit

Permalink
feat(AENS): Implement name update command
Browse files Browse the repository at this point in the history
  • Loading branch information
nduchak committed Oct 9, 2019
1 parent 7c4e28b commit b65c5e6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
2 changes: 2 additions & 0 deletions bin/aecli-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ program
program
.command('update <wallet_path> <name> <address>')
.option('-M, --no-waitMined', 'Do not wait until transaction will be mined')
.option('--nameTtl [nameTtl]', 'Validity of name.', utils.constant.NAME_TTL)
.option('--clientTtl [clientTtl]', 'Client ttl.', utils.constant.CLIENT_TTL)
.description('Update a name pointer')
.action(async (walletPath, name, address, ...arguments) => await AENS.updateName(walletPath, name, address, utils.cli.getCmdFromArguments(arguments)))

Expand Down
56 changes: 35 additions & 21 deletions bin/commands/aens.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ async function preClaim (walletPath, domain, options) {
exit(1)
}
// Create `pre-claim` transaction
printTransaction(
await client.aensPreclaim(domain, { ttl, fee, nonce, waitMined }),
json
)
const preClaimTx = await client.aensPreclaim(domain, { ttl, fee, nonce, waitMined })
if (waitMined) {
printTransaction(
preClaimTx,
json
)
} else {
print('Transaction send to the chain. Tx hash: ' + preClaimTx.hash)
}
exit()
})
} catch (e) {
Expand Down Expand Up @@ -74,10 +79,15 @@ async function claim (walletPath, domain, salt, options) {
}

// Wait for next block and create `claimName` transaction
printTransaction(
await client.aensClaim(domain, salt, { nonce, ttl, fee, waitMined, nameFee }),
json
)
const claimTx = await client.aensClaim(domain, salt, { nonce, ttl, fee, waitMined, nameFee })
if (waitMined) {
printTransaction(
claimTx,
json
)
} else {
print('Transaction send to the chain. Tx hash: ' + claimTx.hash)
}
exit()
})
} catch (e) {
Expand Down Expand Up @@ -123,14 +133,12 @@ async function transferName (walletPath, domain, address, options) {

// ##Update `name` function
async function updateName (walletPath, domain, address, options) {
// Parse options(`ttl`, `nameTtl` and `nonce``)
const ttl = parseInt(options.ttl)
const nameTtl = parseInt(options.nameTtl)
const nonce = parseInt(options.nonce)
const { ttl, fee, nonce, waitMined, json, nameTtl, clientTtl } = options

if (!address) {
// eslint-disable-next-line no-undef
program.outputHelp()
process.exit(1)
exit(1)
}

try {
Expand All @@ -141,23 +149,29 @@ async function updateName (walletPath, domain, address, options) {
// 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 transferred`)
process.exit(1)
print(`Domain is ${name.status} and cannot be updated`)
exit(1)
}

// Create `updateName` transaction
const updateNameTx = await client.aensUpdate(name.id, address, { ttl, nameTtl, nonce })
print('Update Success')
printUnderscored('Transaction Hash', updateNameTx.hash)
process.exit(0)
const updateTx = await client.aensUpdate(name.id, address, { ttl, fee, nonce, waitMined, nameTtl, clientTtl })
if (waitMined) {
printTransaction(
updateTx,
json
)
} else {
print('Transaction send to the chain. Tx hash: ' + updateTx.hash)
}
exit()
})
} catch (e) {
printError(e.message)
process.exit(1)
exit(1)
}
}

// ##Revoke `name` function
// ## Revoke `name` function
async function revokeName (walletPath, domain, options) {
// Parse options(`ttl` and `nonce`)
const ttl = parseInt(options.ttl)
Expand Down
7 changes: 4 additions & 3 deletions bin/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

import * as R from 'ramda'
import fs from 'fs'
import path from 'path'

import { GAS_PRICE, HASH_TYPES, AENS_NAME_DOMAINS } from './constant'
import { GAS_PRICE, HASH_TYPES } from './constant'
import { printError } from './print'
import path from 'path'
import { isNameValid } from '@aeternity/aepp-sdk/es/tx/builder/helpers'

// ## Method which build arguments for call call/deploy contracts
export async function prepareCallParams (name, { descrPath, contractAddress, contractSource, gas, ttl, nonce }) {
Expand Down Expand Up @@ -169,7 +170,7 @@ export function isAvailable (name) { return name.status === 'AVAILABLE' }

// Validate `name`
export function validateName (name) {
if (!AENS_NAME_DOMAINS.includes(R.last(name.split('.')))) { throw new Error('AENS TLDs must end in .' + R.head(AENS_NAME_DOMAINS)) }
isNameValid(name)
}

// Grab contract descriptor by path
Expand Down

0 comments on commit b65c5e6

Please sign in to comment.