SC CODE: // DeroBeats Registry Contract
// Catalog of all songs uploaded to the platform
// Version: 1.0
Function Initialize() Uint64
10 STORE("owner", SIGNER())
20 STORE("total_songs", 0)
30 STORE("platform_name", "DeroBeats")
40 STORE("platform_url", "derobeats.tela")
50 RETURN 0
End Function
// Register a new song on the platform
// Can be called by anyone to submit their song
Function RegisterSong(songSCID String, title String, artist String, genre String, ipfsHash String) Uint64
10 // Validate inputs
20 IF LEN(songSCID) != 64 THEN GOTO 999
30 IF LEN(title) < 1 THEN GOTO 999
40 IF LEN(artist) < 1 THEN GOTO 999
50 // Check if song already registered
60 IF EXISTS(songSCID + "_registered") THEN GOTO 999
70 // Get current song count
80 DIM count as Uint64
90 LET count = LOAD("total_songs")
100 // Store song in list
110 STORE("song_" + count, songSCID)
120 // Store song metadata
130 STORE(songSCID + "_registered", 1)
140 STORE(songSCID + "_title", title)
150 STORE(songSCID + "_artist", artist)
160 STORE(songSCID + "_artist_addr", SIGNER())
165 DIM g as String
166 IF LEN(genre) < 1 THEN LET g = "Unknown" ELSE LET g = genre
170 STORE(songSCID + "_genre", g)
180 STORE(songSCID + "_ipfs", ipfsHash)
185 STORE(songSCID + "_upvotes", 0)
190 STORE(songSCID + "_timestamp", BLOCK_TIMESTAMP())
200 STORE(songSCID + "_topoheight", BLOCK_TOPOHEIGHT())
210 // Store by artist (for artist profile queries)
220 DIM artist_count as Uint64
230 LET artist_count = LOAD(SIGNER() + "_song_count")
240 STORE(SIGNER() + "_song_" + artist_count, songSCID)
250 STORE(SIGNER() + "_song_count", artist_count + 1)
260 // Store by genre (for genre filtering)
270 DIM genre_count as Uint64
280 LET genre_count = LOAD(g + "_count")
290 STORE(g + "_song_" + genre_count, songSCID)
300 STORE(g + "_count", genre_count + 1)
310 // Increment total
320 STORE("total_songs", count + 1)
330 // Emit success
340 RETURN 0
999 // Error
1000 RETURN 1
End Function
// Update song metadata (only by original artist)
Function UpdateSong(songSCID String, title String, genre String, ipfsHash String) Uint64
10 // Verify caller is original artist
20 IF SIGNER() != LOAD(songSCID + "_artist_addr") THEN GOTO 999
30 // Verify song exists
40 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
50 // Update allowed fields
60 IF LEN(title) > 0 THEN STORE(songSCID + "_title", title)
70 IF LEN(genre) > 0 THEN STORE(songSCID + "_genre", genre)
80 IF LEN(ipfsHash) > 0 THEN STORE(songSCID + "_ipfs", ipfsHash)
90 // Update timestamp
100 STORE(songSCID + "_updated", BLOCK_TIMESTAMP())
110 RETURN 0
999 // Error - unauthorized or not found
1000 RETURN 1
End Function
// Feature/promote a song (owner only)
Function FeatureSong(songSCID String) Uint64
10 IF SIGNER() != LOAD("owner") THEN GOTO 999
20 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
30 DIM featured_count as Uint64
40 LET featured_count = LOAD("featured_count")
50 STORE("featured_" + featured_count, songSCID)
60 STORE("featured_count", featured_count + 1)
70 STORE(songSCID + "_featured", 1)
80 STORE(songSCID + "_featured_at", BLOCK_TIMESTAMP())
90 RETURN 0
999 RETURN 1
End Function
// Unfeature a song (owner only)
Function UnfeatureSong(songSCID String) Uint64
10 IF SIGNER() != LOAD("owner") THEN GOTO 999
20 STORE(songSCID + "_featured", 0)
30 RETURN 0
999 RETURN 1
End Function
// Tag a song with a custom tag (for discovery)
Function TagSong(songSCID String, tag String) Uint64
10 // Verify song exists
20 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
30 // Only artist can tag their song
40 IF SIGNER() != LOAD(songSCID + "_artist_addr") THEN GOTO 999
50 // Store tag
60 DIM tag_count as Uint64
70 LET tag_count = LOAD(songSCID + "_tag_count")
80 STORE(songSCID + "_tag_" + tag_count, tag)
90 STORE(songSCID + "_tag_count", tag_count + 1)
100 // Add to tag index
110 DIM tagged_count as Uint64
120 LET tagged_count = LOAD(tag + "_tagged_count")
130 STORE(tag + "_tagged_" + tagged_count, songSCID)
140 STORE(tag + "_tagged_count", tagged_count + 1)
150 RETURN 0
999 RETURN 1
End Function
// Verify an artist (owner only)
Function VerifyArtist(artistAddr String) Uint64
10 IF SIGNER() != LOAD("owner") THEN GOTO 999
20 STORE(artistAddr + "_verified", 1)
30 STORE(artistAddr + "_verified_at", BLOCK_TIMESTAMP())
40 RETURN 0
999 RETURN 1
End Function
// Report inappropriate content (for moderation)
Function ReportSong(songSCID String, reason String) Uint64
10 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
20 DIM report_count as Uint64
30 LET report_count = LOAD(songSCID + "_report_count")
40 // Store report
50 STORE(songSCID + "_report_" + report_count + "_by", SIGNER())
60 STORE(songSCID + "_report_" + report_count + "_reason", reason)
70 STORE(songSCID + "_report_" + report_count + "_time", BLOCK_TIMESTAMP())
80 STORE(songSCID + "_report_count", report_count + 1)
90 RETURN 0
999 RETURN 1
End Function
// Upvote a song (one vote per address per song)
Function UpvoteSong(songSCID String) Uint64
10 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
20 IF EXISTS(SIGNER() + "_upvoted_" + songSCID) THEN GOTO 999
30 DIM upvotes as Uint64
40 LET upvotes = LOAD(songSCID + "_upvotes")
50 STORE(songSCID + "_upvotes", upvotes + 1)
60 STORE(SIGNER() + "_upvoted_" + songSCID, 1)
70 RETURN 0
999 RETURN 1
End Function
// Remove a song (owner only, after reports)
Function RemoveSong(songSCID String) Uint64
10 IF SIGNER() != LOAD("owner") THEN GOTO 999
20 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
30 STORE(songSCID + "_removed", 1)
40 STORE(songSCID + "_removed_at", BLOCK_TIMESTAMP())
50 RETURN 0
999 RETURN 1
End Function
// Get total number of songs
Function GetTotalSongs() Uint64
10 RETURN LOAD("total_songs")
End Function
// Get song SCID by index
Function GetSong(index Uint64) String
10 RETURN LOAD("song_" + index)
End Function
// Get song count by artist
Function GetArtistSongCount(artistAddr String) Uint64
10 RETURN LOAD(artistAddr + "_song_count")
End Function
// Get song count by genre
Function GetGenreSongCount(genre String) Uint64
10 RETURN LOAD(genre + "_count")
End Function
// Get featured songs count
Function GetFeaturedCount() Uint64
10 RETURN LOAD("featured_count")
End Function
// Transfer ownership (current owner only)
Function TransferOwnership(newOwner String) Uint64
10 IF SIGNER() != LOAD("owner") THEN GOTO 999
20 STORE("owner", newOwner)
30 RETURN 0
999 RETURN 1
End Function
|
| SC Arguments: [Name:SC_ACTION Type:uint64 Value:'1' Name:SC_CODE Type:string Value:'// DeroBeats Registry Contract
// Catalog of all songs uploaded to the platform
// Version: 1.0
Function Initialize() Uint64
10 STORE("owner", SIGNER())
20 STORE("total_songs", 0)
30 STORE("platform_name", "DeroBeats")
40 STORE("platform_url", "derobeats.tela")
50 RETURN 0
End Function
// Register a new song on the platform
// Can be called by anyone to submit their song
Function RegisterSong(songSCID String, title String, artist String, genre String, ipfsHash String) Uint64
10 // Validate inputs
20 IF LEN(songSCID) != 64 THEN GOTO 999
30 IF LEN(title) < 1 THEN GOTO 999
40 IF LEN(artist) < 1 THEN GOTO 999
50 // Check if song already registered
60 IF EXISTS(songSCID + "_registered") THEN GOTO 999
70 // Get current song count
80 DIM count as Uint64
90 LET count = LOAD("total_songs")
100 // Store song in list
110 STORE("song_" + count, songSCID)
120 // Store song metadata
130 STORE(songSCID + "_registered", 1)
140 STORE(songSCID + "_title", title)
150 STORE(songSCID + "_artist", artist)
160 STORE(songSCID + "_artist_addr", SIGNER())
165 DIM g as String
166 IF LEN(genre) < 1 THEN LET g = "Unknown" ELSE LET g = genre
170 STORE(songSCID + "_genre", g)
180 STORE(songSCID + "_ipfs", ipfsHash)
185 STORE(songSCID + "_upvotes", 0)
190 STORE(songSCID + "_timestamp", BLOCK_TIMESTAMP())
200 STORE(songSCID + "_topoheight", BLOCK_TOPOHEIGHT())
210 // Store by artist (for artist profile queries)
220 DIM artist_count as Uint64
230 LET artist_count = LOAD(SIGNER() + "_song_count")
240 STORE(SIGNER() + "_song_" + artist_count, songSCID)
250 STORE(SIGNER() + "_song_count", artist_count + 1)
260 // Store by genre (for genre filtering)
270 DIM genre_count as Uint64
280 LET genre_count = LOAD(g + "_count")
290 STORE(g + "_song_" + genre_count, songSCID)
300 STORE(g + "_count", genre_count + 1)
310 // Increment total
320 STORE("total_songs", count + 1)
330 // Emit success
340 RETURN 0
999 // Error
1000 RETURN 1
End Function
// Update song metadata (only by original artist)
Function UpdateSong(songSCID String, title String, genre String, ipfsHash String) Uint64
10 // Verify caller is original artist
20 IF SIGNER() != LOAD(songSCID + "_artist_addr") THEN GOTO 999
30 // Verify song exists
40 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
50 // Update allowed fields
60 IF LEN(title) > 0 THEN STORE(songSCID + "_title", title)
70 IF LEN(genre) > 0 THEN STORE(songSCID + "_genre", genre)
80 IF LEN(ipfsHash) > 0 THEN STORE(songSCID + "_ipfs", ipfsHash)
90 // Update timestamp
100 STORE(songSCID + "_updated", BLOCK_TIMESTAMP())
110 RETURN 0
999 // Error - unauthorized or not found
1000 RETURN 1
End Function
// Feature/promote a song (owner only)
Function FeatureSong(songSCID String) Uint64
10 IF SIGNER() != LOAD("owner") THEN GOTO 999
20 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
30 DIM featured_count as Uint64
40 LET featured_count = LOAD("featured_count")
50 STORE("featured_" + featured_count, songSCID)
60 STORE("featured_count", featured_count + 1)
70 STORE(songSCID + "_featured", 1)
80 STORE(songSCID + "_featured_at", BLOCK_TIMESTAMP())
90 RETURN 0
999 RETURN 1
End Function
// Unfeature a song (owner only)
Function UnfeatureSong(songSCID String) Uint64
10 IF SIGNER() != LOAD("owner") THEN GOTO 999
20 STORE(songSCID + "_featured", 0)
30 RETURN 0
999 RETURN 1
End Function
// Tag a song with a custom tag (for discovery)
Function TagSong(songSCID String, tag String) Uint64
10 // Verify song exists
20 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
30 // Only artist can tag their song
40 IF SIGNER() != LOAD(songSCID + "_artist_addr") THEN GOTO 999
50 // Store tag
60 DIM tag_count as Uint64
70 LET tag_count = LOAD(songSCID + "_tag_count")
80 STORE(songSCID + "_tag_" + tag_count, tag)
90 STORE(songSCID + "_tag_count", tag_count + 1)
100 // Add to tag index
110 DIM tagged_count as Uint64
120 LET tagged_count = LOAD(tag + "_tagged_count")
130 STORE(tag + "_tagged_" + tagged_count, songSCID)
140 STORE(tag + "_tagged_count", tagged_count + 1)
150 RETURN 0
999 RETURN 1
End Function
// Verify an artist (owner only)
Function VerifyArtist(artistAddr String) Uint64
10 IF SIGNER() != LOAD("owner") THEN GOTO 999
20 STORE(artistAddr + "_verified", 1)
30 STORE(artistAddr + "_verified_at", BLOCK_TIMESTAMP())
40 RETURN 0
999 RETURN 1
End Function
// Report inappropriate content (for moderation)
Function ReportSong(songSCID String, reason String) Uint64
10 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
20 DIM report_count as Uint64
30 LET report_count = LOAD(songSCID + "_report_count")
40 // Store report
50 STORE(songSCID + "_report_" + report_count + "_by", SIGNER())
60 STORE(songSCID + "_report_" + report_count + "_reason", reason)
70 STORE(songSCID + "_report_" + report_count + "_time", BLOCK_TIMESTAMP())
80 STORE(songSCID + "_report_count", report_count + 1)
90 RETURN 0
999 RETURN 1
End Function
// Upvote a song (one vote per address per song)
Function UpvoteSong(songSCID String) Uint64
10 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
20 IF EXISTS(SIGNER() + "_upvoted_" + songSCID) THEN GOTO 999
30 DIM upvotes as Uint64
40 LET upvotes = LOAD(songSCID + "_upvotes")
50 STORE(songSCID + "_upvotes", upvotes + 1)
60 STORE(SIGNER() + "_upvoted_" + songSCID, 1)
70 RETURN 0
999 RETURN 1
End Function
// Remove a song (owner only, after reports)
Function RemoveSong(songSCID String) Uint64
10 IF SIGNER() != LOAD("owner") THEN GOTO 999
20 IF !EXISTS(songSCID + "_registered") THEN GOTO 999
30 STORE(songSCID + "_removed", 1)
40 STORE(songSCID + "_removed_at", BLOCK_TIMESTAMP())
50 RETURN 0
999 RETURN 1
End Function
// Get total number of songs
Function GetTotalSongs() Uint64
10 RETURN LOAD("total_songs")
End Function
// Get song SCID by index
Function GetSong(index Uint64) String
10 RETURN LOAD("song_" + index)
End Function
// Get song count by artist
Function GetArtistSongCount(artistAddr String) Uint64
10 RETURN LOAD(artistAddr + "_song_count")
End Function
// Get song count by genre
Function GetGenreSongCount(genre String) Uint64
10 RETURN LOAD(genre + "_count")
End Function
// Get featured songs count
Function GetFeaturedCount() Uint64
10 RETURN LOAD("featured_count")
End Function
// Transfer ownership (current owner only)
Function TransferOwnership(newOwner String) Uint64
10 IF SIGNER() != LOAD("owner") THEN GOTO 999
20 STORE("owner", newOwner)
30 RETURN 0
999 RETURN 1
End Function
'] |