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

Commit

Permalink
Merge Feature/6917 implement nft module (#8841)
Browse files Browse the repository at this point in the history
### What was the problem?

This PR resolves #6917 

### How was it solved?

Add NFT module
  • Loading branch information
shuse2 authored Aug 11, 2023
2 parents 5702a26 + 7044e65 commit 43b93f3
Show file tree
Hide file tree
Showing 83 changed files with 10,531 additions and 24 deletions.
1 change: 1 addition & 0 deletions examples/interop/pos-mainchain-fast/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build
scripts
config
test/_setup.js
src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,95 @@
}
}
},
{
"module": "nft",
"data": {
"nftSubstore": [],
"supportedNFTsSubstore": [
{
"chainID": "",
"supportedCollectionIDArray": []
}
]
},
"schema": {
"$id": "/nft/module/genesis",
"type": "object",
"required": ["nftSubstore", "supportedNFTsSubstore"],
"properties": {
"nftSubstore": {
"type": "array",
"fieldNumber": 1,
"items": {
"type": "object",
"required": ["nftID", "owner", "attributesArray"],
"properties": {
"nftID": {
"dataType": "bytes",
"fieldNumber": 1,
"minLength": 16,
"maxLength": 16
},
"owner": {
"dataType": "bytes",
"fieldNumber": 2
},
"attributesArray": {
"type": "array",
"fieldNumber": 3,
"items": {
"type": "object",
"required": ["module", "attributes"],
"properties": {
"module": {
"dataType": "string",
"minLength": 1,
"maxLength": 32,
"fieldNumber": 1
},
"attributes": {
"dataType": "bytes",
"fieldNumber": 2
}
}
}
}
}
}
},
"supportedNFTsSubstore": {
"type": "array",
"fieldNumber": 2,
"items": {
"type": "object",
"required": ["chainID", "supportedCollectionIDArray"],
"properties": {
"chainID": {
"dataType": "bytes",
"fieldNumber": 1
},
"supportedCollectionIDArray": {
"type": "array",
"fieldNumber": 2,
"items": {
"type": "object",
"required": ["collectionID"],
"properties": {
"collectionID": {
"dataType": "bytes",
"minLength": 4,
"maxLength": 4,
"fieldNumber": 1
}
}
}
}
}
}
}
}
}
},
{
"module": "pos",
"data": {
Expand Down
Binary file not shown.
17 changes: 15 additions & 2 deletions examples/interop/pos-mainchain-fast/src/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { Application, PartialApplicationConfig } from 'lisk-sdk';
import { Application, PartialApplicationConfig, NFTModule } from 'lisk-sdk';
import { TestNftModule } from './modules/testNft/module';
import { registerModules } from './modules';
import { registerPlugins } from './plugins';

export const getApplication = (config: PartialApplicationConfig): Application => {
const { app } = Application.defaultApplication(config, true);
const { app, method } = Application.defaultApplication(config, true);

const nftModule = new NFTModule();
const testNftModule = new TestNftModule();
const interoperabilityModule = app['_registeredModules'].find(
mod => mod.name === 'interoperability',
);
interoperabilityModule.registerInteroperableModule(nftModule);
nftModule.addDependencies(method.interoperability, method.fee, method.token);
testNftModule.addDependencies(nftModule.method);

app.registerModule(nftModule);
app.registerModule(testNftModule);

registerModules(app);
registerPlugins(app);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

import { BaseCommand, CommandExecuteContext, NFTMethod } from 'lisk-sdk';
import { destroyNftParamsSchema } from '../schema';

interface Params {
address: Buffer;
nftID: Buffer;
}

export class DestroyNftCommand extends BaseCommand {
private _nftMethod!: NFTMethod;
public schema = destroyNftParamsSchema;

public init(args: { nftMethod: NFTMethod }): void {
this._nftMethod = args.nftMethod;
}

public async execute(context: CommandExecuteContext<Params>): Promise<void> {
const { params } = context;

await this._nftMethod.destroy(context.getMethodContext(), params.address, params.nftID);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

import { BaseCommand, CommandExecuteContext, NFTMethod } from 'lisk-sdk';
import { NFTAttributes } from '../types';
import { mintNftParamsSchema } from '../schema';

interface Params {
address: Buffer;
collectionID: Buffer;
attributesArray: NFTAttributes[];
}

export class MintNftCommand extends BaseCommand {
private _nftMethod!: NFTMethod;
public schema = mintNftParamsSchema;

public init(args: { nftMethod: NFTMethod }): void {
this._nftMethod = args.nftMethod;
}

public async execute(context: CommandExecuteContext<Params>): Promise<void> {
const { params } = context;

await this._nftMethod.create(
context.getMethodContext(),
params.address,
params.collectionID,
params.attributesArray,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

export const LENGTH_COLLECTION_ID = 4;
export const MIN_LENGTH_MODULE_NAME = 1;
export const MAX_LENGTH_MODULE_NAME = 32;
export const LENGTH_NFT_ID = 16;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

import { BaseEndpoint } from 'lisk-sdk';

export class TestNftEndpoint extends BaseEndpoint {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

import { BaseMethod } from 'lisk-sdk';

export class TestNftMethod extends BaseMethod {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

import { BaseModule, ModuleInitArgs, ModuleMetadata, NFTMethod } from 'lisk-sdk';
import { TestNftEndpoint } from './endpoint';
import { TestNftMethod } from './method';
import { MintNftCommand } from './commands/mint_nft';
import { DestroyNftCommand } from './commands/destroy_nft';

export class TestNftModule extends BaseModule {
public endpoint = new TestNftEndpoint(this.stores, this.offchainStores);
public method = new TestNftMethod(this.stores, this.events);
public mintNftCommand = new MintNftCommand(this.stores, this.events);
public destroyNftCommand = new DestroyNftCommand(this.stores, this.events);
public commands = [this.mintNftCommand, this.destroyNftCommand];

private _nftMethod!: NFTMethod;

public addDependencies(nftMethod: NFTMethod) {
this._nftMethod = nftMethod;
}

public metadata(): ModuleMetadata {
return {
...this.baseMetadata(),
endpoints: [],
commands: this.commands.map(command => ({
name: command.name,
params: command.schema,
})),
events: [],
assets: [],
};
}

// eslint-disable-next-line @typescript-eslint/require-await
public async init(_args: ModuleInitArgs) {
this.mintNftCommand.init({
nftMethod: this._nftMethod,
});
this.destroyNftCommand.init({
nftMethod: this._nftMethod,
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

import {
LENGTH_COLLECTION_ID,
LENGTH_NFT_ID,
MAX_LENGTH_MODULE_NAME,
MIN_LENGTH_MODULE_NAME,
} from './constants';

export const mintNftParamsSchema = {
$id: '/lisk/nftTransferParams',
type: 'object',
required: ['address', 'collectionID', 'attributesArray'],
properties: {
address: {
dataType: 'bytes',
format: 'lisk32',
fieldNumber: 1,
},
collectionID: {
dataType: 'bytes',
minLength: LENGTH_COLLECTION_ID,
maxLength: LENGTH_COLLECTION_ID,
fieldNumber: 2,
},
attributesArray: {
type: 'array',
fieldNumber: 4,
items: {
type: 'object',
required: ['module', 'attributes'],
properties: {
module: {
dataType: 'string',
minLength: MIN_LENGTH_MODULE_NAME,
maxLength: MAX_LENGTH_MODULE_NAME,
pattern: '^[a-zA-Z0-9]*$',
fieldNumber: 1,
},
attributes: {
dataType: 'bytes',
fieldNumber: 2,
},
},
},
},
},
};

export const destroyNftParamsSchema = {
$id: '/lisk/nftDestroyParams',
type: 'object',
required: ['address', 'nftID'],
properties: {
address: {
dataType: 'bytes',
format: 'lisk32',
fieldNumber: 1,
},
nftID: {
dataType: 'bytes',
minLength: LENGTH_NFT_ID,
maxLength: LENGTH_NFT_ID,
fieldNumber: 2,
},
},
};
Loading

0 comments on commit 43b93f3

Please sign in to comment.