Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

chore: devnet to testnet #238

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const replace = require('replace-in-file');
const {
auctionBidSchema,
buyRecordSchema,
createReservedNameSchema,
extendRecordSchema,
increaseUndernameCountSchema,
joinNetworkSchema,
Expand All @@ -27,6 +28,7 @@ const ajv = new Ajv({
schemas: [
auctionBidSchema,
buyRecordSchema,
createReservedNameSchema,
extendRecordSchema,
increaseUndernameCountSchema,
joinNetworkSchema,
Expand All @@ -48,6 +50,7 @@ const ajv = new Ajv({
const moduleCode = standaloneCode(ajv, {
validateAuctionBid: '#/definitions/auctionBid',
validateBuyRecord: '#/definitions/buyRecord',
validateCreateReservedName: '#/definitions/createReservedName',
validateExtendRecord: '#/definitions/extendRecord',
validateIncreaseUndernameCount: '#/definitions/increaseUndernameCount',
validateJoinNetwork: '#/definitions/joinNetwork',
Expand Down
28 changes: 28 additions & 0 deletions schemas/createReservedName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const createReservedNameSchema = {
$id: '#/definitions/createReservedName',
type: 'object',
properties: {
function: {
type: 'string',
const: 'createReservedName',
},
name: {
type: 'string',
pattern: '^([a-zA-Z0-9][a-zA-Z0-9-]{0,49}[a-zA-Z0-9]|[a-zA-Z0-9]{1})$',
},
target: {
type: 'string',
pattern: '^[a-zA-Z0-9-_]{43}$',
},
endTimestamp: {
type: 'integer',
minimum: 1,
},
},
required: ['name', 'target'],
additionalProperties: false,
};

module.exports = {
createReservedNameSchema,
};
2 changes: 2 additions & 0 deletions schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ const { updateGatewaySchema } = require('./updateGateway');
const { delegateStakeSchema } = require('./delegateStake');
const { decreaseDelegateStakeSchema } = require('./decreaseDelegateStake');
const { decreaseOperatorStakeSchema } = require('./decreaseOperatorStake');
const { createReservedNameSchema } = require('./createReservedName');
module.exports = {
auctionBidSchema,
buyRecordSchema,
createReservedNameSchema,
extendRecordSchema,
increaseUndernameCountSchema,
joinNetworkSchema,
Expand Down
53 changes: 53 additions & 0 deletions src/actions/write/createReservedName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { getInvalidAjvMessage } from 'src/utilities';

import { NON_CONTRACT_OWNER_MESSAGE } from '../../constants';
import { ContractWriteResult, IOState, PstAction } from '../../types';
import { validateCreateReservedName } from '../../validations';

export class ReservedName {
name: string;
target: string;
endTimestamp: number;

constructor(input: any) {

Check warning on line 12 in src/actions/write/createReservedName.ts

View workflow job for this annotation

GitHub Actions / build / build (lint:check)

Argument 'input' should be typed with a non-any type

Check warning on line 12 in src/actions/write/createReservedName.ts

View workflow job for this annotation

GitHub Actions / build / build (lint:check)

Unexpected any. Specify a different type

Check warning on line 12 in src/actions/write/createReservedName.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Argument 'input' should be typed with a non-any type

Check warning on line 12 in src/actions/write/createReservedName.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Unexpected any. Specify a different type
// validate using ajv validator
if (!validateCreateReservedName(input)) {
throw new ContractError(
getInvalidAjvMessage(
validateCreateReservedName,
input,
'createReservedName',
),
);
}
const { name, target, endTimestamp } = input;
this.endTimestamp = endTimestamp;
this.target = target;
this.name = name;
}
}

// Updates this contract to new source code
export const createReservedName = async (
state: IOState,
{ caller, input }: PstAction,
): Promise<ContractWriteResult> => {
const owner = state.owner;

if (caller !== owner) {
throw new ContractError(NON_CONTRACT_OWNER_MESSAGE);
}

const reservedName = new ReservedName(input);

if (reservedName.endTimestamp < +SmartWeave.block.timestamp) {
throw new ContractError('End timestamp is in the past');
}

state.reserved[reservedName.name] = {
target: reservedName.target,
endTimestamp: reservedName.endTimestamp,
};

return { state };
};
Loading