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)
|
||||
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) =
|
||||
self.communityTokensService.deployContract(communityId, addressFrom, password, deploymentParams, tokenMetadata, chainId)
|
||||
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, tokenImageCropInfoJson, chainId)
|
||||
|
||||
proc airdropCollectibles*(self: Controller, communityId: string, password: string, collectiblesAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string]) =
|
||||
self.communityTokensService.airdropCollectibles(communityId, password, collectiblesAndAmounts, walletAddresses)
|
||||
|
@ -105,4 +105,4 @@ proc computeBurnFee*(self: Controller, contractUniqueKey: string, amount: int) =
|
|||
self.communityTokensService.computeBurnFee(contractUniqueKey, amount)
|
||||
|
||||
proc getNetwork*(self:Controller, chainId: int): NetworkDto =
|
||||
self.networksService.getNetwork(chainId)
|
||||
self.networksService.getNetwork(chainId)
|
||||
|
|
|
@ -24,11 +24,11 @@ method burnCollectibles*(self: AccessInterface, communityId: string, contractUni
|
|||
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,
|
||||
selfDestruct: bool, chainId: int, image: string) {.base.} =
|
||||
selfDestruct: bool, chainId: int, imageCropInfoJson: string) {.base.} =
|
||||
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,
|
||||
chainId: int, image: string) {.base.} =
|
||||
chainId: int, imageCropInfoJson: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onUserAuthenticated*(self: AccessInterface, password: string) {.base.} =
|
||||
|
@ -68,4 +68,4 @@ method onBurnStateChanged*(self: AccessInterface, communityId: string, tokenName
|
|||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onAirdropStateChanged*(self: AccessInterface, communityId: string, tokenName: string, chainId: int, transactionHash: string, status: ContractTransactionStatus) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
|
|
@ -35,6 +35,7 @@ type
|
|||
tempContractAddress: string
|
||||
tempDeploymentParams: DeploymentParameters
|
||||
tempTokenMetadata: CommunityTokensMetadataDto
|
||||
tempTokenImageCropInfoJson: string
|
||||
tempWalletAddresses: seq[string]
|
||||
tempContractAction: ContractAction
|
||||
tempContractUniqueKey: string
|
||||
|
@ -62,6 +63,7 @@ method resetTempValues(self:Module) =
|
|||
self.tempCommunityId = ""
|
||||
self.tempDeploymentParams = DeploymentParameters()
|
||||
self.tempTokenMetadata = CommunityTokensMetadataDto()
|
||||
self.tempTokenImageCropInfoJson = ""
|
||||
self.tempChainId = 0
|
||||
self.tempContractAddress = ""
|
||||
self.tempWalletAddresses = @[]
|
||||
|
@ -131,7 +133,7 @@ method burnCollectibles*(self: Module, communityId: string, contractUniqueKey: s
|
|||
self.authenticate()
|
||||
|
||||
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.tempCommunityId = communityId
|
||||
self.tempChainId = chainId
|
||||
|
@ -143,13 +145,13 @@ method deployCollectibles*(self: Module, communityId: string, fromAddress: strin
|
|||
self.tempDeploymentParams.remoteSelfDestruct = selfDestruct
|
||||
self.tempDeploymentParams.tokenUri = utl.changeCommunityKeyCompression(communityId) & "/"
|
||||
self.tempTokenMetadata.tokenType = TokenType.ERC721
|
||||
self.tempTokenMetadata.image = singletonInstance.utils.formatImagePath(image)
|
||||
self.tempTokenMetadata.description = description
|
||||
self.tempTokenImageCropInfoJson = imageCropInfoJson
|
||||
self.tempContractAction = ContractAction.Deploy
|
||||
self.authenticate()
|
||||
|
||||
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.tempCommunityId = communityId
|
||||
self.tempChainId = chainId
|
||||
|
@ -160,8 +162,8 @@ method deployAssets*(self: Module, communityId: string, fromAddress: string, nam
|
|||
self.tempDeploymentParams.decimals = decimals
|
||||
self.tempDeploymentParams.tokenUri = utl.changeCommunityKeyCompression(communityId) & "/"
|
||||
self.tempTokenMetadata.tokenType = TokenType.ERC20
|
||||
self.tempTokenMetadata.image = singletonInstance.utils.formatImagePath(image)
|
||||
self.tempTokenMetadata.description = description
|
||||
self.tempTokenImageCropInfoJson = imageCropInfoJson
|
||||
self.tempContractAction = ContractAction.Deploy
|
||||
self.authenticate()
|
||||
|
||||
|
@ -172,7 +174,7 @@ method onUserAuthenticated*(self: Module, password: string) =
|
|||
#TODO signalize somehow
|
||||
else:
|
||||
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:
|
||||
self.controller.airdropCollectibles(self.tempCommunityId, password, self.tempTokenAndAmountList, self.tempWalletAddresses)
|
||||
elif self.tempContractAction == ContractAction.SelfDestruct:
|
||||
|
@ -225,4 +227,4 @@ method onBurnStateChanged*(self: Module, communityId: string, tokenName: string,
|
|||
method onAirdropStateChanged*(self: Module, communityId: string, tokenName: string, chainId: int, transactionHash: string, status: ContractTransactionStatus) =
|
||||
let url = self.createUrl(chainId, transactionHash)
|
||||
let chainName = self.getChainName(chainId)
|
||||
self.view.emitAirdropStateChanged(communityId, tokenName, chainName, status.int, url)
|
||||
self.view.emitAirdropStateChanged(communityId, tokenName, chainName, status.int, url)
|
||||
|
|
|
@ -21,11 +21,11 @@ QtObject:
|
|||
result.QObject.setup
|
||||
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.} =
|
||||
self.communityTokensModule.deployCollectibles(communityId, fromAddress, name, symbol, description, supply, infiniteSupply, transferable, selfDestruct, chainId, image)
|
||||
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, 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.} =
|
||||
self.communityTokensModule.deployAssets(communityId, fromAddress, name, symbol, description, supply, infiniteSupply, decimals, chainId, image)
|
||||
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, imageCropInfoJson)
|
||||
|
||||
proc airdropCollectibles*(self: View, communityId: string, collectiblesJsonString: string, walletsJsonString: string) {.slot.} =
|
||||
self.communityTokensModule.airdropCollectibles(communityId, collectiblesJsonString, walletsJsonString)
|
||||
|
@ -79,4 +79,4 @@ QtObject:
|
|||
|
||||
proc airdropStateChanged*(self: View, communityId: string, tokenName: string, chainName: string, status: int, url: string) {.signal.}
|
||||
proc emitAirdropStateChanged*(self: View, communityId: string, tokenName: string, chainName: string, status: int, url: string) =
|
||||
self.airdropStateChanged(communityId, tokenName, chainName, status, url)
|
||||
self.airdropStateChanged(communityId, tokenName, chainName, status, url)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import NimQml, Tables, chronicles, json, stint, strutils, sugar, sequtils
|
||||
import ../../../app/global/global_singleton
|
||||
import ../../../app/core/eventemitter
|
||||
import ../../../app/core/tasks/[qt, threadpool]
|
||||
import ../../../app/modules/shared_models/currency_amount
|
||||
|
@ -288,7 +289,7 @@ QtObject:
|
|||
if suggestedFees.eip1559Enabled: $suggestedFees.maxPriorityFeePerGas 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:
|
||||
let txData = self.buildTransactionDataDto(addressFrom, chainId, "")
|
||||
if txData.source == parseAddress(ZERO_ADDRESS):
|
||||
|
@ -323,11 +324,13 @@ QtObject:
|
|||
communityToken.tokenUri = deploymentParams.tokenUri
|
||||
communityToken.chainId = chainId
|
||||
communityToken.deployState = DeployState.InProgress
|
||||
communityToken.image = tokenMetadata.image
|
||||
communityToken.decimals = deploymentParams.decimals
|
||||
|
||||
var croppedImage = croppedImageJson.parseJson
|
||||
croppedImage{"imagePath"} = newJString(singletonInstance.utils.formatImagePath(croppedImage["imagePath"].getStr))
|
||||
|
||||
# save token to db
|
||||
let communityTokenJson = tokens_backend.addCommunityToken(communityToken)
|
||||
let communityTokenJson = tokens_backend.addCommunityToken(communityToken, $croppedImage)
|
||||
communityToken = communityTokenJson.result.toCommunityTokenDto()
|
||||
let data = CommunityTokenDeployedArgs(communityToken: communityToken, transactionHash: transactionHash)
|
||||
self.events.emit(SIGNAL_COMMUNITY_TOKEN_DEPLOYED, data)
|
||||
|
@ -793,4 +796,4 @@ QtObject:
|
|||
proc fetchAllTokenOwners*(self: Service) =
|
||||
let allTokens = self.getAllCommunityTokens()
|
||||
for token in allTokens:
|
||||
self.fetchCommunityOwners(token)
|
||||
self.fetchCommunityOwners(token)
|
||||
|
|
|
@ -5,6 +5,7 @@ import ./eth
|
|||
import ../app_service/common/utils
|
||||
import ./core, ./response_type
|
||||
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].} =
|
||||
let payload = %* [chainId, deploymentParams, txData, utils.hashPassword(password)]
|
||||
|
@ -22,8 +23,9 @@ proc getAllCommunityTokens*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|||
let payload = %* []
|
||||
return core.callPrivateRPC("wakuext_getAllCommunityTokens", payload)
|
||||
|
||||
proc addCommunityToken*(token: CommunityTokenDto): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* [token.toJsonNode()]
|
||||
proc addCommunityToken*(token: CommunityTokenDto, croppedImageJson: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let croppedImage = newCroppedImage(croppedImageJson)
|
||||
let payload = %* [token.toJsonNode(), croppedImage]
|
||||
return core.callPrivateRPC("wakuext_addCommunityToken", payload)
|
||||
|
||||
proc updateCommunityTokenState*(chainId: int, contractAddress: string, deployState: DeployState): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
|
@ -72,4 +74,4 @@ proc deployCollectiblesEstimate*(): RpcResponse[JsonNode] {.raises: [Exception].
|
|||
|
||||
proc deployAssetsEstimate*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %*[]
|
||||
return core.callPrivateRPC("collectibles_deployAssetsEstimate", payload)
|
||||
return core.callPrivateRPC("collectibles_deployAssetsEstimate", payload)
|
||||
|
|
|
@ -29,12 +29,11 @@ QtObject {
|
|||
// 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,
|
||||
// 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)
|
||||
communityTokensModuleInst.deployCollectible(communityId, collectibleItem.accountAddress, collectibleItem.name,
|
||||
collectibleItem.symbol, collectibleItem.description, collectibleItem.supply,
|
||||
collectibleItem.infiniteSupply, collectibleItem.transferable, collectibleItem.remotelyDestruct,
|
||||
collectibleItem.chainId, collectibleItem.artworkSource/*instead: jsonArtworkFile*/)
|
||||
collectibleItem.chainId, jsonArtworkFile)
|
||||
}
|
||||
|
||||
function deployAsset(communityId, assetItem)
|
||||
|
@ -42,11 +41,10 @@ QtObject {
|
|||
// 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,
|
||||
// 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)
|
||||
communityTokensModuleInst.deployAssets(communityId, assetItem.accountAddress, assetItem.name,
|
||||
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) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e5e5229e6a64c9f91d4f2c8bff283cd76c2f4568
|
||||
Subproject commit ac666da495e8a007ae9deb120918baa920870749
|
Loading…
Reference in New Issue