-
Notifications
You must be signed in to change notification settings - Fork 41
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 * imports * add standard * defaults * Add irc 30 * cleanup * camelCase * more cleanup * changelog * lints * doc * type annotations * from_dict * default dict * default factory list too * Add as_feature * and to irc 30 * unused import
- Loading branch information
DaughterOfMars
authored
Sep 20, 2023
1 parent
b9dd984
commit 610dc50
Showing
9 changed files
with
217 additions
and
43 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,66 @@ | ||
# Copyright 2023 IOTA Stiftung | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import json | ||
from iota_sdk import utf8_to_hex, MetadataFeature | ||
from dataclasses import dataclass, field | ||
from typing import Optional, List, Any | ||
from dacite import from_dict | ||
|
||
|
||
@dataclass | ||
class Attribute: | ||
"""An attribute which follows [OpenSea Metadata standards](https://docs.opensea.io/docs/metadata-standards). | ||
Attributes: | ||
trait_type: The trait type. | ||
value: The value of the specified Attribute. | ||
display_type: The optional type used to display the Attribute. | ||
""" | ||
|
||
trait_type: str | ||
value: Any | ||
display_type: Optional[str] = None | ||
|
||
|
||
@dataclass | ||
class Irc27Metadata: | ||
"""The IRC27 NFT standard schema. | ||
Attributes: | ||
standard: The metadata standard (IRC27). | ||
version: The metadata spec version (v1.0). | ||
type: 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. | ||
uri: URL pointing to the NFT file location. | ||
name: The human-readable name of the native token. | ||
collectionName: The human-readable collection name of the native token. | ||
royalties: Royalty payment addresses mapped to the payout percentage. | ||
issuerName: The human-readable name of the native token creator. | ||
description: The human-readable description of the token. | ||
attributes: Additional attributes which follow [OpenSea Metadata standards](https://docs.opensea.io/docs/metadata-standards). | ||
""" | ||
|
||
standard: str = field(default="IRC27", init=False) | ||
version: str = field(default="v1.0", init=False) | ||
type: str | ||
uri: str | ||
name: str | ||
collectionName: Optional[str] = None | ||
royalties: dict[str, float] = field(default_factory=dict) | ||
issuerName: Optional[str] = None | ||
description: Optional[str] = None | ||
attributes: List[Attribute] = field(default_factory=list) | ||
|
||
@staticmethod | ||
def from_dict(metadata_dict: dict): | ||
return from_dict(Irc27Metadata, metadata_dict) | ||
|
||
def as_hex(self): | ||
utf8_to_hex(json.dumps(self.as_dict(), separators=(",", ":"))) | ||
|
||
def as_feature(self): | ||
MetadataFeature(self.as_hex()) |
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 IOTA Stiftung | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import json | ||
from iota_sdk.types.common import HexStr | ||
from iota_sdk import utf8_to_hex, MetadataFeature | ||
from dataclasses import dataclass, field | ||
from typing import Optional | ||
from dacite import from_dict | ||
|
||
|
||
@dataclass | ||
class Irc30Metadata: | ||
"""The IRC30 native token metadata standard schema. | ||
Attributes: | ||
standard: The metadata standard (IRC30). | ||
name: The human-readable name of the native token. | ||
symbol: The symbol/ticker of the token. | ||
decimals: Number of decimals the token uses (divide the token amount by 10^decimals to get its user representation). | ||
description: The human-readable description of the token. | ||
url: URL pointing to more resources about the token. | ||
logoUrl: URL pointing to an image resource of the token logo. | ||
logo: The svg logo of the token encoded as a byte string. | ||
""" | ||
|
||
standard: str = field(default="IRC30", init=False) | ||
name: str | ||
symbol: str | ||
decimals: int | ||
description: Optional[str] = None | ||
url: Optional[str] = None | ||
logoUrl: Optional[str] = None | ||
logo: Optional[HexStr] = None | ||
|
||
@staticmethod | ||
def from_dict(metadata_dict: dict): | ||
return from_dict(Irc30Metadata, metadata_dict) | ||
|
||
def as_hex(self): | ||
utf8_to_hex(json.dumps(self.as_dict(), separators=(",", ":"))) | ||
|
||
def as_feature(self): | ||
MetadataFeature(self.as_hex()) |
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