-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNFTObject.sol
67 lines (59 loc) · 1.91 KB
/
NFTObject.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.17;
/// A object presentation of ERC721 NFT
library NFTObject {
struct ERC721 {
//object id
bytes32 id;
//contract address
address contractAddress;
uint256 tokenId;
// reference to metadata
bytes32 metadataId;
}
struct Metadata{
bytes32 id;
string name;
string description;
string image;
string animation_url;
string external_url;
string background_color;
string youtube_url;
string[] attributes_key;
string[] attributes_value;
}
struct Object{
bytes data;
address owner;
}
function newMetadata(
string memory name,
string memory description,
string memory image,
string memory animation_url,
string memory external_url,
string memory background_color,
string memory youtube_url,
string[] memory attributes_key,
string[] memory attributes_value
) internal pure returns(Metadata memory) {
bytes32 id = keccak256(abi.encodePacked(name, description, image, animation_url, external_url, background_color, youtube_url, attributes_key, attributes_value));
return Metadata(id, name, description, image, animation_url, external_url, background_color, youtube_url, attributes_key, attributes_value);
}
function newERC721(
address contractAddress,
uint256 tokenId,
bytes32 metadataId
) internal pure returns(ERC721 memory) {
bytes32 id = keccak256(abi.encodePacked(contractAddress, tokenId));
ERC721 memory data = ERC721(id, contractAddress, tokenId, metadataId);
return data;
}
function newERC721Object(
ERC721 memory data,
address owner
) internal pure returns(Object memory) {
return Object(abi.encode(data), owner);
}
}