Skip to content

Commit

Permalink
Merge pull request #130 from walt-id/feat/nftOwnershipAlgorand
Browse files Browse the repository at this point in the history
Feat/nft ownership with traits on algorand
  • Loading branch information
SuperBatata authored Jul 30, 2023
2 parents 78bfef4 + 82ce16a commit 7deb019
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/main/kotlin/id/walt/nftkit/rest/NftKitApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ object NftKitApi {
"chain/{chain}/verifyNftOwnership",
documented(VerificationController.verifyAlgorandNftOwnershipDocs(), VerificationController::verifyAlgorandNftOwnership)
)
get(
"chain/{chain}/verifyNftOwnershipWithTraits",
documented(VerificationController.verifyAlgorandNftOwnershipWithTraitsDocs(), VerificationController::verifyAlgorandNftOwnershipWithTraits)
)
get(
"chain/{chain}/contract/{contractAddress}/verifyNftOwnership",
documented(VerificationController.verifyNftOwnershipDocs(), VerificationController::verifyNftOwnership)
Expand Down
25 changes: 25 additions & 0 deletions src/main/kotlin/id/walt/nftkit/rest/VerificationController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@ import kotlinx.serialization.Serializable

object VerificationController {


fun verifyAlgorandNftOwnershipWithTraits(ctx: Context){
val chain = ctx.pathParam("chain")
val assetId = ctx.queryParam("assetId") ?: throw BadRequestResponse("Account not specified")
val account = ctx.queryParam("account") ?: throw BadRequestResponse("Account not specified")
val traitType = ctx.queryParam("trait") ?: throw BadRequestResponse("Trait not specified")
val traitValue = ctx.queryParam("value") ?: throw BadRequestResponse("Trait value not specified")
val result = VerificationService.NFTAlgorandOwnershipVerificationWithTraits(AlgorandChain.valueOf(chain.uppercase()), account!!, assetId!!, traitType!! , traitValue!!)
ctx.json(result)
}

fun verifyAlgorandNftOwnershipWithTraitsDocs() = document().operation {
it.summary("NFT ownership verification on algorand with traits")
.operationId("verifyAlgorandNftOwnershipWithTraits").addTagsItem("NFT verification")
}.pathParam<String>("chain") {
it.schema<AlgorandChain> { }
}.queryParam<String>("assetId") {
}.queryParam<String>("account") {
it.required(true)
}.queryParam<String>("trait") {
it.required(true)
}.queryParam<String>("value") {
it.required(true)
}.json<Boolean>("200") { }

fun verifyAlgorandNftOwnership(ctx: Context) {
val chain = ctx.pathParam("chain")
val assetId = ctx.queryParam("assetId") ?: throw BadRequestResponse("Account not specified")
Expand Down
24 changes: 21 additions & 3 deletions src/main/kotlin/id/walt/nftkit/services/AlgorandNftService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import kotlinx.coroutines.runBlocking
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.encodeToJsonElement
import kotlinx.serialization.json.*
import java.io.BufferedReader
import java.io.DataOutputStream
import java.io.InputStreamReader
Expand Down Expand Up @@ -392,5 +390,25 @@ object AlgorandNftService {
return@runBlocking response
}
}


fun verifyOwnerShipWithTraits(address: String, assetId:String, chain: AlgorandChain , traitType : String , traitValue : String):Boolean {
return runBlocking {
print(traitType)
print(traitValue)
val response = getNftMetadata(assetId, chain)
if (response.properties != null) {
for (trait in response.properties!!) {

if (trait.key.filterIndexed { index, c -> index < traitType.length } ==traitType && trait.value.jsonPrimitive.content.equals(traitValue) ) {
return@runBlocking true
}


}
}
return@runBlocking false
}
}
}

1 change: 1 addition & 0 deletions src/main/kotlin/id/walt/nftkit/services/NftService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum class Chain {
GHOSTNET,
MAINNET,
TESTNET,
BETANET,
ASTAR,
MOONBEAM,
UNIQUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ object VerificationService {
val result = AlgorandNftService.verifyOwnership(account, assetId,chain )
return if (result.assetHolding?.assetId.toString().equals(assetId)) true else false
}

fun NFTAlgorandOwnershipVerificationWithTraits(chain: AlgorandChain, account: String, assetId: String , traitType: String, traitValue: String):Boolean{
val result = AlgorandNftService.verifyOwnerShipWithTraits(account, assetId, chain,traitType, traitValue)
return result
}

private fun NFTsNearOwnershipVerification(chain:NearChain, contractAddress : String, account : String, tokenId : String) : Boolean{

Expand Down

0 comments on commit 7deb019

Please sign in to comment.