Skip to content

Commit

Permalink
unique attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedsmiai committed Sep 11, 2023
1 parent dd1ddb1 commit 8bfa8be
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/nftkit/opa/DynamicPolicy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object DynamicPolicy {

}else if(nftMetadata.uniqueNftMetadata != null){
data.put("image", nftMetadata.uniqueNftMetadata.ipfsCid)
nftMetadata.uniqueNftMetadata.attributes?.forEach { data.put(it.name, it.value) }
nftMetadata.uniqueNftMetadata.attributes?.forEach { data.put(it.name, it.value.toString()) }


}else if (nftMetadata.algorandNftMetadata != null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import id.walt.nftkit.utilis.Common
import io.javalin.http.Context
import io.javalin.plugin.openapi.dsl.document
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json

@Serializable
data class PolkadotUniqueDeployRequest(
Expand Down Expand Up @@ -70,7 +71,7 @@ object PolkadotUniqueNftController {

val tokenDataResponse = PolkadotNftService.fetchUniqueNFTsMetadata(network, collectionId, tokenId)
val result = PolkadotNftService.parseNftMetadataUniqueResponse(tokenDataResponse!!)
ctx.json(result)
ctx.result(Json.encodeToString(result))
}

fun fetchUniqueNftMetadataDocs() = document().operation {
Expand Down
25 changes: 12 additions & 13 deletions src/main/kotlin/id/walt/nftkit/services/PolkadotNftService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import kotlinx.serialization.json.*
import kotlinx.serialization.json.Json.Default.decodeFromJsonElement

enum class PolkadotParachain {
ASTAR,
Expand Down Expand Up @@ -74,13 +73,13 @@ data class SubscanEvmErc721CollectiblesResult(
@Serializable
data class UniqueNftMetadata(
val fullUrl: String,
val ipfsCid: String,
val ipfsCid: String?=null,
val attributes: List<Attribute>?=null
){
@Serializable
data class Attribute(
val name: String,
var value: String,
var value: JsonElement?,
)
}

Expand Down Expand Up @@ -171,19 +170,19 @@ object PolkadotNftService {
}

fun parseNftMetadataUniqueResponse(tokens: TokenDataResponse): UniqueNftMetadata {
val attributes = tokens.data?.get(0)!!.attributes!!.values.map {
UniqueNftMetadata.Attribute(
it.jsonObject["name"]!!.jsonObject["_"]!!.jsonPrimitive.content,
it.jsonObject["value"]!!.jsonObject["_"]!!.jsonPrimitive.content
)

val metadata = (tokens.data ?: throw IllegalArgumentException("Tokens have no data?"))[0]
val attributes = metadata.attributes?.values?.map {
Json.decodeFromJsonElement<UniqueNftMetadata.Attribute>(it)
}
val tokenImage = metadata.image!!
return UniqueNftMetadata(
tokens.data[0].image!!.jsonObject["fullUrl"]!!.jsonPrimitive.content,
tokens.data[0].image!!.jsonObject["ipfsCid"]!!.jsonPrimitive.content, attributes
fullUrl = tokenImage["fullUrl"]!!.jsonPrimitive.content,
ipfsCid = tokenImage["ipfsCid"]!!.jsonPrimitive.content,
attributes
)
}


private fun getUniqueNetworkIndexerUrl(uniqueNetwork: UniqueNetwork): String {
return when(uniqueNetwork){
UniqueNetwork.UNIQUE -> WaltIdServices.loadIndexers().indexersUrl.uniqueUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ object VerificationService {
if(result != null && result.data != null){
val uniqueNftMetadata= PolkadotNftService.parseNftMetadataUniqueResponse(result)
if(uniqueNftMetadata!!.attributes?.filter {
(it.name.equals(name) && it.value.equals(
(it.name.equals(name) && it.value.toString().equals(
value,
true
)) || (value == null && name.equals(it.name))
Expand Down

0 comments on commit 8bfa8be

Please sign in to comment.