-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add irc 27 metadata * Add examples * Add irc 30 * array literal * doc Co-authored-by: Thoralf-M <[email protected]> * doc again * format * changelog * Add asFeature helpers * Update bindings/nodejs/lib/types/block/output/irc-27.ts --------- Co-authored-by: Thoralf-M <[email protected]> Co-authored-by: Thibault Martinez <[email protected]> Co-authored-by: Abdulrahim Al Methiab <[email protected]>
- Loading branch information
1 parent
5b1867e
commit ec617be
Showing
9 changed files
with
222 additions
and
37 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
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
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
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
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
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
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,111 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { utf8ToHex } from '../../../utils'; | ||
import { MetadataFeature } from './feature'; | ||
|
||
/** | ||
* The IRC27 NFT standard schema. | ||
*/ | ||
class Irc27Metadata { | ||
/** The IRC standard */ | ||
readonly standard: string = 'IRC27'; | ||
/** The current version. */ | ||
readonly version: string = 'v1.0'; | ||
/** The media type (MIME) of the asset. | ||
* | ||
* ## Examples | ||
* - Image files: `image/jpeg`, `image/png`, `image/gif`, etc. | ||
* - Video files: `video/x-msvideo` (avi), `video/mp4`, `video/mpeg`, etc. | ||
* - Audio files: `audio/mpeg`, `audio/wav`, etc. | ||
* - 3D Assets: `model/obj`, `model/u3d`, etc. | ||
* - Documents: `application/pdf`, `text/plain`, etc. | ||
*/ | ||
type: string; | ||
/** URL pointing to the NFT file location. */ | ||
uri: string; | ||
/** The human-readable name of the native token. */ | ||
name: string; | ||
/** The human-readable collection name of the native token. */ | ||
collectionName?: string; | ||
/** Royalty payment addresses mapped to the payout percentage. */ | ||
royalties: Map<string, number> = new Map(); | ||
/** The human-readable name of the native token creator. */ | ||
issuerName?: string; | ||
/** The human-readable description of the token. */ | ||
description?: string; | ||
/** Additional attributes which follow [OpenSea Metadata standards](https://docs.opensea.io/docs/metadata-standards). */ | ||
attributes: Attribute[] = []; | ||
|
||
/** | ||
* @param type The media type (MIME) of the asset. | ||
* @param uri URL pointing to the NFT file location. | ||
* @param name The human-readable name of the native token. | ||
*/ | ||
constructor(type: string, uri: string, name: string) { | ||
this.type = type; | ||
this.uri = uri; | ||
this.name = name; | ||
} | ||
|
||
withCollectionName(collectionName: string): Irc27Metadata { | ||
this.collectionName = collectionName; | ||
return this; | ||
} | ||
|
||
addRoyalty(address: string, percentage: number): Irc27Metadata { | ||
this.royalties.set(address, percentage); | ||
return this; | ||
} | ||
|
||
withRoyalties(royalties: Map<string, number>): Irc27Metadata { | ||
this.royalties = royalties; | ||
return this; | ||
} | ||
|
||
withIssuerName(issuerName: string): Irc27Metadata { | ||
this.issuerName = issuerName; | ||
return this; | ||
} | ||
|
||
withDescription(description: string): Irc27Metadata { | ||
this.description = description; | ||
return this; | ||
} | ||
|
||
addAttribute(attribute: Attribute): Irc27Metadata { | ||
this.attributes.push(attribute); | ||
return this; | ||
} | ||
|
||
withAttributes(attributes: Attribute[]): Irc27Metadata { | ||
this.attributes = attributes; | ||
return this; | ||
} | ||
|
||
asHex(): string { | ||
return utf8ToHex(JSON.stringify(this)); | ||
} | ||
|
||
asFeature(): MetadataFeature { | ||
return new MetadataFeature(this.asHex()); | ||
} | ||
} | ||
|
||
class Attribute { | ||
trait_type: string; | ||
value: any; | ||
display_type?: string; | ||
|
||
constructor(trait_type: string, value: any) { | ||
this.trait_type = trait_type; | ||
this.value = value; | ||
} | ||
|
||
withDisplayType(display_type: string): Attribute { | ||
this.display_type = display_type; | ||
return this; | ||
} | ||
} | ||
|
||
export { Irc27Metadata, Attribute }; |
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,68 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { utf8ToHex } from '../../../utils'; | ||
import { MetadataFeature } from './feature'; | ||
|
||
/** | ||
* The IRC30 native token metadata standard schema. | ||
*/ | ||
class Irc30Metadata { | ||
/** The IRC standard */ | ||
readonly standard: string = 'IRC30'; | ||
/** The human-readable name of the native token. */ | ||
name: string; | ||
/** The symbol/ticker of the token. */ | ||
symbol: string; | ||
/** Number of decimals the token uses (divide the token amount by `10^decimals` to get its user representation). */ | ||
decimals: number; | ||
/** The human-readable description of the token. */ | ||
description?: string; | ||
/** URL pointing to more resources about the token. */ | ||
url?: string; | ||
/** URL pointing to an image resource of the token logo. */ | ||
logoUrl?: string; | ||
/** The svg logo of the token encoded as a byte string. */ | ||
logo?: string; | ||
|
||
/** | ||
* @param name The human-readable name of the native token. | ||
* @param symbol The symbol/ticker of the token. | ||
* @param decimals Number of decimals the token uses. | ||
*/ | ||
constructor(name: string, symbol: string, decimals: number) { | ||
this.name = name; | ||
this.symbol = symbol; | ||
this.decimals = decimals; | ||
} | ||
|
||
withDescription(description: string): Irc30Metadata { | ||
this.description = description; | ||
return this; | ||
} | ||
|
||
withUrl(url: string): Irc30Metadata { | ||
this.url = url; | ||
return this; | ||
} | ||
|
||
withLogoUrl(logoUrl: string): Irc30Metadata { | ||
this.logoUrl = logoUrl; | ||
return this; | ||
} | ||
|
||
withLogo(logo: string): Irc30Metadata { | ||
this.logo = logo; | ||
return this; | ||
} | ||
|
||
asHex(): string { | ||
return utf8ToHex(JSON.stringify(this)); | ||
} | ||
|
||
asFeature(): MetadataFeature { | ||
return new MetadataFeature(this.asHex()); | ||
} | ||
} | ||
|
||
export { Irc30Metadata }; |
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