This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Feature/6917 implement nft module (#8841)
### What was the problem? This PR resolves #6917 ### How was it solved? Add NFT module
- Loading branch information
Showing
83 changed files
with
10,531 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ build | |
scripts | ||
config | ||
test/_setup.js | ||
src/app/app.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+13 Bytes
(100%)
examples/interop/pos-mainchain-fast/config/default/genesis_block.blob
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
examples/interop/pos-mainchain-fast/src/app/modules/testNft/commands/destroy_nft.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
examples/interop/pos-mainchain-fast/src/app/modules/testNft/commands/mint_nft.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/interop/pos-mainchain-fast/src/app/modules/testNft/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
17 changes: 17 additions & 0 deletions
17
examples/interop/pos-mainchain-fast/src/app/modules/testNft/endpoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
17 changes: 17 additions & 0 deletions
17
examples/interop/pos-mainchain-fast/src/app/modules/testNft/method.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
56 changes: 56 additions & 0 deletions
56
examples/interop/pos-mainchain-fast/src/app/modules/testNft/module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
examples/interop/pos-mainchain-fast/src/app/modules/testNft/schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.