feat: add support for cropped asset data when deploying community NFTs
Needs: https://github.com/status-im/status-go/pull/3705 Closes: #10317
This commit is contained in:
parent
b748402825
commit
c10809863a
|
@ -70,8 +70,8 @@ proc init*(self: Controller) =
|
||||||
let args = AirdropArgs(e)
|
let args = AirdropArgs(e)
|
||||||
self.communityTokensModule.onAirdropStateChanged(args.communityToken.communityId, args.communityToken.name, args.communityToken.chainId, args.transactionHash, args.status)
|
self.communityTokensModule.onAirdropStateChanged(args.communityToken.communityId, args.communityToken.name, args.communityToken.chainId, args.transactionHash, args.status)
|
||||||
|
|
||||||
proc deployContract*(self: Controller, communityId: string, addressFrom: string, password: string, deploymentParams: DeploymentParameters, tokenMetadata: CommunityTokensMetadataDto, chainId: int) =
|
proc deployContract*(self: Controller, communityId: string, addressFrom: string, password: string, deploymentParams: DeploymentParameters, tokenMetadata: CommunityTokensMetadataDto, tokenImageCropInfoJson: string, chainId: int) =
|
||||||
self.communityTokensService.deployContract(communityId, addressFrom, password, deploymentParams, tokenMetadata, chainId)
|
self.communityTokensService.deployContract(communityId, addressFrom, password, deploymentParams, tokenMetadata, tokenImageCropInfoJson, chainId)
|
||||||
|
|
||||||
proc airdropCollectibles*(self: Controller, communityId: string, password: string, collectiblesAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string]) =
|
proc airdropCollectibles*(self: Controller, communityId: string, password: string, collectiblesAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string]) =
|
||||||
self.communityTokensService.airdropCollectibles(communityId, password, collectiblesAndAmounts, walletAddresses)
|
self.communityTokensService.airdropCollectibles(communityId, password, collectiblesAndAmounts, walletAddresses)
|
||||||
|
|
|
@ -24,11 +24,11 @@ method burnCollectibles*(self: AccessInterface, communityId: string, contractUni
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method deployCollectibles*(self: AccessInterface, communityId: string, address: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, transferable: bool,
|
method deployCollectibles*(self: AccessInterface, communityId: string, address: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, transferable: bool,
|
||||||
selfDestruct: bool, chainId: int, image: string) {.base.} =
|
selfDestruct: bool, chainId: int, imageCropInfoJson: string) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method deployAssets*(self: AccessInterface, communityId: string, address: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, decimals: int,
|
method deployAssets*(self: AccessInterface, communityId: string, address: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, decimals: int,
|
||||||
chainId: int, image: string) {.base.} =
|
chainId: int, imageCropInfoJson: string) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method onUserAuthenticated*(self: AccessInterface, password: string) {.base.} =
|
method onUserAuthenticated*(self: AccessInterface, password: string) {.base.} =
|
||||||
|
|
|
@ -35,6 +35,7 @@ type
|
||||||
tempContractAddress: string
|
tempContractAddress: string
|
||||||
tempDeploymentParams: DeploymentParameters
|
tempDeploymentParams: DeploymentParameters
|
||||||
tempTokenMetadata: CommunityTokensMetadataDto
|
tempTokenMetadata: CommunityTokensMetadataDto
|
||||||
|
tempTokenImageCropInfoJson: string
|
||||||
tempWalletAddresses: seq[string]
|
tempWalletAddresses: seq[string]
|
||||||
tempContractAction: ContractAction
|
tempContractAction: ContractAction
|
||||||
tempContractUniqueKey: string
|
tempContractUniqueKey: string
|
||||||
|
@ -62,6 +63,7 @@ method resetTempValues(self:Module) =
|
||||||
self.tempCommunityId = ""
|
self.tempCommunityId = ""
|
||||||
self.tempDeploymentParams = DeploymentParameters()
|
self.tempDeploymentParams = DeploymentParameters()
|
||||||
self.tempTokenMetadata = CommunityTokensMetadataDto()
|
self.tempTokenMetadata = CommunityTokensMetadataDto()
|
||||||
|
self.tempTokenImageCropInfoJson = ""
|
||||||
self.tempChainId = 0
|
self.tempChainId = 0
|
||||||
self.tempContractAddress = ""
|
self.tempContractAddress = ""
|
||||||
self.tempWalletAddresses = @[]
|
self.tempWalletAddresses = @[]
|
||||||
|
@ -131,7 +133,7 @@ method burnCollectibles*(self: Module, communityId: string, contractUniqueKey: s
|
||||||
self.authenticate()
|
self.authenticate()
|
||||||
|
|
||||||
method deployCollectibles*(self: Module, communityId: string, fromAddress: string, name: string, symbol: string, description: string,
|
method deployCollectibles*(self: Module, communityId: string, fromAddress: string, name: string, symbol: string, description: string,
|
||||||
supply: int, infiniteSupply: bool, transferable: bool, selfDestruct: bool, chainId: int, image: string) =
|
supply: int, infiniteSupply: bool, transferable: bool, selfDestruct: bool, chainId: int, imageCropInfoJson: string) =
|
||||||
self.tempAddressFrom = fromAddress
|
self.tempAddressFrom = fromAddress
|
||||||
self.tempCommunityId = communityId
|
self.tempCommunityId = communityId
|
||||||
self.tempChainId = chainId
|
self.tempChainId = chainId
|
||||||
|
@ -143,13 +145,13 @@ method deployCollectibles*(self: Module, communityId: string, fromAddress: strin
|
||||||
self.tempDeploymentParams.remoteSelfDestruct = selfDestruct
|
self.tempDeploymentParams.remoteSelfDestruct = selfDestruct
|
||||||
self.tempDeploymentParams.tokenUri = utl.changeCommunityKeyCompression(communityId) & "/"
|
self.tempDeploymentParams.tokenUri = utl.changeCommunityKeyCompression(communityId) & "/"
|
||||||
self.tempTokenMetadata.tokenType = TokenType.ERC721
|
self.tempTokenMetadata.tokenType = TokenType.ERC721
|
||||||
self.tempTokenMetadata.image = singletonInstance.utils.formatImagePath(image)
|
|
||||||
self.tempTokenMetadata.description = description
|
self.tempTokenMetadata.description = description
|
||||||
|
self.tempTokenImageCropInfoJson = imageCropInfoJson
|
||||||
self.tempContractAction = ContractAction.Deploy
|
self.tempContractAction = ContractAction.Deploy
|
||||||
self.authenticate()
|
self.authenticate()
|
||||||
|
|
||||||
method deployAssets*(self: Module, communityId: string, fromAddress: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, decimals: int,
|
method deployAssets*(self: Module, communityId: string, fromAddress: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, decimals: int,
|
||||||
chainId: int, image: string) =
|
chainId: int, imageCropInfoJson: string) =
|
||||||
self.tempAddressFrom = fromAddress
|
self.tempAddressFrom = fromAddress
|
||||||
self.tempCommunityId = communityId
|
self.tempCommunityId = communityId
|
||||||
self.tempChainId = chainId
|
self.tempChainId = chainId
|
||||||
|
@ -160,8 +162,8 @@ method deployAssets*(self: Module, communityId: string, fromAddress: string, nam
|
||||||
self.tempDeploymentParams.decimals = decimals
|
self.tempDeploymentParams.decimals = decimals
|
||||||
self.tempDeploymentParams.tokenUri = utl.changeCommunityKeyCompression(communityId) & "/"
|
self.tempDeploymentParams.tokenUri = utl.changeCommunityKeyCompression(communityId) & "/"
|
||||||
self.tempTokenMetadata.tokenType = TokenType.ERC20
|
self.tempTokenMetadata.tokenType = TokenType.ERC20
|
||||||
self.tempTokenMetadata.image = singletonInstance.utils.formatImagePath(image)
|
|
||||||
self.tempTokenMetadata.description = description
|
self.tempTokenMetadata.description = description
|
||||||
|
self.tempTokenImageCropInfoJson = imageCropInfoJson
|
||||||
self.tempContractAction = ContractAction.Deploy
|
self.tempContractAction = ContractAction.Deploy
|
||||||
self.authenticate()
|
self.authenticate()
|
||||||
|
|
||||||
|
@ -172,7 +174,7 @@ method onUserAuthenticated*(self: Module, password: string) =
|
||||||
#TODO signalize somehow
|
#TODO signalize somehow
|
||||||
else:
|
else:
|
||||||
if self.tempContractAction == ContractAction.Deploy:
|
if self.tempContractAction == ContractAction.Deploy:
|
||||||
self.controller.deployContract(self.tempCommunityId, self.tempAddressFrom, password, self.tempDeploymentParams, self.tempTokenMetadata, self.tempChainId)
|
self.controller.deployContract(self.tempCommunityId, self.tempAddressFrom, password, self.tempDeploymentParams, self.tempTokenMetadata, self.tempTokenImageCropInfoJson, self.tempChainId)
|
||||||
elif self.tempContractAction == ContractAction.Airdrop:
|
elif self.tempContractAction == ContractAction.Airdrop:
|
||||||
self.controller.airdropCollectibles(self.tempCommunityId, password, self.tempTokenAndAmountList, self.tempWalletAddresses)
|
self.controller.airdropCollectibles(self.tempCommunityId, password, self.tempTokenAndAmountList, self.tempWalletAddresses)
|
||||||
elif self.tempContractAction == ContractAction.SelfDestruct:
|
elif self.tempContractAction == ContractAction.SelfDestruct:
|
||||||
|
|
|
@ -21,11 +21,11 @@ QtObject:
|
||||||
result.QObject.setup
|
result.QObject.setup
|
||||||
result.communityTokensModule = communityTokensModule
|
result.communityTokensModule = communityTokensModule
|
||||||
|
|
||||||
proc deployCollectible*(self: View, communityId: string, fromAddress: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, transferable: bool, selfDestruct: bool, chainId: int, image: string) {.slot.} =
|
proc deployCollectible*(self: View, communityId: string, fromAddress: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, transferable: bool, selfDestruct: bool, chainId: int, imageCropInfoJson: string) {.slot.} =
|
||||||
self.communityTokensModule.deployCollectibles(communityId, fromAddress, name, symbol, description, supply, infiniteSupply, transferable, selfDestruct, chainId, image)
|
self.communityTokensModule.deployCollectibles(communityId, fromAddress, name, symbol, description, supply, infiniteSupply, transferable, selfDestruct, chainId, imageCropInfoJson)
|
||||||
|
|
||||||
proc deployAssets*(self: View, communityId: string, fromAddress: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, decimals: int, chainId: int, image: string) {.slot.} =
|
proc deployAssets*(self: View, communityId: string, fromAddress: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, decimals: int, chainId: int, imageCropInfoJson: string) {.slot.} =
|
||||||
self.communityTokensModule.deployAssets(communityId, fromAddress, name, symbol, description, supply, infiniteSupply, decimals, chainId, image)
|
self.communityTokensModule.deployAssets(communityId, fromAddress, name, symbol, description, supply, infiniteSupply, decimals, chainId, imageCropInfoJson)
|
||||||
|
|
||||||
proc airdropCollectibles*(self: View, communityId: string, collectiblesJsonString: string, walletsJsonString: string) {.slot.} =
|
proc airdropCollectibles*(self: View, communityId: string, collectiblesJsonString: string, walletsJsonString: string) {.slot.} =
|
||||||
self.communityTokensModule.airdropCollectibles(communityId, collectiblesJsonString, walletsJsonString)
|
self.communityTokensModule.airdropCollectibles(communityId, collectiblesJsonString, walletsJsonString)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import NimQml, Tables, chronicles, json, stint, strutils, sugar, sequtils
|
import NimQml, Tables, chronicles, json, stint, strutils, sugar, sequtils
|
||||||
|
import ../../../app/global/global_singleton
|
||||||
import ../../../app/core/eventemitter
|
import ../../../app/core/eventemitter
|
||||||
import ../../../app/core/tasks/[qt, threadpool]
|
import ../../../app/core/tasks/[qt, threadpool]
|
||||||
import ../../../app/modules/shared_models/currency_amount
|
import ../../../app/modules/shared_models/currency_amount
|
||||||
|
@ -288,7 +289,7 @@ QtObject:
|
||||||
if suggestedFees.eip1559Enabled: $suggestedFees.maxPriorityFeePerGas else: "",
|
if suggestedFees.eip1559Enabled: $suggestedFees.maxPriorityFeePerGas else: "",
|
||||||
if suggestedFees.eip1559Enabled: $suggestedFees.maxFeePerGasM else: "")
|
if suggestedFees.eip1559Enabled: $suggestedFees.maxFeePerGasM else: "")
|
||||||
|
|
||||||
proc deployContract*(self: Service, communityId: string, addressFrom: string, password: string, deploymentParams: DeploymentParameters, tokenMetadata: CommunityTokensMetadataDto, chainId: int) =
|
proc deployContract*(self: Service, communityId: string, addressFrom: string, password: string, deploymentParams: DeploymentParameters, tokenMetadata: CommunityTokensMetadataDto, croppedImageJson: string, chainId: int) =
|
||||||
try:
|
try:
|
||||||
let txData = self.buildTransactionDataDto(addressFrom, chainId, "")
|
let txData = self.buildTransactionDataDto(addressFrom, chainId, "")
|
||||||
if txData.source == parseAddress(ZERO_ADDRESS):
|
if txData.source == parseAddress(ZERO_ADDRESS):
|
||||||
|
@ -323,11 +324,13 @@ QtObject:
|
||||||
communityToken.tokenUri = deploymentParams.tokenUri
|
communityToken.tokenUri = deploymentParams.tokenUri
|
||||||
communityToken.chainId = chainId
|
communityToken.chainId = chainId
|
||||||
communityToken.deployState = DeployState.InProgress
|
communityToken.deployState = DeployState.InProgress
|
||||||
communityToken.image = tokenMetadata.image
|
|
||||||
communityToken.decimals = deploymentParams.decimals
|
communityToken.decimals = deploymentParams.decimals
|
||||||
|
|
||||||
|
var croppedImage = croppedImageJson.parseJson
|
||||||
|
croppedImage{"imagePath"} = newJString(singletonInstance.utils.formatImagePath(croppedImage["imagePath"].getStr))
|
||||||
|
|
||||||
# save token to db
|
# save token to db
|
||||||
let communityTokenJson = tokens_backend.addCommunityToken(communityToken)
|
let communityTokenJson = tokens_backend.addCommunityToken(communityToken, $croppedImage)
|
||||||
communityToken = communityTokenJson.result.toCommunityTokenDto()
|
communityToken = communityTokenJson.result.toCommunityTokenDto()
|
||||||
let data = CommunityTokenDeployedArgs(communityToken: communityToken, transactionHash: transactionHash)
|
let data = CommunityTokenDeployedArgs(communityToken: communityToken, transactionHash: transactionHash)
|
||||||
self.events.emit(SIGNAL_COMMUNITY_TOKEN_DEPLOYED, data)
|
self.events.emit(SIGNAL_COMMUNITY_TOKEN_DEPLOYED, data)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import ./eth
|
||||||
import ../app_service/common/utils
|
import ../app_service/common/utils
|
||||||
import ./core, ./response_type
|
import ./core, ./response_type
|
||||||
import ../app_service/service/community_tokens/dto/community_token
|
import ../app_service/service/community_tokens/dto/community_token
|
||||||
|
import interpret/cropped_image
|
||||||
|
|
||||||
proc deployCollectibles*(chainId: int, deploymentParams: JsonNode, txData: JsonNode, password: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
proc deployCollectibles*(chainId: int, deploymentParams: JsonNode, txData: JsonNode, password: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
let payload = %* [chainId, deploymentParams, txData, utils.hashPassword(password)]
|
let payload = %* [chainId, deploymentParams, txData, utils.hashPassword(password)]
|
||||||
|
@ -22,8 +23,9 @@ proc getAllCommunityTokens*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
let payload = %* []
|
let payload = %* []
|
||||||
return core.callPrivateRPC("wakuext_getAllCommunityTokens", payload)
|
return core.callPrivateRPC("wakuext_getAllCommunityTokens", payload)
|
||||||
|
|
||||||
proc addCommunityToken*(token: CommunityTokenDto): RpcResponse[JsonNode] {.raises: [Exception].} =
|
proc addCommunityToken*(token: CommunityTokenDto, croppedImageJson: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
let payload = %* [token.toJsonNode()]
|
let croppedImage = newCroppedImage(croppedImageJson)
|
||||||
|
let payload = %* [token.toJsonNode(), croppedImage]
|
||||||
return core.callPrivateRPC("wakuext_addCommunityToken", payload)
|
return core.callPrivateRPC("wakuext_addCommunityToken", payload)
|
||||||
|
|
||||||
proc updateCommunityTokenState*(chainId: int, contractAddress: string, deployState: DeployState): RpcResponse[JsonNode] {.raises: [Exception].} =
|
proc updateCommunityTokenState*(chainId: int, contractAddress: string, deployState: DeployState): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
|
|
|
@ -29,12 +29,11 @@ QtObject {
|
||||||
// TODO: Backend needs to create new role `accountName` and update this call accordingly
|
// TODO: Backend needs to create new role `accountName` and update this call accordingly
|
||||||
// TODO: Backend will need to check if the collectibleItem has a valid tokenKey, so it means a deployment retry,
|
// TODO: Backend will need to check if the collectibleItem has a valid tokenKey, so it means a deployment retry,
|
||||||
// otherwise, it is a new deployment.
|
// otherwise, it is a new deployment.
|
||||||
// TODO: Backend needs to modify the call to expect an image JSON file with cropped artwork information:
|
|
||||||
const jsonArtworkFile = Utils.getImageAndCropInfoJson(collectibleItem.artworkSource, collectibleItem.artworkCropRect)
|
const jsonArtworkFile = Utils.getImageAndCropInfoJson(collectibleItem.artworkSource, collectibleItem.artworkCropRect)
|
||||||
communityTokensModuleInst.deployCollectible(communityId, collectibleItem.accountAddress, collectibleItem.name,
|
communityTokensModuleInst.deployCollectible(communityId, collectibleItem.accountAddress, collectibleItem.name,
|
||||||
collectibleItem.symbol, collectibleItem.description, collectibleItem.supply,
|
collectibleItem.symbol, collectibleItem.description, collectibleItem.supply,
|
||||||
collectibleItem.infiniteSupply, collectibleItem.transferable, collectibleItem.remotelyDestruct,
|
collectibleItem.infiniteSupply, collectibleItem.transferable, collectibleItem.remotelyDestruct,
|
||||||
collectibleItem.chainId, collectibleItem.artworkSource/*instead: jsonArtworkFile*/)
|
collectibleItem.chainId, jsonArtworkFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
function deployAsset(communityId, assetItem)
|
function deployAsset(communityId, assetItem)
|
||||||
|
@ -42,11 +41,10 @@ QtObject {
|
||||||
// TODO: Backend needs to create new role `accountName` and update this call accordingly
|
// TODO: Backend needs to create new role `accountName` and update this call accordingly
|
||||||
// TODO: Backend will need to check if the collectibleItem has a valid tokenKey, so it means a deployment retry,
|
// TODO: Backend will need to check if the collectibleItem has a valid tokenKey, so it means a deployment retry,
|
||||||
// otherwise, it is a new deployment.
|
// otherwise, it is a new deployment.
|
||||||
// TODO: Backend needs to modify the call to expect an image JSON file with cropped artwork information:
|
|
||||||
const jsonArtworkFile = Utils.getImageAndCropInfoJson(assetItem.artworkSource, assetItem.artworkCropRect)
|
const jsonArtworkFile = Utils.getImageAndCropInfoJson(assetItem.artworkSource, assetItem.artworkCropRect)
|
||||||
communityTokensModuleInst.deployAssets(communityId, assetItem.accountAddress, assetItem.name,
|
communityTokensModuleInst.deployAssets(communityId, assetItem.accountAddress, assetItem.name,
|
||||||
assetItem.symbol, assetItem.description, assetItem.supply,
|
assetItem.symbol, assetItem.description, assetItem.supply,
|
||||||
assetItem.infiniteSupply, assetItem.decimals, assetItem.chainId, assetItem.artworkSource/*instead: jsonArtworkFile*/)
|
assetItem.infiniteSupply, assetItem.decimals, assetItem.chainId, jsonArtworkFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteToken(communityId, contractUniqueKey) {
|
function deleteToken(communityId, contractUniqueKey) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit e5e5229e6a64c9f91d4f2c8bff283cd76c2f4568
|
Subproject commit ac666da495e8a007ae9deb120918baa920870749
|
Loading…
Reference in New Issue