-
Notifications
You must be signed in to change notification settings - Fork 6
feat: MOBILE-388 - add multi-chain NFT song api #715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
30 changes: 30 additions & 0 deletions
30
newm-server/src/main/kotlin/io/newm/server/compression/CompressionInstall.kt
This file contains hidden or 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,30 @@ | ||
| package io.newm.server.compression | ||
|
|
||
| import io.ktor.server.application.Application | ||
| import io.ktor.server.application.install | ||
| import io.ktor.server.plugins.compression.Compression | ||
| import io.ktor.server.plugins.compression.condition | ||
| import io.ktor.server.plugins.compression.deflate | ||
| import io.ktor.server.plugins.compression.gzip | ||
| import io.ktor.server.plugins.compression.minimumSize | ||
| import io.ktor.server.plugins.compression.zstd.zstd | ||
| import io.ktor.server.request.path | ||
| import io.newm.shared.ktx.getConfigLong | ||
| import io.newm.shared.ktx.getConfigStrings | ||
|
|
||
| fun Application.installCompression() { | ||
| val minSize = environment.getConfigLong("compression.minSize") | ||
| val pathPrefixes = environment.getConfigStrings("compression.pathPrefixes") | ||
|
|
||
| install(Compression) { | ||
| minimumSize(minSize) | ||
| condition { | ||
| val path = request.path() | ||
| pathPrefixes.any(path::startsWith) | ||
| } | ||
|
|
||
| zstd { priority = 1.0 } | ||
| gzip { priority = 0.9 } | ||
| deflate { priority = 0.8 } | ||
| } | ||
| } |
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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
3 changes: 2 additions & 1 deletion
3
newm-server/src/main/kotlin/io/newm/server/features/ethereum/repo/EthereumRepository.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| package io.newm.server.features.ethereum.repo | ||
|
|
||
| import io.newm.server.features.ethereum.model.EthereumNftSong | ||
| import io.newm.server.typealiases.UserId | ||
|
|
||
| interface EthereumRepository { | ||
| suspend fun getNftSongs(ownerAddress: String): List<EthereumNftSong> | ||
| suspend fun getWalletNftSongs(userId: UserId): List<EthereumNftSong> | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -12,18 +12,26 @@ import io.newm.server.features.ethereum.model.EthereumNft | |
| import io.newm.server.features.ethereum.model.EthereumNftSong | ||
| import io.newm.server.features.ethereum.model.GetNftsByOwnerResponse | ||
| import io.newm.server.features.ethereum.parser.parseSong | ||
| import io.newm.server.features.user.database.UserEntity | ||
| import io.newm.server.ktx.checkedBody | ||
| import io.newm.server.ktx.getSecureConfigString | ||
| import io.newm.server.typealiases.UserId | ||
| import io.newm.shared.ktx.getConfigString | ||
| import org.jetbrains.exposed.sql.transactions.transaction | ||
|
|
||
| internal class EthereumRepositoryImpl( | ||
| private val client: HttpClient, | ||
| private val environment: ApplicationEnvironment | ||
| ) : EthereumRepository { | ||
| private val logger = KotlinLogging.logger {} | ||
|
|
||
| override suspend fun getNftSongs(ownerAddress: String): List<EthereumNftSong> { | ||
| logger.debug { "getNftSongs: ownerAddress = $ownerAddress" } | ||
| override suspend fun getWalletNftSongs(userId: UserId): List<EthereumNftSong> { | ||
| logger.debug { "getWalletNftSongs: userId = $userId" } | ||
|
|
||
| // Temporary test hook until Ethereum wallet connections are implemented | ||
| val email = transaction { UserEntity[userId].email } | ||
| if (!email.endsWith("@newm.io")) return emptyList() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏼 |
||
| val address = "0x89fd6e1e7a737293dc9ecaee118753b7abdf5e37" | ||
|
|
||
| val apiUrl = environment.getConfigString("alchemy.apiUrl") | ||
| val apiKey = environment.getSecureConfigString("alchemy.apiKey") | ||
|
|
@@ -34,7 +42,7 @@ internal class EthereumRepositoryImpl( | |
| delayMillis { 500L } | ||
| } | ||
| accept(ContentType.Application.Json) | ||
| parameter("owner", ownerAddress) | ||
| parameter("owner", address) | ||
| }.checkedBody<GetNftsByOwnerResponse>() | ||
| .ownedNfts | ||
| .mapNotNull(EthereumNft::parseSong) | ||
|
|
||
10 changes: 10 additions & 0 deletions
10
newm-server/src/main/kotlin/io/newm/server/features/nftsong/NftSongKoinModule.kt
This file contains hidden or 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,10 @@ | ||
| package io.newm.server.features.nftsong | ||
|
|
||
| import io.newm.server.features.nftsong.repo.NftSongRepository | ||
| import io.newm.server.features.nftsong.repo.NftSongRepositoryImpl | ||
| import org.koin.dsl.module | ||
|
|
||
| val nftSongKoinModule = | ||
| module { | ||
| single<NftSongRepository> { NftSongRepositoryImpl(get(), get()) } | ||
| } |
20 changes: 20 additions & 0 deletions
20
newm-server/src/main/kotlin/io/newm/server/features/nftsong/NftSongRoutes.kt
This file contains hidden or 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,20 @@ | ||
| package io.newm.server.features.nftsong | ||
|
|
||
| import io.ktor.server.auth.authenticate | ||
| import io.ktor.server.response.respond | ||
| import io.ktor.server.routing.Routing | ||
| import io.newm.server.auth.jwt.AUTH_JWT | ||
| import io.newm.server.features.nftsong.repo.NftSongRepository | ||
| import io.newm.server.ktx.myUserId | ||
| import io.newm.shared.koin.inject | ||
| import io.newm.shared.ktx.get | ||
|
|
||
| fun Routing.createNftSongRoutes() { | ||
| val repository: NftSongRepository by inject() | ||
|
|
||
| authenticate(AUTH_JWT) { | ||
| get("/v1/nft/songs") { | ||
| respond(repository.getNftSongs(myUserId)) | ||
| } | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
newm-server/src/main/kotlin/io/newm/server/features/nftsong/model/NftChainMetadata.kt
This file contains hidden or 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,21 @@ | ||
| package io.newm.server.features.nftsong.model | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| sealed interface NftChainMetadata { | ||
| @Serializable | ||
| data class Cardano( | ||
| val fingerprint: String, | ||
| val policyId: String, | ||
| val assetName: String, | ||
| val isStreamToken: Boolean | ||
| ) : NftChainMetadata | ||
|
|
||
| @Serializable | ||
| data class Ethereum( | ||
| val contractAddress: String, | ||
| val tokenType: String, | ||
| val tokenId: String, | ||
|
AndrewWestberg marked this conversation as resolved.
|
||
| ) : NftChainMetadata | ||
| } | ||
9 changes: 9 additions & 0 deletions
9
newm-server/src/main/kotlin/io/newm/server/features/nftsong/model/NftChainType.kt
This file contains hidden or 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,9 @@ | ||
| package io.newm.server.features.nftsong.model | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| enum class NftChainType { | ||
| Cardano, | ||
| Ethereum | ||
| } |
21 changes: 21 additions & 0 deletions
21
newm-server/src/main/kotlin/io/newm/server/features/nftsong/model/NftSong.kt
This file contains hidden or 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,21 @@ | ||
| package io.newm.server.features.nftsong.model | ||
|
|
||
| import kotlinx.serialization.Contextual | ||
| import kotlinx.serialization.Serializable | ||
| import java.util.UUID | ||
|
|
||
| @Serializable | ||
| data class NftSong( | ||
| @Contextual | ||
| val id: UUID, | ||
| val title: String, | ||
| val imageUrl: String, | ||
| val audioUrl: String, | ||
| val duration: Long, | ||
| val artists: List<String>, | ||
| val genres: List<String>, | ||
| val moods: List<String>, | ||
| val amount: Long, | ||
| val chainType: NftChainType, | ||
| val chainMetadata: NftChainMetadata | ||
| ) |
8 changes: 8 additions & 0 deletions
8
newm-server/src/main/kotlin/io/newm/server/features/nftsong/repo/NftSongRepository.kt
This file contains hidden or 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,8 @@ | ||
| package io.newm.server.features.nftsong.repo | ||
|
|
||
| import io.newm.server.features.nftsong.model.NftSong | ||
| import io.newm.server.typealiases.UserId | ||
|
|
||
| interface NftSongRepository { | ||
| suspend fun getNftSongs(userId: UserId): List<NftSong> | ||
| } |
68 changes: 68 additions & 0 deletions
68
newm-server/src/main/kotlin/io/newm/server/features/nftsong/repo/NftSongRepositoryImpl.kt
This file contains hidden or 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,68 @@ | ||
| package io.newm.server.features.nftsong.repo | ||
|
|
||
| import io.newm.server.features.cardano.model.CardanoNftSong | ||
| import io.newm.server.features.cardano.repo.CardanoRepository | ||
| import io.newm.server.features.ethereum.model.EthereumNftSong | ||
| import io.newm.server.features.ethereum.repo.EthereumRepository | ||
| import io.newm.server.features.nftsong.model.NftChainMetadata | ||
| import io.newm.server.features.nftsong.model.NftChainType | ||
| import io.newm.server.features.nftsong.model.NftSong | ||
| import io.newm.server.typealiases.UserId | ||
|
|
||
| internal class NftSongRepositoryImpl( | ||
| private val cardanoRepository: CardanoRepository, | ||
| private val ethereumRepository: EthereumRepository | ||
| ) : NftSongRepository { | ||
| override suspend fun getNftSongs(userId: UserId): List<NftSong> { | ||
| val nftSongs = mutableListOf<NftSong>() | ||
|
|
||
| nftSongs += cardanoRepository | ||
| .getWalletNftSongs(userId, includeLegacy = true, useDripDropz = false) | ||
| .map { it.toNftSong() } | ||
|
|
||
| nftSongs += ethereumRepository | ||
| .getWalletNftSongs(userId) | ||
| .map { it.toNftSong() } | ||
|
|
||
| return nftSongs | ||
| } | ||
|
|
||
| private fun CardanoNftSong.toNftSong(): NftSong = | ||
| NftSong( | ||
| id = id, | ||
| title = title, | ||
| imageUrl = imageUrl, | ||
| audioUrl = audioUrl, | ||
| duration = duration, | ||
| artists = artists, | ||
| genres = genres, | ||
| moods = moods, | ||
| amount = amount, | ||
| chainType = NftChainType.Cardano, | ||
| chainMetadata = NftChainMetadata.Cardano( | ||
| fingerprint = fingerprint, | ||
| policyId = policyId, | ||
| assetName = assetName, | ||
| isStreamToken = isStreamToken | ||
| ) | ||
| ) | ||
|
|
||
| private fun EthereumNftSong.toNftSong(): NftSong = | ||
| NftSong( | ||
| id = id, | ||
| title = title, | ||
| imageUrl = imageUrl, | ||
| audioUrl = audioUrl, | ||
| duration = duration, | ||
| artists = artists, | ||
| genres = genres, | ||
| moods = moods, | ||
| amount = amount, | ||
| chainType = NftChainType.Ethereum, | ||
| chainMetadata = NftChainMetadata.Ethereum( | ||
| contractAddress = contractAddress, | ||
| tokenType = tokenType, | ||
| tokenId = tokenId | ||
| ) | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.