Skip to content

Commit

Permalink
feat(tx-builder): validate nameTtl in NameUpdateTx
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Dec 7, 2023
1 parent 8ff3650 commit bca877e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/aens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import BigNumber from 'bignumber.js';
import { genSalt } from './utils/crypto';
import { commitmentHash, isAuctionName } from './tx/builder/helpers';
import { Tag, AensName } from './tx/builder/constants';
import { ArgumentError } from './utils/errors';
import { Encoded } from './utils/encoder';
import { sendTransaction, SendTransactionOptions, getName } from './chain';
import { buildTxAsync, BuildTxOptions } from './tx/builder';
Expand Down Expand Up @@ -165,8 +164,6 @@ interface AensTransferOptions extends
BuildTxOptions<Tag.NameTransferTx, 'nameId' | 'accountId' | 'recipientId' | 'onNode'>,
SendTransactionOptions {}

const NAME_TTL = 180000;

/**
* Query the AENS name info from the node
* and return the object with info and predefined functions for manipulating name
Expand Down Expand Up @@ -238,11 +235,7 @@ export async function aensQuery(
async revoke(options) {
return aensRevoke(name, { ...opt, ...options });
},
async extendTtl(nameTtl = NAME_TTL, options = {}) {
if (nameTtl > NAME_TTL || nameTtl <= 0) {
throw new ArgumentError('nameTtl', `a number between 1 and ${NAME_TTL} blocks`, nameTtl);
}

async extendTtl(nameTtl, options = {}) {
return {
...await aensUpdate(name, {}, {
...opt, ...options, nameTtl, extendPointers: true,
Expand Down
10 changes: 9 additions & 1 deletion src/tx/builder/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,15 @@ export const txSchema = [{
nonce: nonce('accountId'),
nameId,
// https://github.com/aeternity/protocol/blob/fd17982/AENS.md#update
nameTtl: withDefault(180000, shortUInt),
nameTtl: withFormatting(
(nameTtl) => {
const NAME_TTL = 180000;
nameTtl ??= NAME_TTL;
if (nameTtl >= 1 && nameTtl <= NAME_TTL) return nameTtl;
throw new ArgumentError('nameTtl', `a number between 1 and ${NAME_TTL} blocks`, nameTtl);
},
shortUInt,
),
pointers,
clientTtl: withDefault(60 * 60, shortUInt),
fee,
Expand Down

0 comments on commit bca877e

Please sign in to comment.