Skip to content

Commit

Permalink
Merge pull request #137 from walt-id/feat/Algorand-verification
Browse files Browse the repository at this point in the history
Feat/algorand verification
  • Loading branch information
SuperBatata authored Aug 12, 2023
2 parents 9486984 + 299ebe4 commit 6e10f72
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
23 changes: 23 additions & 0 deletions src/main/kotlin/id/walt/nftkit/rest/AlgorandNftController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,28 @@ object AlgorandNftController{
it.description("Algorand NFT Metadata")
}

///////////////////////////////////////////////////////////////////////////

fun verifyNftOwnerShipBasedOnCreator(ctx: Context){
val chain =ctx.pathParam("chain")
val address = ctx.pathParam("address")
val creatorAddress = ctx.pathParam("creatorAddress")
val result = AlgorandNftService.verifyOwnerShipBasedOnCreator(address, Common.getAlgorandChain(chain.uppercase()) , creatorAddress)
ctx.result(Json.encodeToString(result))

}

fun verifyNftOwnerShipBasedOnCreatorDocs()= document().operation {
it.summary("Verifying NFT ownership based on creator ")
.operationId("verifyNftOwnerShipBasedOnCreator")
.addTagsItem("NFT verification")}
.pathParam<String>("chain") {
it.schema<AlgorandChain>{}}
.pathParam<String>("address"){}
.pathParam<String>("creatorAddress"){}
.json<String>(200.toString()) {
it.description("Algorand NFT Metadata")
}

}

6 changes: 6 additions & 0 deletions src/main/kotlin/id/walt/nftkit/rest/NftKitApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ object NftKitApi {
documented(AlgorandNftController.fetchAccountAssetsDocs(), AlgorandNftController::fetchAccountAssets)
)



}
}
path("nft/verifier") {
Expand All @@ -317,6 +319,10 @@ object NftKitApi {
"chain/{chain}/verifyNftOwnershipWithTraits",
documented(VerificationController.verifyAlgorandNftOwnershipWithTraitsDocs(), VerificationController::verifyAlgorandNftOwnershipWithTraits)
)
get(
"chain/{chain}/{address}/verifyNftOwnershipBasedOnCreator/{creatorAddress}",
documented(AlgorandNftController.verifyNftOwnerShipBasedOnCreatorDocs(), AlgorandNftController::verifyNftOwnerShipBasedOnCreator)
)
get(
"chain/{chain}/contract/{contractAddress}/verifyNftOwnership",
documented(VerificationController.verifyNftOwnershipDocs(), VerificationController::verifyNftOwnership)
Expand Down
45 changes: 29 additions & 16 deletions src/main/kotlin/id/walt/nftkit/services/AlgorandNftService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -352,27 +352,27 @@ object AlgorandNftService {
}

fun getAccountAssets(address: String, chain: AlgorandChain): List<AlgorandToken> {
val API_ADDR = when (chain) {
AlgorandChain.MAINNET -> "https://mainnet-idx.algonode.cloud"
AlgorandChain.TESTNET -> "https://testnet-idx.algonode.cloud"
AlgorandChain.BETANET -> "https://betanet-idx.algonode.cloud"
}

return runBlocking {
var API_ADDR = when (chain) {
AlgorandChain.MAINNET -> "https://mainnet-idx.algonode.cloud"
AlgorandChain.TESTNET -> "https://testnet-idx.algonode.cloud"
AlgorandChain.BETANET -> "https://betanet-idx.algonode.cloud"
}
val resp = client.get(API_ADDR + "/v2/accounts/" + address + "/assets") {
val resp = client.get("$API_ADDR/v2/accounts/$address/assets") {
contentType(ContentType.Application.Json)
}.body<AssetHoldingsResponse>()

val result = mutableListOf<AlgorandToken>()
if (resp.assets.isNotEmpty()){
for (a in resp.assets){
if (a.amount == 1) {
var token = getToken(a.assetId.toString(), chain)
if (token.TokenParams?.params?.total == 1L )
result.add(token)
resp.assets
.filter { it.amount?.toLong() == 1L }
.mapNotNull { asset ->
val token = getToken(asset.assetId.toString(), chain)
if (token.TokenParams?.params?.total == 1L) {
token
} else {
null
}
}
}
}
return@runBlocking result;
}
}

Expand Down Expand Up @@ -410,5 +410,18 @@ object AlgorandNftService {
return@runBlocking false
}
}

fun verifyOwnerShipBasedOnCreator(address: String, chain: AlgorandChain , creatorAddress : String):Boolean {
return runBlocking {

val response = getAccountAssets(address, chain)
for (asset in response) {
if (asset.TokenParams?.params?.creator.equals(creatorAddress)) {
return@runBlocking true
}
}
return@runBlocking false
}
}
}

0 comments on commit 6e10f72

Please sign in to comment.