Skip to content

Commit 65e5970

Browse files
feat: STUD-501 Update Stream token Metadata
1 parent c85c7e5 commit 65e5970

File tree

8 files changed

+314
-2
lines changed

8 files changed

+314
-2
lines changed

newm-server/src/main/kotlin/io/newm/server/config/repo/ConfigRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface ConfigRepository {
3838
const val CONFIG_KEY_MINT_CASH_REGISTER_COLLECTION_AMOUNT = "mint.cashRegisterCollectionAmount"
3939
const val CONFIG_KEY_MINT_CIP68_POLICY = "mint.cip68Policy"
4040
const val CONFIG_KEY_MINT_CIP68_SCRIPT_ADDRESS = "mint.cip68ScriptAddress"
41+
const val CONFIG_KEY_MINT_CIP68_UTXO_REFERENCE = "mint.cip68UtxoReference"
4142
const val CONFIG_KEY_MINT_SCRIPT_UTXO_REFERENCE = "mint.scriptUtxoReference"
4243
const val CONFIG_KEY_MINT_STARTER_TOKEN_UTXO_REFERENCE = "mint.starterTokenUtxoReference"
4344
const val CONFIG_KEY_MINT_MONITOR_PAYMENT_ADDRESS_TIMEOUT_MIN = "mint.monitorPaymentAddressTimeoutMin"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.newm.server.database.migration
2+
3+
import org.flywaydb.core.api.migration.BaseJavaMigration
4+
import org.flywaydb.core.api.migration.Context
5+
import org.jetbrains.exposed.sql.transactions.transaction
6+
7+
@Suppress("unused")
8+
class V79__ConfigUpdates : BaseJavaMigration() {
9+
override fun migrate(context: Context?) {
10+
transaction {
11+
exec("INSERT INTO config VALUES ('mint.cip68UtxoReference','<update_me>') ON CONFLICT(id) DO NOTHING")
12+
}
13+
}
14+
}

newm-server/src/main/kotlin/io/newm/server/features/cardano/repo/CardanoRepository.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import io.newm.chain.grpc.TransactionBuilderRequestKt
1313
import io.newm.chain.grpc.TransactionBuilderResponse
1414
import io.newm.chain.grpc.Utxo
1515
import io.newm.chain.grpc.VerifySignDataResponse
16+
import io.newm.server.features.cardano.model.CardanoNftSong
1617
import io.newm.server.features.cardano.model.EncryptionRequest
1718
import io.newm.server.features.cardano.model.GetWalletSongsResponse
1819
import io.newm.server.features.cardano.model.Key
19-
import io.newm.server.features.cardano.model.CardanoNftSong
2020
import io.newm.server.features.song.model.SongFilters
2121
import io.newm.server.typealiases.UserId
22-
import kotlinx.coroutines.flow.Flow
2322
import java.util.UUID
23+
import kotlinx.coroutines.flow.Flow
2424

2525
interface CardanoRepository {
2626
suspend fun saveKey(
@@ -121,6 +121,14 @@ interface CardanoRepository {
121121
*/
122122
suspend fun saveScriptAddressToWhitelist(scriptAddress: String)
123123

124+
/**
125+
* Get the utxo(s) holding this native asset
126+
*/
127+
suspend fun queryUtxoByNativeAsset(
128+
policyHex: String,
129+
nameHex: String
130+
): Utxo
131+
124132
companion object {
125133
const val MUTEX_NAME = "newm-server"
126134

newm-server/src/main/kotlin/io/newm/server/features/cardano/repo/CardanoRepositoryImpl.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ internal class CardanoRepositoryImpl(
220220
return response.utxosList
221221
}
222222

223+
override suspend fun queryUtxoByNativeAsset(
224+
policyHex: String,
225+
nameHex: String
226+
): Utxo {
227+
val response = client.queryUtxoByNativeAsset(
228+
queryByNativeAssetRequest {
229+
policy = policyHex
230+
name = nameHex
231+
}
232+
)
233+
return response
234+
}
235+
223236
override fun signTransaction(
224237
transactionIdBytes: ByteArray,
225238
signingKeys: List<Key>

newm-server/src/main/kotlin/io/newm/server/features/minting/MintingMessageReceiver.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,19 @@ class MintingMessageReceiver : SqsMessageReceiver {
4646
override suspend fun onMessageReceived(message: Message) {
4747
log.info { "received: ${message.body()}" }
4848
val mintingStatusSqsMessage: MintingStatusSqsMessage = json.decodeFromString(message.body())
49+
4950
val dbSong = songRepository.get(mintingStatusSqsMessage.songId)
51+
if (mintingStatusSqsMessage.mintingStatus == MintingStatus.UpdateTokenMetadataRequested && dbSong.mintingStatus in listOf(
52+
MintingStatus.Minted,
53+
MintingStatus.Released
54+
)
55+
) {
56+
log.info { "Updating token metadata for ${dbSong.id} ..." }
57+
val mintInfo = mintingRepository.updateTokenMetadata(dbSong)
58+
log.info { "Updated ${dbSong.id}: $mintInfo" }
59+
return
60+
}
61+
5062
if (dbSong.mintingStatus == MintingStatus.Released) {
5163
// Sometimes, we will manually reprocess a song. If it is already minted & released successfully when we do
5264
// dead-letter queue reprocessing, we can safely ignore these messages and let them be successfully
@@ -340,6 +352,8 @@ class MintingMessageReceiver : SqsMessageReceiver {
340352
} else {
341353
val mintInfo = mintingRepository.mint(song)
342354

355+
log.info { "Minted ${song.id}: $mintInfo" }
356+
343357
// Update the song record with the minting info
344358
songRepository.update(
345359
songId = mintingStatusSqsMessage.songId,

newm-server/src/main/kotlin/io/newm/server/features/minting/repo/MintingRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ interface MintingRepository {
1313
*/
1414
suspend fun mint(song: Song): MintInfo
1515

16+
suspend fun updateTokenMetadata(song: Song): MintInfo
17+
1618
fun getTokenAgreementFileIndex(policyId: String): Int
1719

1820
fun getAudioClipFileIndex(policyId: String): Int

0 commit comments

Comments
 (0)