Skip to content

Commit

Permalink
Merge pull request #153 from walt-id/feat/soulbound
Browse files Browse the repository at this point in the history
Feat/soulbound
  • Loading branch information
SuperBatata authored Sep 26, 2023
2 parents a4a869f + bd36ba1 commit ceb7327
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
10 changes: 8 additions & 2 deletions src/main/kotlin/id/walt/nftkit/rest/NftController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -107,7 +108,12 @@ object NftController {
}.pathParam<String>("chain") {
it.schema<EVMChain> { }
}.pathParam<String>("contractAddress") {
}.body<MintRequest> {
}
.queryParam<Boolean>("isSoulbound") {
it.required(false)

}
.body<MintRequest> {
it.description("")
}.json<MintingResponse>("200") { it.description("Transaction ID and token ID") }

Expand Down
24 changes: 11 additions & 13 deletions src/main/kotlin/id/walt/nftkit/services/NftService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 != "") {
Expand All @@ -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 )
}


Expand Down Expand Up @@ -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? =
Expand All @@ -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))

Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ceb7327

Please sign in to comment.