diff --git a/src/main/kotlin/id/walt/nftkit/rest/NftController.kt b/src/main/kotlin/id/walt/nftkit/rest/NftController.kt index 53dc5cdd..8e71ec1e 100644 --- a/src/main/kotlin/id/walt/nftkit/rest/NftController.kt +++ b/src/main/kotlin/id/walt/nftkit/rest/NftController.kt @@ -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 @@ -87,7 +89,7 @@ object NftController { fun mint(ctx: Context) { - val mintReq = ctx.bodyAsClass(MintRequest::class.java) + val mintReq = Json.decodeFromString(ctx.body()) val chain = ctx.pathParam("chain") val contractAddress = ctx.pathParam("contractAddress") val mintingParameter = MintingParameter(mintReq.metadataUri, mintReq.recipientAddress, mintReq.metadata) diff --git a/src/main/kotlin/id/walt/nftkit/services/VerificationService.kt b/src/main/kotlin/id/walt/nftkit/services/VerificationService.kt index 7b4c8647..a4433582 100644 --- a/src/main/kotlin/id/walt/nftkit/services/VerificationService.kt +++ b/src/main/kotlin/id/walt/nftkit/services/VerificationService.kt @@ -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 @@ -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 { diff --git a/src/main/kotlin/id/walt/nftkit/utilis/Common.kt b/src/main/kotlin/id/walt/nftkit/utilis/Common.kt index 0ff70f71..6a849871 100644 --- a/src/main/kotlin/id/walt/nftkit/utilis/Common.kt +++ b/src/main/kotlin/id/walt/nftkit/utilis/Common.kt @@ -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")} } } @@ -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) }