From 06e695fac3357f4f015245031d19b8599d78568d Mon Sep 17 00:00:00 2001 From: valeriagrazzini Date: Tue, 30 Aug 2022 13:45:38 +0100 Subject: [PATCH] implemented new fields --- openapi.json | 26 ++++++++++++++++++++++- src/controllers/erc721/erc721.test.ts | 11 ++++++++-- src/controllers/erc721/post.controller.ts | 5 +++++ src/models/ERC721.ts | 2 ++ src/services/ERC721Service.ts | 2 +- src/types/TERC721.ts | 2 ++ 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/openapi.json b/openapi.json index 57b61d5f..ad6389ef 100644 --- a/openapi.json +++ b/openapi.json @@ -1,7 +1,7 @@ { "swagger": "2.0", "info": { - "version": "1.20.7", + "version": "1.20.8", "title": "THX API Specification", "description": "User guides are available at https://docs.thx.network." }, @@ -779,6 +779,12 @@ }, "schema": { "example": "any" + }, + "royaltyAddress": { + "example": "any" + }, + "royaltyPercentage": { + "example": "any" } } } @@ -3147,6 +3153,24 @@ } } }, + "royaltyRecipient": { + "type": "object", + "properties": { + "type": { + "type": "string", + "example": "string" + } + } + }, + "royaltyBps": { + "type": "object", + "properties": { + "type": { + "type": "string", + "example": "number" + } + } + }, "_id": { "type": "object", "properties": { diff --git a/src/controllers/erc721/erc721.test.ts b/src/controllers/erc721/erc721.test.ts index be632387..a6c3bb33 100644 --- a/src/controllers/erc721/erc721.test.ts +++ b/src/controllers/erc721/erc721.test.ts @@ -15,7 +15,9 @@ describe('ERC721', () => { schema = [ { name: 'color', propType: 'string', description: 'lorem ipsum' }, { name: 'size', propType: 'string', description: 'lorem ipsum dolor sit' }, - ]; + ], + royaltyAddress = '0x00', + royaltyPercentage = 5; let erc721ID: string; beforeAll(beforeAllCallback); @@ -31,6 +33,8 @@ describe('ERC721', () => { symbol, description, schema, + royaltyAddress, + royaltyPercentage, }) .expect(({ body }: request.Response) => { expect(body._id).toBeDefined(); @@ -46,7 +50,8 @@ describe('ERC721', () => { expect(body.properties[1].propType).toBe(schema[1].propType); expect(isAddress(body.address)).toBe(true); expect(body.archived).toBe(false); - + expect(body.royaltyRecipient).toBe(royaltyAddress); + expect(body.royaltyBps).toBe(royaltyPercentage * 1000); erc721ID = body._id; }) .expect(201, done); @@ -69,6 +74,8 @@ describe('ERC721', () => { expect(body.properties[1].description).toBe(schema[1].description); expect(body.properties[1].name).toBe(schema[1].name); expect(body.properties[1].propType).toBe(schema[1].propType); + expect(body.royaltyRecipient).toBe(royaltyAddress); + expect(body.royaltyBps).toBe(royaltyPercentage * 1000); expect(isAddress(body.address)).toBe(true); }) .expect(200, done); diff --git a/src/controllers/erc721/post.controller.ts b/src/controllers/erc721/post.controller.ts index b174d47b..80e54b50 100644 --- a/src/controllers/erc721/post.controller.ts +++ b/src/controllers/erc721/post.controller.ts @@ -1,6 +1,7 @@ import { Request, Response } from 'express'; import { body } from 'express-validator'; import ERC721Service from '@/services/ERC721Service'; +import { ADDRESS_ZERO } from '@/config/secrets'; const validation = [ body('name').exists().isString(), @@ -8,6 +9,8 @@ const validation = [ body('description').exists().isString(), body('chainId').exists().isNumeric(), body('schema').exists().isArray(), + body('royaltyAddress').optional().isString(), + body('royaltyPercentage').optional().isInt({ max: 100 }), ]; const controller = async (req: Request, res: Response) => { @@ -20,6 +23,8 @@ const controller = async (req: Request, res: Response) => { description: req.body.description, properties: req.body.schema, archived: false, + royaltyRecipient: req.body.royaltyAddress ? req.body.royaltyAddress : ADDRESS_ZERO, + royaltyBps: req.body.royaltyPercentage ? Number(req.body.royaltyPercentage) * 1000 : 0, }); res.status(201).json(erc721); diff --git a/src/models/ERC721.ts b/src/models/ERC721.ts index a7ea279c..78097cfe 100644 --- a/src/models/ERC721.ts +++ b/src/models/ERC721.ts @@ -17,6 +17,8 @@ const ERC721Schema = new mongoose.Schema( baseURL: String, properties: [{ name: String, propType: String, description: String }], archived: Boolean, + royaltyRecipient: String, + royaltyBps: Number, }, { timestamps: true }, ); diff --git a/src/services/ERC721Service.ts b/src/services/ERC721Service.ts index e353d8e5..ee51bac0 100644 --- a/src/services/ERC721Service.ts +++ b/src/services/ERC721Service.ts @@ -27,7 +27,7 @@ async function deploy(data: TERC721): Promise { const contract = await TransactionService.deploy( abi, bytecode, - [erc721.name, erc721.symbol, erc721.baseURL, defaultAccount], + [erc721.name, erc721.symbol, erc721.baseURL, defaultAccount, erc721.royaltyRecipient, erc721.royaltyBps], erc721.chainId, ); diff --git a/src/types/TERC721.ts b/src/types/TERC721.ts index 1f68d71a..a1c509f2 100644 --- a/src/types/TERC721.ts +++ b/src/types/TERC721.ts @@ -46,6 +46,8 @@ export type TERC721 = { createdAt?: Date; updatedAt?: Date; archived?: boolean; + royaltyRecipient?: string; + royaltyBps?: number; }; export type TERC721Metadata = {