Skip to content

Commit

Permalink
Merge pull request #146 from walt-id/fix-mint-request
Browse files Browse the repository at this point in the history
fix-mint-request
  • Loading branch information
waltkb authored Sep 6, 2023
2 parents efc2e54 + c015d04 commit e0ab63d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 45 deletions.
4 changes: 3 additions & 1 deletion src/main/kotlin/id/walt/nftkit/rest/NftController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import io.javalin.http.BadRequestResponse
import io.javalin.http.Context
import io.javalin.plugin.openapi.dsl.document
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import java.math.BigInteger


Expand Down Expand Up @@ -87,7 +89,7 @@ object NftController {


fun mint(ctx: Context) {
val mintReq = ctx.bodyAsClass(MintRequest::class.java)
val mintReq = Json.decodeFromString<MintRequest>(ctx.body())
val chain = ctx.pathParam("chain")
val contractAddress = ctx.pathParam("contractAddress")
val mintingParameter = MintingParameter(mintReq.metadataUri, mintReq.recipientAddress, mintReq.metadata)
Expand Down
28 changes: 7 additions & 21 deletions src/main/kotlin/id/walt/nftkit/services/VerificationService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import id.walt.nftkit.utilis.Common
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.util.*
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonPrimitive
import org.web3j.tx.exceptions.ContractCallException
import java.math.BigInteger

Expand Down Expand Up @@ -43,28 +41,16 @@ object VerificationService {
// Verify if NFT is part of a collection (contract address)
fun verifyNftOwnership(chain: Chain, contractAddress: String,account: String, tokenId: String): Boolean{
return when{
Common.isEVMChain(chain) -> {
return NFTsEvmOwnershipVerification(EVMChain.valueOf(chain.toString()), contractAddress, account, BigInteger(tokenId))
}
Common.isTezosChain(chain) -> {
return NFTsTezosOwnershipVerification(chain, contractAddress, account, tokenId)
}
Common.isEVMChain(chain) -> NFTsEvmOwnershipVerification(EVMChain.valueOf(chain.toString()), contractAddress, account, BigInteger(tokenId))
Common.isTezosChain(chain) -> NFTsTezosOwnershipVerification(chain, contractAddress, account, tokenId)

Common.isNearChain(chain) -> {
return NFTsNearOwnershipVerification(NearChain.valueOf(chain.toString()), contractAddress, account, tokenId)
}
Common.isNearChain(chain) -> NFTsNearOwnershipVerification(NearChain.valueOf(chain.toString()), contractAddress, account, tokenId)

Common.isPolkadotParachain(chain) -> {
return NFTsPolkadotOwnershipVerification(PolkadotParachain.valueOf(chain.toString()), contractAddress, account, tokenId)
}
Common.isUniqueParachain(chain) -> {
return NFTsUniqueOwnershipVerification(UniqueNetwork.valueOf(chain.toString()), contractAddress, account, tokenId)
}
Common.isAlgorand(chain) -> {
return NFTsAlgorandOwnershipVerification(AlgorandChain.valueOf(chain.toString()), account, tokenId )
}
Common.isPolkadotParachain(chain) -> NFTsPolkadotOwnershipVerification(PolkadotParachain.valueOf(chain.toString()), contractAddress, account, tokenId)
Common.isUniqueParachain(chain) -> NFTsUniqueOwnershipVerification(UniqueNetwork.valueOf(chain.toString()), contractAddress, account, tokenId)
Common.isAlgorand(chain) -> NFTsAlgorandOwnershipVerification(AlgorandChain.valueOf(chain.toString()), account, tokenId )

else -> {throw Exception("Chain is not supported")}
else -> throw Exception("Chain is not supported")
}
}
fun verifyNftOwnershipOnFlow( chain: Chain, contractAddress: String, account: String, tokenId: String, collectionPath: String): Boolean {
Expand Down
34 changes: 11 additions & 23 deletions src/main/kotlin/id/walt/nftkit/utilis/Common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ object Common {
EVMChain.SEPOLIA -> Values.ETHEREUM_TESTNET_SEPOLIA_SCAN_API_URL
EVMChain.POLYGON -> Values.POLYGON_MAINNET_SCAN_API_URL
EVMChain.MUMBAI -> Values.POLYGON_TESTNET_MUMBAI_SCAN_API_URL
else -> {throw Exception("${chain.toString()} is not supported")}
else -> {throw Exception("$chain is not supported")}
}
}

Expand All @@ -108,43 +108,31 @@ object Common {
EVMChain.SEPOLIA -> WaltIdServices.loadApiKeys().apiKeys.ethereumBlockExplorer
EVMChain.POLYGON -> WaltIdServices.loadApiKeys().apiKeys.polygonBlockExplorer
EVMChain.MUMBAI -> WaltIdServices.loadApiKeys().apiKeys.polygonBlockExplorer
else -> {throw Exception("${chain.toString()} is not supported")}
else -> {throw Exception("$chain is not supported")}
}
}

fun isEVMChain(chain: Chain): Boolean{
val EVMChains= listOf(Chain.ETHEREUM, Chain.POLYGON, Chain.GOERLI, Chain.SEPOLIA, Chain.MUMBAI)
if(chain in EVMChains) return true
return false
return chain in EVMChains
}

fun isTezosChain(chain: Chain): Boolean{
val TezosChains= listOf(Chain.TEZOS, Chain.GHOSTNET)
if(chain in TezosChains) return true
return false
return chain in TezosChains
}

fun isNearChain(chain: Chain): Boolean{
val NearChains= listOf(Chain.MAINNET, Chain.TESTNET)
if(chain in NearChains) return true
return false
return chain in NearChains
}

fun isPolkadotParachain(chain: Chain): Boolean{
val polkadotParachain= listOf(Chain.ASTAR, Chain.MOONBEAM)
if(chain in polkadotParachain) return true
return false
}
fun isPolkadotParachain(chain: Chain): Boolean =
chain in listOf(Chain.ASTAR, Chain.MOONBEAM)

fun isUniqueParachain(chain: Chain): Boolean{
val uniqueParachain= listOf(Chain.UNIQUE, Chain.OPAL)
if(chain in uniqueParachain) return true
return false
}
fun isAlgorand(chain: Chain): Boolean{
val algorandChain= listOf(Chain.ALGORAND_MAINNET, Chain.ALGORAND_TESTNET, Chain.ALGORAND_BETANET)
if(chain in algorandChain) return true
return false
}
fun isUniqueParachain(chain: Chain): Boolean =
chain in listOf(Chain.UNIQUE, Chain.OPAL)
fun isAlgorand(chain: Chain): Boolean =
chain in listOf(Chain.ALGORAND_MAINNET, Chain.ALGORAND_TESTNET, Chain.ALGORAND_BETANET)
}

0 comments on commit e0ab63d

Please sign in to comment.