diff --git a/es/ae/aens.js b/es/ae/aens.js index 9419d5febb..76e8cbdf06 100644 --- a/es/ae/aens.js +++ b/es/ae/aens.js @@ -173,11 +173,8 @@ async function claim (name, salt, options = {}) { })) const result = await this.send(claimTx, opt) - - return { - ...result, - ...opt.waitMined && await this.aensQuery(name, opt) - } + const nameInter = this.Chain.defaults.waitMined ? await this.aensQuery(name, opt) : {} + return Object.assign(result, nameInter) } /** diff --git a/es/tx/builder/index.js b/es/tx/builder/index.js index beb2635232..1e32e77bfc 100644 --- a/es/tx/builder/index.js +++ b/es/tx/builder/index.js @@ -141,6 +141,10 @@ function validateField (value, key, type, prefix) { return assert((!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).gte(0), { value, isMinusValue }) } case FIELD_TYPES.id: + if (Array.isArray(prefix)) { + const p = prefix.find(p => p === value.split('_')[0]) + return assert(p && PREFIX_ID_TAG[value.split('_')[0]], { value, prefix }) + } return assert(assertedType(value, prefix) && PREFIX_ID_TAG[value.split('_')[0]] && value.split('_')[0] === prefix, { value, prefix }) case FIELD_TYPES.binary: return assert(value.split('_')[0] === prefix, { prefix, value }) diff --git a/es/tx/builder/schema.js b/es/tx/builder/schema.js index 8ece8f1727..8febfc3c8d 100644 --- a/es/tx/builder/schema.js +++ b/es/tx/builder/schema.js @@ -374,14 +374,14 @@ const ACCOUNT_TX_2 = [ TX_FIELD('flags', FIELD_TYPES.int), TX_FIELD('nonce', FIELD_TYPES.int), TX_FIELD('balance', FIELD_TYPES.int), - TX_FIELD('gaContract', FIELD_TYPES.id, 'ct'), + TX_FIELD('gaContract', FIELD_TYPES.id, ['ct', 'nm']), TX_FIELD('gaAuthFun', FIELD_TYPES.binary, 'cb') ] const SPEND_TX = [ ...BASE_TX, TX_FIELD('senderId', FIELD_TYPES.id, 'ak'), - TX_FIELD('recipientId', FIELD_TYPES.id, 'ak'), + TX_FIELD('recipientId', FIELD_TYPES.id, ['ak', 'nm']), TX_FIELD('amount', FIELD_TYPES.int), TX_FIELD('fee', FIELD_TYPES.int), TX_FIELD('ttl', FIELD_TYPES.int), @@ -431,7 +431,7 @@ const NAME_TRANSFER_TX = [ TX_FIELD('accountId', FIELD_TYPES.id, 'ak'), TX_FIELD('nonce', FIELD_TYPES.int), TX_FIELD('nameId', FIELD_TYPES.id, 'nm'), - TX_FIELD('recipientId', FIELD_TYPES.id, 'ak'), + TX_FIELD('recipientId', FIELD_TYPES.id, ['ak', 'nm']), TX_FIELD('fee', FIELD_TYPES.int), TX_FIELD('ttl', FIELD_TYPES.int) ] @@ -501,7 +501,7 @@ const CONTRACT_CALL_TX = [ ...BASE_TX, TX_FIELD('callerId', FIELD_TYPES.id, 'ak'), TX_FIELD('nonce', FIELD_TYPES.int), - TX_FIELD('contractId', FIELD_TYPES.id, 'ct'), + TX_FIELD('contractId', FIELD_TYPES.id, ['ct', 'nm']), TX_FIELD('abiVersion', FIELD_TYPES.int), TX_FIELD('fee', FIELD_TYPES.int), TX_FIELD('ttl', FIELD_TYPES.int), @@ -541,7 +541,7 @@ const ORACLE_REGISTER_TX = [ const ORACLE_EXTEND_TX = [ ...BASE_TX, - TX_FIELD('oracleId', FIELD_TYPES.id, 'ok'), + TX_FIELD('oracleId', FIELD_TYPES.id, ['ok', 'nm']), TX_FIELD('nonce', FIELD_TYPES.int), TX_FIELD('oracleTtlType', FIELD_TYPES.int), TX_FIELD('oracleTtlValue', FIELD_TYPES.int), @@ -553,7 +553,7 @@ const ORACLE_QUERY_TX = [ ...BASE_TX, TX_FIELD('senderId', FIELD_TYPES.id, 'ak'), TX_FIELD('nonce', FIELD_TYPES.int), - TX_FIELD('oracleId', FIELD_TYPES.id, 'ok'), + TX_FIELD('oracleId', FIELD_TYPES.id, ['ok', 'nm']), TX_FIELD('query', FIELD_TYPES.string), TX_FIELD('queryFee', FIELD_TYPES.int), TX_FIELD('queryTtlType', FIELD_TYPES.int), diff --git a/test/integration/aens.js b/test/integration/aens.js index f88165b3c2..8ccdfa9761 100644 --- a/test/integration/aens.js +++ b/test/integration/aens.js @@ -30,6 +30,7 @@ describe('Aens', function () { configure(this) let aens + let nameHash const account = generateKeyPair() const name = randomName() @@ -68,12 +69,19 @@ describe('Aens', function () { it('updates names', async () => { const claim = await aens.aensQuery(name) + nameHash = claim.id const address = await aens.address() return claim.update(address).should.eventually.deep.include({ pointers: [R.fromPairs([['key', 'account_pubkey'], ['id', address]])] }) }) + it('Spend by name', async () => { + const current = await aens.address() + const onAccount = aens.addresses().find(acc => acc !== current) + await aens.spend(100, nameHash, { onAccount }).catch(async e => console.log(await e.verifyTx())) + }) + it('transfers names', async () => { const claim = await aens.aensQuery(name)