diff --git a/src/main/kotlin/id/walt/nftkit/rest/NftController.kt b/src/main/kotlin/id/walt/nftkit/rest/NftController.kt index 6302a8d5..d66548c6 100644 --- a/src/main/kotlin/id/walt/nftkit/rest/NftController.kt +++ b/src/main/kotlin/id/walt/nftkit/rest/NftController.kt @@ -94,8 +94,9 @@ object NftController { val contractAddress = ctx.pathParam("contractAddress") val mintingParameter = MintingParameter(mintReq.metadataUri, mintReq.recipientAddress, mintReq.metadata) val mintingOptions = MintingOptions(mintReq.metadataStorageType) + val isSoulbound = ctx.queryParam("isSoulbound")?.toBoolean() ?: false val result = - NftService.mintToken(Common.getEVMChain(chain.uppercase()), contractAddress, mintingParameter, mintingOptions) + NftService.mintToken(Common.getEVMChain(chain.uppercase()), contractAddress, mintingParameter, mintingOptions , isSoulbound ) ctx.json( result ) @@ -107,7 +108,12 @@ object NftController { }.pathParam("chain") { it.schema { } }.pathParam("contractAddress") { - }.body { + } + .queryParam("isSoulbound") { + it.required(false) + + } + .body { it.description("") }.json("200") { it.description("Transaction ID and token ID") } diff --git a/src/main/kotlin/id/walt/nftkit/services/NftService.kt b/src/main/kotlin/id/walt/nftkit/services/NftService.kt index 9b8eac4b..09bf251a 100644 --- a/src/main/kotlin/id/walt/nftkit/services/NftService.kt +++ b/src/main/kotlin/id/walt/nftkit/services/NftService.kt @@ -21,9 +21,7 @@ import io.ktor.client.request.* import io.ktor.http.* import io.ktor.serialization.kotlinx.json.* import kotlinx.coroutines.runBlocking -import kotlinx.serialization.Contextual import kotlinx.serialization.Serializable -import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.* import org.web3j.abi.EventEncoder import org.web3j.abi.EventValues @@ -305,7 +303,8 @@ object NftService { chain: EVMChain, contractAddress: String, parameter: MintingParameter, - options: MintingOptions + options: MintingOptions, + isSoulBound: Boolean ): MintingResponse { var tokenUri: String? if (parameter.metadataUri != null && parameter.metadataUri != "") { @@ -316,7 +315,7 @@ object NftService { tokenUri = metadataUri.getTokenUri(nftMetadataWrapper) } - return mintNewToken(parameter.recipientAddress, tokenUri, chain, contractAddress) + return mintNewToken(parameter.recipientAddress, tokenUri, chain, contractAddress , isSoulBound ) } @@ -595,10 +594,11 @@ object NftService { recipientAddress: String, metadataUri: String, chain: EVMChain, - contractAddress: String + contractAddress: String, + isSoulBound : Boolean ): MintingResponse { - if (isErc721Standard(chain, contractAddress) && !isSoulBoundStandard(chain , contractAddress)) { - //val erc721TokenStandard = Erc721TokenStandard() + if (!isSoulBound) { + val recipient = Address(recipientAddress) val tokenUri = Utf8String(metadataUri) val transactionReceipt: TransactionReceipt? = @@ -611,11 +611,9 @@ object NftService { TransactionResponse(transactionReceipt!!.transactionHash, "$url/tx/${transactionReceipt.transactionHash}") val mr = MintingResponse(ts, eventValues?.indexedValues?.get(2)?.value as BigInteger) return mr - } else if (isSoulBoundStandard(chain , contractAddress) && isErc721Standard(chain, contractAddress)){ - val recipient = recipientAddress - val tokenUri = metadataUri + } else if (isSoulBound){ val transactionReceipt: TransactionReceipt? = - SoulBoundTokenStandard.safeMint(chain, contractAddress, recipient, tokenUri) + SoulBoundTokenStandard.safeMint(chain, contractAddress, recipientAddress, metadataUri) val eventValues: EventValues? = staticExtractEventParameters(Erc721OnchainCredentialWrapper.TRANSFER_EVENT, transactionReceipt?.logs?.get(0)) @@ -638,10 +636,10 @@ object NftService { } - private fun isErc721Standard(chain: EVMChain, contractAddress: String): Boolean { + fun isErc721Standard(chain: EVMChain, contractAddress: String): Boolean { return Erc721TokenStandard.supportsInterface(chain, contractAddress) } - private fun isSoulBoundStandard(chain: EVMChain, contractAddress: String): Boolean { + fun isSoulBoundStandard(chain: EVMChain, contractAddress: String): Boolean { return SoulBoundTokenStandard.supportsInterface(chain, contractAddress) } diff --git a/src/test/kotlin/id/walt/nftkit/blockchainTransactionsCalls/evm/Erc721Standard.kt b/src/test/kotlin/id/walt/nftkit/blockchainTransactionsCalls/evm/Erc721Standard.kt index 50439d22..c1701243 100644 --- a/src/test/kotlin/id/walt/nftkit/blockchainTransactionsCalls/evm/Erc721Standard.kt +++ b/src/test/kotlin/id/walt/nftkit/blockchainTransactionsCalls/evm/Erc721Standard.kt @@ -33,7 +33,7 @@ class Erc721Standard : StringSpec({ val nftMetaData = NftMetadata("Ticket 2 description", "Ticket 2", "string", "string","string") val mintingParametre = MintingParameter(metadataUri = "", recipientAddress="0xaf87c5ce7a1fb6bd5aadb6dd9c0b8ef51ef1bc31", metadata = nftMetaData ) val mintingOption = MintingOptions(MetadataStorageType.ON_CHAIN) - val result = NftService.mintToken(EVMChain.MUMBAI, contractAddress = "0xf277BE034881eE38A9b270E5b6C5c6f333Af2517",mintingParametre, mintingOption) + val result = NftService.mintToken(EVMChain.MUMBAI, contractAddress = "0xf277BE034881eE38A9b270E5b6C5c6f333Af2517",mintingParametre, mintingOption , false) val newNFT = NftService.getNftMetadata(EVMChain.MUMBAI, "0xf277BE034881eE38A9b270E5b6C5c6f333Af2517", result.tokenId!!) result.tokenId shouldNotBe null newNFT shouldBe nftMetaData diff --git a/src/test/kotlin/id/walt/nftkit/blockchainTransactionsCalls/evm/EvmBasedSCExtensions.kt b/src/test/kotlin/id/walt/nftkit/blockchainTransactionsCalls/evm/EvmBasedSCExtensions.kt index 00d720ee..25edf3f8 100644 --- a/src/test/kotlin/id/walt/nftkit/blockchainTransactionsCalls/evm/EvmBasedSCExtensions.kt +++ b/src/test/kotlin/id/walt/nftkit/blockchainTransactionsCalls/evm/EvmBasedSCExtensions.kt @@ -66,7 +66,7 @@ class EvmBasedSCExtensions : StringSpec({ val nftMetaData = NftMetadata("To burn", "To burn", "string", "string","string") val mintingParametre = MintingParameter(metadataUri = "", recipientAddress="0xaf87c5ce7a1fb6bd5aadb6dd9c0b8ef51ef1bc31", metadata = nftMetaData ) val mintingOption = MintingOptions(MetadataStorageType.ON_CHAIN) - val newNftId = NftService.mintToken(EVMChain.MUMBAI, contractAddress = "0xf277BE034881eE38A9b270E5b6C5c6f333Af2517",mintingParametre, mintingOption).tokenId + val newNftId = NftService.mintToken(EVMChain.MUMBAI, contractAddress = "0xf277BE034881eE38A9b270E5b6C5c6f333Af2517",mintingParametre, mintingOption ,false).tokenId if (!(ExtensionsService.getBurnable(EVMChain.MUMBAI, "0xf277BE034881eE38A9b270E5b6C5c6f333Af2517"))) {ExtensionsService.setBurnable(EVMChain.MUMBAI, "0xf277BE034881eE38A9b270E5b6C5c6f333Af2517", true) } val result = newNftId?.let {