2
2
pragma solidity ^ 0.8.24 ;
3
3
4
4
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol " ;
5
+ import {ERC1155Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol " ;
5
6
6
- contract Albums is OwnableUpgradeable {
7
+ contract Albums is OwnableUpgradeable , ERC1155Upgradeable {
7
8
8
9
struct Album {
9
10
uint16 id;
@@ -19,7 +20,6 @@ contract Albums is OwnableUpgradeable {
19
20
uint64 price;
20
21
string uri;
21
22
}
22
-
23
23
24
24
mapping (uint16 albumId = > Album) private _albums;
25
25
mapping (uint16 albumId = > mapping (uint16 songID = > Song)) private _albumSongs;
@@ -45,6 +45,7 @@ contract Albums is OwnableUpgradeable {
45
45
function initialize (
46
46
address _user
47
47
) external initializer {
48
+ __ERC1155_init ("" );
48
49
_transferOwnership (_user);
49
50
}
50
51
@@ -108,6 +109,33 @@ contract Albums is OwnableUpgradeable {
108
109
return songId;
109
110
}
110
111
112
+ function mintAlbum (uint16 albumId ) public payable returns (uint16 ) {
113
+ Album storage album = _albums[albumId];
114
+ require (album.maxSupply > 0 , "Album does not exist " );
115
+ require (album.price == msg .value , "Invalid price " );
116
+
117
+ _mint (msg .sender , album.id, 1 , "" ); // TODO: id should be formed by another way to avoid conflicts with song ids
118
+
119
+ emit ItemMinted (owner (), msg .sender , album.id, 0 );
120
+
121
+ return album.id;
122
+ }
123
+
124
+ function mintSong (uint16 albumId , uint16 songId ) public payable returns (uint16 ) {
125
+ Album storage album = _albums[albumId];
126
+ require (album.maxSupply > 0 , "Album does not exist " );
127
+
128
+ Song storage song = _albumSongs[albumId][songId];
129
+ require (song.maxSupply > 0 , "Song does not exist " );
130
+ require (song.price == msg .value , "Invalid price " );
131
+
132
+ _mint (msg .sender , song.id, 1 , "" ); // TODO: id should be formed by another way to avoid conflicts with album ids
133
+
134
+ emit ItemMinted (owner (), msg .sender , album.id, song.id);
135
+
136
+ return song.id;
137
+ }
138
+
111
139
function getAlbum (uint16 albumId ) external view returns (Album memory ) {
112
140
return _albums[albumId];
113
141
}
0 commit comments