Skip to content

Commit

Permalink
fix(AENS): Change tld for Lima from aet to chain (#714)
Browse files Browse the repository at this point in the history
* fix(AENS): Change tld for Lima from `aet` to `chain`
Point docker to the rc-5 node and 4.0.0 compiler
Move `classify` method from AENS to transaction builder helpers

* fix(AENS): Fix claim command with new tld
  • Loading branch information
nduchak authored Oct 16, 2019
1 parent 1e42fa1 commit 323ef6a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TAG=v5.0.0-rc.3
COMPILER_TAG=v4.0.0-rc5
TAG=v5.0.0-rc.5
COMPILER_TAG=v4.0.0
31 changes: 2 additions & 29 deletions es/ae/aens.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import * as R from 'ramda'
import { encodeBase58Check, salt } from '../utils/crypto'
import { commitmentHash, isNameValid, getMinimumNameFee } from '../tx/builder/helpers'
import { commitmentHash, isNameValid, getMinimumNameFee, classify } from '../tx/builder/helpers'
import Ae from './'
import { CLIENT_TTL, NAME_FEE, NAME_TTL } from '../tx/builder/schema'

Expand Down Expand Up @@ -76,33 +76,6 @@ async function revoke (nameId, options = {}) {
return this.send(nameRevokeTx, opt)
}

/**
* What kind of a hash is this? If it begins with 'ak_' it is an
* account key, if with 'ok_' it's an oracle key.
*
* @param s - the hash.
* returns the type, or throws an exception if type not found.
*/
function classify (s) {
const keys = {
ak: 'account_pubkey',
ok: 'oracle_pubkey',
ct: 'contract_pubkey',
ch: 'channel'
}

if (!s.match(/^[a-z]{2}_.+/)) {
throw Error('Not a valid hash')
}

const klass = s.substr(0, 2)
if (klass in keys) {
return keys[klass]
} else {
throw Error(`Unknown class ${klass}`)
}
}

/**
* Update an aens entry
* @instance
Expand Down Expand Up @@ -193,7 +166,7 @@ async function claim (name, salt, options = {}) {
}))

const result = await this.send(claimTx, opt)
if (opt.vsn === 1 || name.length - 4 > 12) {
if (opt.vsn === 1 || name.split('.')[0].length > 12) {
delete opt.vsn
const nameInter = this.Chain.defaults.waitMined ? await this.aensQuery(name, opt) : {}
return Object.assign(result, nameInter)
Expand Down
34 changes: 31 additions & 3 deletions es/tx/builder/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function formatSalt (salt) {
*/
export function produceNameId (name) {
const namespace = R.last(name.split('.'))
if (namespace === 'aet') return encode(hash(name.toLowerCase()), 'nm')
if (namespace === 'chain') return encode(hash(name.toLowerCase()), 'nm')
return encode(nameHash(name), 'nm')
}

Expand All @@ -115,7 +115,7 @@ export function produceNameId (name) {
*/
export function commitmentHash (name, salt = createSalt()) {
const namespace = R.last(name.split('.'))
if (namespace === 'aet') return `cm_${encodeBase58Check(hash(Buffer.concat([Buffer.from(name), formatSalt(salt)])))}`
if (namespace === 'chain') return `cm_${encodeBase58Check(hash(Buffer.concat([Buffer.from(name), formatSalt(salt)])))}`
return `cm_${encodeBase58Check(hash(Buffer.concat([nameHash(name.toLowerCase()), formatSalt(salt)])))}`
}

Expand Down Expand Up @@ -248,6 +248,33 @@ export function isNameValid (name, throwError = true) {
return true
}

/**
* What kind of a hash is this? If it begins with 'ak_' it is an
* account key, if with 'ok_' it's an oracle key.
*
* @param s - the hash.
* returns the type, or throws an exception if type not found.
*/
export function classify (s) {
const keys = {
ak: 'account_pubkey',
ok: 'oracle_pubkey',
ct: 'contract_pubkey',
ch: 'channel'
}

if (!s.match(/^[a-z]{2}_.+/)) {
throw Error('Not a valid hash')
}

const klass = s.substr(0, 2)
if (klass in keys) {
return keys[klass]
} else {
throw Error(`Unknown class ${klass}`)
}
}

/**
* Get the minimum name fee for a domain
* @function
Expand Down Expand Up @@ -293,5 +320,6 @@ export default {
createSalt,
buildHash,
isNameValid,
produceNameId
produceNameId,
classify
}
2 changes: 1 addition & 1 deletion es/tx/builder/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const VSN_2 = 2
export const TX_TTL = 0

// # AENS
export const AENS_NAME_DOMAINS = ['aet', 'test']
export const AENS_NAME_DOMAINS = ['chain', 'test']
export const NAME_TTL = 500
// # max number of block into the future that the name is going to be available
// # https://github.com/aeternity/protocol/blob/epoch-v0.22.0/AENS.md#update
Expand Down
6 changes: 3 additions & 3 deletions test/integration/aens.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ describe('Aens', function () {
const { version } = aens.getNodeInfo()
const [majorVersion] = version.split('.')
nameAuctionsSupported = +majorVersion === 5 && version !== '5.0.0-rc.1'
name = randomName(13, nameAuctionsSupported ? '.aet' : '.test') // 13 name length doesn't trigger auction
name2 = randomName(13, nameAuctionsSupported ? '.aet' : '.test')
name = randomName(13, nameAuctionsSupported ? '.chain' : '.test') // 13 name length doesn't trigger auction
name2 = randomName(13, nameAuctionsSupported ? '.chain' : '.test')
})

const lima = fn => async () => nameAuctionsSupported ? fn() : undefined
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('Aens', function () {
it('claims names', lima(async () => {
const current = await aens.address()
const onAccount = aens.addresses().find(acc => acc !== current)
const name = randomName(12, '.aet')
const name = randomName(12, '.chain')

const preclaim = await aens.aensPreclaim(name)
preclaim.should.be.an('object')
Expand Down

0 comments on commit 323ef6a

Please sign in to comment.