Skip to content

Commit 4bbe499

Browse files
feat: mint albums and songs
1 parent 0b6910a commit 4bbe499

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

backend/contracts/Albums.sol

+30-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
pragma solidity ^0.8.24;
33

44
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
5+
import {ERC1155Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
56

6-
contract Albums is OwnableUpgradeable {
7+
contract Albums is OwnableUpgradeable, ERC1155Upgradeable {
78

89
struct Album {
910
uint16 id;
@@ -19,7 +20,6 @@ contract Albums is OwnableUpgradeable {
1920
uint64 price;
2021
string uri;
2122
}
22-
2323

2424
mapping(uint16 albumId => Album) private _albums;
2525
mapping(uint16 albumId => mapping(uint16 songID => Song)) private _albumSongs;
@@ -45,6 +45,7 @@ contract Albums is OwnableUpgradeable {
4545
function initialize(
4646
address _user
4747
) external initializer {
48+
__ERC1155_init("");
4849
_transferOwnership(_user);
4950
}
5051

@@ -108,6 +109,33 @@ contract Albums is OwnableUpgradeable {
108109
return songId;
109110
}
110111

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+
111139
function getAlbum(uint16 albumId) external view returns (Album memory) {
112140
return _albums[albumId];
113141
}

0 commit comments

Comments
 (0)