fix(@desktop/communities): Pass addressFrom from UI to contract calls.

Use address set in UI instead of deployer.

Fix #11827
This commit is contained in:
Michal Iskierko 2023-08-17 09:51:08 +02:00 committed by Michał Iskierko
parent 6b570d1114
commit da30b8d2d8
8 changed files with 86 additions and 92 deletions

View File

@ -94,17 +94,17 @@ proc deployOwnerContracts*(self: Controller, communityId: string, addressFrom: s
proc removeCommunityToken*(self: Controller, communityId: string, chainId: int, address: string) = proc removeCommunityToken*(self: Controller, communityId: string, chainId: int, address: string) =
self.communityTokensService.removeCommunityToken(communityId, chainId, address) self.communityTokensService.removeCommunityToken(communityId, chainId, address)
proc airdropTokens*(self: Controller, communityId: string, password: string, tokensAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string]) = proc airdropTokens*(self: Controller, communityId: string, password: string, tokensAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string], addressFrom: string) =
self.communityTokensService.airdropTokens(communityId, password, tokensAndAmounts, walletAddresses) self.communityTokensService.airdropTokens(communityId, password, tokensAndAmounts, walletAddresses, addressFrom)
proc computeAirdropFee*(self: Controller, tokensAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string]) = proc computeAirdropFee*(self: Controller, tokensAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string], addressFrom: string) =
self.communityTokensService.computeAirdropFee(tokensAndAmounts, walletAddresses) self.communityTokensService.computeAirdropFee(tokensAndAmounts, walletAddresses, addressFrom)
proc selfDestructCollectibles*(self: Controller, communityId: string, password: string, walletAndAmounts: seq[WalletAndAmount], contractUniqueKey: string) = proc selfDestructCollectibles*(self: Controller, communityId: string, password: string, walletAndAmounts: seq[WalletAndAmount], contractUniqueKey: string, addressFrom: string) =
self.communityTokensService.selfDestructCollectibles(communityId, password, walletAndAmounts, contractUniqueKey) self.communityTokensService.selfDestructCollectibles(communityId, password, walletAndAmounts, contractUniqueKey, addressFrom)
proc burnTokens*(self: Controller, communityId: string, password: string, contractUniqueKey: string, amount: Uint256) = proc burnTokens*(self: Controller, communityId: string, password: string, contractUniqueKey: string, amount: Uint256, addressFrom: string) =
self.communityTokensService.burnTokens(communityId, password, contractUniqueKey, amount) self.communityTokensService.burnTokens(communityId, password, contractUniqueKey, amount, addressFrom)
proc authenticateUser*(self: Controller, keyUid = "") = proc authenticateUser*(self: Controller, keyUid = "") =
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_DEPLOY_COLLECTIBLES_COMMUNITY_TOKENS_MODULE_IDENTIFIER, keyUid: keyUid) let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_DEPLOY_COLLECTIBLES_COMMUNITY_TOKENS_MODULE_IDENTIFIER, keyUid: keyUid)
@ -119,14 +119,14 @@ proc computeDeployFee*(self: Controller, chainId: int, accountAddress: string, t
proc computeDeployOwnerContractsFee*(self: Controller, chainId: int, accountAddress: string) = proc computeDeployOwnerContractsFee*(self: Controller, chainId: int, accountAddress: string) =
self.communityTokensService.computeDeployOwnerContractsFee(chainId, accountAddress) self.communityTokensService.computeDeployOwnerContractsFee(chainId, accountAddress)
proc computeSelfDestructFee*(self: Controller, walletAndAmountList: seq[WalletAndAmount], contractUniqueKey: string) = proc computeSelfDestructFee*(self: Controller, walletAndAmountList: seq[WalletAndAmount], contractUniqueKey: string, addressFrom: string) =
self.communityTokensService.computeSelfDestructFee(walletAndAmountList, contractUniqueKey) self.communityTokensService.computeSelfDestructFee(walletAndAmountList, contractUniqueKey, addressFrom)
proc findContractByUniqueId*(self: Controller, contractUniqueKey: string): CommunityTokenDto = proc findContractByUniqueId*(self: Controller, contractUniqueKey: string): CommunityTokenDto =
return self.communityTokensService.findContractByUniqueId(contractUniqueKey) return self.communityTokensService.findContractByUniqueId(contractUniqueKey)
proc computeBurnFee*(self: Controller, contractUniqueKey: string, amount: Uint256) = proc computeBurnFee*(self: Controller, contractUniqueKey: string, amount: Uint256, addressFrom: string) =
self.communityTokensService.computeBurnFee(contractUniqueKey, amount) self.communityTokensService.computeBurnFee(contractUniqueKey, amount, addressFrom)
proc getNetwork*(self:Controller, chainId: int): NetworkDto = proc getNetwork*(self:Controller, chainId: int): NetworkDto =
self.networksService.getNetwork(chainId) self.networksService.getNetwork(chainId)

View File

@ -12,16 +12,16 @@ method delete*(self: AccessInterface) {.base.} =
method load*(self: AccessInterface) {.base.} = method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method airdropTokens*(self: AccessInterface, communityId: string, tokensJsonString: string, walletsJsonString: string) {.base.} = method airdropTokens*(self: AccessInterface, communityId: string, tokensJsonString: string, walletsJsonString: string, addressFrom: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method computeAirdropFee*(self: AccessInterface, communityId: string, tokensJsonString: string, walletsJsonString: string) {.base.} = method computeAirdropFee*(self: AccessInterface, communityId: string, tokensJsonString: string, walletsJsonString: string, addressFrom: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method selfDestructCollectibles*(self: AccessInterface, communityId: string, collectiblesToBurnJsonString: string, contractUniqueKey: string) {.base.} = method selfDestructCollectibles*(self: AccessInterface, communityId: string, collectiblesToBurnJsonString: string, contractUniqueKey: string, addressFrom: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method burnTokens*(self: AccessInterface, communityId: string, contractUniqueKey: string, amount: string) {.base.} = method burnTokens*(self: AccessInterface, communityId: string, contractUniqueKey: string, amount: string, addressFrom: string) {.base.} =
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: string, infiniteSupply: bool, transferable: bool, method deployCollectibles*(self: AccessInterface, communityId: string, address: string, name: string, symbol: string, description: string, supply: string, infiniteSupply: bool, transferable: bool,
@ -45,10 +45,10 @@ method resetTempValues*(self: AccessInterface) {.base.} =
method computeDeployFee*(self: AccessInterface, chainId: int, accountAddress: string, tokenType: TokenType, isOwnerDeployment: bool) {.base.} = method computeDeployFee*(self: AccessInterface, chainId: int, accountAddress: string, tokenType: TokenType, isOwnerDeployment: bool) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method computeSelfDestructFee*(self: AccessInterface, collectiblesToBurnJsonString: string, contractUniqueKey: string) {.base.} = method computeSelfDestructFee*(self: AccessInterface, collectiblesToBurnJsonString: string, contractUniqueKey: string, addressFrom: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method computeBurnFee*(self: AccessInterface, contractUniqueKey: string, amount: string) {.base.} = method computeBurnFee*(self: AccessInterface, contractUniqueKey: string, amount: string, addressFrom: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method onDeployFeeComputed*(self: AccessInterface, ethCurrency: CurrencyAmount, fiatCurrency: CurrencyAmount, errorCode: ComputeFeeErrorCode) {.base.} = method onDeployFeeComputed*(self: AccessInterface, ethCurrency: CurrencyAmount, fiatCurrency: CurrencyAmount, errorCode: ComputeFeeErrorCode) {.base.} =

View File

@ -107,20 +107,21 @@ proc getTokenAndAmountList(self: Module, communityId: string, tokensJsonString:
except Exception as e: except Exception as e:
error "Error getTokenAndAmountList", msg = e.msg error "Error getTokenAndAmountList", msg = e.msg
method airdropTokens*(self: Module, communityId: string, tokensJsonString: string, walletsJsonString: string) = method airdropTokens*(self: Module, communityId: string, tokensJsonString: string, walletsJsonString: string, addressFrom: string) =
self.tempTokenAndAmountList = self.getTokenAndAmountList(communityId, tokensJsonString) self.tempTokenAndAmountList = self.getTokenAndAmountList(communityId, tokensJsonString)
if len(self.tempTokenAndAmountList) == 0: if len(self.tempTokenAndAmountList) == 0:
return return
self.tempWalletAddresses = walletsJsonString.parseJson.to(seq[string]) self.tempWalletAddresses = walletsJsonString.parseJson.to(seq[string])
self.tempCommunityId = communityId self.tempCommunityId = communityId
self.tempAddressFrom = addressFrom
self.tempContractAction = ContractAction.Airdrop self.tempContractAction = ContractAction.Airdrop
self.authenticate() self.authenticate()
method computeAirdropFee*(self: Module, communityId: string, tokensJsonString: string, walletsJsonString: string) = method computeAirdropFee*(self: Module, communityId: string, tokensJsonString: string, walletsJsonString: string, addressFrom: string) =
let tokenAndAmountList = self.getTokenAndAmountList(communityId, tokensJsonString) let tokenAndAmountList = self.getTokenAndAmountList(communityId, tokensJsonString)
if len(tokenAndAmountList) == 0: if len(tokenAndAmountList) == 0:
return return
self.controller.computeAirdropFee(tokenAndAmountList, walletsJsonString.parseJson.to(seq[string])) self.controller.computeAirdropFee(tokenAndAmountList, walletsJsonString.parseJson.to(seq[string]), addressFrom)
proc getWalletAndAmountListFromJson(self: Module, collectiblesToBurnJsonString: string): seq[WalletAndAmount] = proc getWalletAndAmountListFromJson(self: Module, collectiblesToBurnJsonString: string): seq[WalletAndAmount] =
let collectiblesToBurnJson = collectiblesToBurnJsonString.parseJson let collectiblesToBurnJson = collectiblesToBurnJsonString.parseJson
@ -129,18 +130,19 @@ proc getWalletAndAmountListFromJson(self: Module, collectiblesToBurnJsonString:
let amount = collectibleToBurn["amount"].getInt let amount = collectibleToBurn["amount"].getInt
result.add(WalletAndAmount(walletAddress: walletAddress, amount: amount)) result.add(WalletAndAmount(walletAddress: walletAddress, amount: amount))
method selfDestructCollectibles*(self: Module, communityId: string, collectiblesToBurnJsonString: string, contractUniqueKey: string) = method selfDestructCollectibles*(self: Module, communityId: string, collectiblesToBurnJsonString: string, contractUniqueKey: string, addressFrom: string) =
self.tempWalletAndAmountList = self.getWalletAndAmountListFromJson(collectiblesToBurnJsonString) self.tempWalletAndAmountList = self.getWalletAndAmountListFromJson(collectiblesToBurnJsonString)
self.tempCommunityId = communityId self.tempCommunityId = communityId
self.tempContractUniqueKey = contractUniqueKey self.tempContractUniqueKey = contractUniqueKey
self.tempAddressFrom = addressFrom
self.tempContractAction = ContractAction.SelfDestruct self.tempContractAction = ContractAction.SelfDestruct
self.authenticate() self.authenticate()
method burnTokens*(self: Module, communityId: string, contractUniqueKey: string, amount: string) = method burnTokens*(self: Module, communityId: string, contractUniqueKey: string, amount: string, addressFrom: string) =
let tokenDto = self.controller.findContractByUniqueId(contractUniqueKey)
self.tempCommunityId = communityId self.tempCommunityId = communityId
self.tempContractUniqueKey = contractUniqueKey self.tempContractUniqueKey = contractUniqueKey
self.tempAmount = amount.parse(Uint256) self.tempAmount = amount.parse(Uint256)
self.tempAddressFrom = addressFrom
self.tempContractAction = ContractAction.Burn self.tempContractAction = ContractAction.Burn
self.authenticate() self.authenticate()
@ -225,11 +227,11 @@ method onUserAuthenticated*(self: Module, password: string) =
if self.tempContractAction == ContractAction.Deploy: if self.tempContractAction == ContractAction.Deploy:
self.controller.deployContract(self.tempCommunityId, self.tempAddressFrom, password, self.tempDeploymentParams, self.tempTokenMetadata, self.tempTokenImageCropInfoJson, 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.airdropTokens(self.tempCommunityId, password, self.tempTokenAndAmountList, self.tempWalletAddresses) self.controller.airdropTokens(self.tempCommunityId, password, self.tempTokenAndAmountList, self.tempWalletAddresses, self.tempAddressFrom)
elif self.tempContractAction == ContractAction.SelfDestruct: elif self.tempContractAction == ContractAction.SelfDestruct:
self.controller.selfDestructCollectibles(self.tempCommunityId, password, self.tempWalletAndAmountList, self.tempContractUniqueKey) self.controller.selfDestructCollectibles(self.tempCommunityId, password, self.tempWalletAndAmountList, self.tempContractUniqueKey, self.tempAddressFrom)
elif self.tempContractAction == ContractAction.Burn: elif self.tempContractAction == ContractAction.Burn:
self.controller.burnTokens(self.tempCommunityId, password, self.tempContractUniqueKey, self.tempAmount) self.controller.burnTokens(self.tempCommunityId, password, self.tempContractUniqueKey, self.tempAmount, self.tempAddressFrom)
elif self.tempContractAction == ContractAction.DeployOwnerToken: elif self.tempContractAction == ContractAction.DeployOwnerToken:
self.controller.deployOwnerContracts(self.tempCommunityId, self.tempAddressFrom, password, self.controller.deployOwnerContracts(self.tempCommunityId, self.tempAddressFrom, password,
self.tempOwnerDeploymentParams, self.tempOwnerTokenMetadata, self.tempOwnerDeploymentParams, self.tempOwnerTokenMetadata,
@ -254,13 +256,12 @@ method computeDeployFee*(self: Module, chainId: int, accountAddress: string, tok
else: else:
self.controller.computeDeployFee(chainId, accountAddress, tokenType) self.controller.computeDeployFee(chainId, accountAddress, tokenType)
method computeSelfDestructFee*(self: Module, collectiblesToBurnJsonString: string, contractUniqueKey: string) = method computeSelfDestructFee*(self: Module, collectiblesToBurnJsonString: string, contractUniqueKey: string, addressFrom: string) =
let walletAndAmountList = self.getWalletAndAmountListFromJson(collectiblesToBurnJsonString) let walletAndAmountList = self.getWalletAndAmountListFromJson(collectiblesToBurnJsonString)
self.controller.computeSelfDestructFee(walletAndAmountList, contractUniqueKey) self.controller.computeSelfDestructFee(walletAndAmountList, contractUniqueKey, addressFrom)
method computeBurnFee*(self: Module, contractUniqueKey: string, amount: string) = method computeBurnFee*(self: Module, contractUniqueKey: string, amount: string, addressFrom: string) =
let tokenDto = self.controller.findContractByUniqueId(contractUniqueKey) self.controller.computeBurnFee(contractUniqueKey, amount.parse(Uint256), addressFrom)
self.controller.computeBurnFee(contractUniqueKey, amount.parse(Uint256))
proc createUrl(self: Module, chainId: int, transactionHash: string): string = proc createUrl(self: Module, chainId: int, transactionHash: string): string =
let network = self.controller.getNetwork(chainId) let network = self.controller.getNetwork(chainId)

View File

@ -33,17 +33,17 @@ QtObject:
proc removeCommunityToken*(self: View, communityId: string, chainId: int, address: string) {.slot.} = proc removeCommunityToken*(self: View, communityId: string, chainId: int, address: string) {.slot.} =
self.communityTokensModule.removeCommunityToken(communityId, chainId, address) self.communityTokensModule.removeCommunityToken(communityId, chainId, address)
proc airdropTokens*(self: View, communityId: string, tokensJsonString: string, walletsJsonString: string) {.slot.} = proc airdropTokens*(self: View, communityId: string, tokensJsonString: string, walletsJsonString: string, addressFrom: string) {.slot.} =
self.communityTokensModule.airdropTokens(communityId, tokensJsonString, walletsJsonString) self.communityTokensModule.airdropTokens(communityId, tokensJsonString, walletsJsonString, addressFrom)
proc computeAirdropFee*(self: View, communityId: string, tokensJsonString: string, walletsJsonString: string) {.slot.} = proc computeAirdropFee*(self: View, communityId: string, tokensJsonString: string, walletsJsonString: string, addressFrom: string) {.slot.} =
self.communityTokensModule.computeAirdropFee(communityId, tokensJsonString, walletsJsonString) self.communityTokensModule.computeAirdropFee(communityId, tokensJsonString, walletsJsonString, addressFrom)
proc selfDestructCollectibles*(self: View, communityId: string, collectiblesToBurnJsonString: string, contractUniqueKey: string) {.slot.} = proc selfDestructCollectibles*(self: View, communityId: string, collectiblesToBurnJsonString: string, contractUniqueKey: string, addressFrom: string) {.slot.} =
self.communityTokensModule.selfDestructCollectibles(communityId, collectiblesToBurnJsonString, contractUniqueKey) self.communityTokensModule.selfDestructCollectibles(communityId, collectiblesToBurnJsonString, contractUniqueKey, addressFrom)
proc burnTokens*(self: View, communityId: string, contractUniqueKey: string, amount: string) {.slot.} = proc burnTokens*(self: View, communityId: string, contractUniqueKey: string, amount: string, addressFrom: string) {.slot.} =
self.communityTokensModule.burnTokens(communityId, contractUniqueKey, amount) self.communityTokensModule.burnTokens(communityId, contractUniqueKey, amount, addressFrom)
proc deployFeeUpdated*(self: View, ethCurrency: QVariant, fiatCurrency: QVariant, errorCode: int) {.signal.} proc deployFeeUpdated*(self: View, ethCurrency: QVariant, fiatCurrency: QVariant, errorCode: int) {.signal.}
proc selfDestructFeeUpdated*(self: View, ethCurrency: QVariant, fiatCurrency: QVariant, errorCode: int) {.signal.} proc selfDestructFeeUpdated*(self: View, ethCurrency: QVariant, fiatCurrency: QVariant, errorCode: int) {.signal.}
@ -53,11 +53,11 @@ QtObject:
proc computeDeployFee*(self: View, chainId: int, accountAddress: string, tokenType: int, isOwnerDeployment: bool) {.slot.} = proc computeDeployFee*(self: View, chainId: int, accountAddress: string, tokenType: int, isOwnerDeployment: bool) {.slot.} =
self.communityTokensModule.computeDeployFee(chainId, accountAddress, intToEnum(tokenType, TokenType.Unknown), isOwnerDeployment) self.communityTokensModule.computeDeployFee(chainId, accountAddress, intToEnum(tokenType, TokenType.Unknown), isOwnerDeployment)
proc computeSelfDestructFee*(self: View, collectiblesToBurnJsonString: string, contractUniqueKey: string) {.slot.} = proc computeSelfDestructFee*(self: View, collectiblesToBurnJsonString: string, contractUniqueKey: string, addressFrom: string) {.slot.} =
self.communityTokensModule.computeSelfDestructFee(collectiblesToBurnJsonString, contractUniqueKey) self.communityTokensModule.computeSelfDestructFee(collectiblesToBurnJsonString, contractUniqueKey, addressFrom)
proc computeBurnFee*(self: View, contractUniqueKey: string, amount: string) {.slot.} = proc computeBurnFee*(self: View, contractUniqueKey: string, amount: string, addressFrom: string) {.slot.} =
self.communityTokensModule.computeBurnFee(contractUniqueKey, amount) self.communityTokensModule.computeBurnFee(contractUniqueKey, amount, addressFrom)
proc updateDeployFee*(self: View, ethCurrency: CurrencyAmount, fiatCurrency: CurrencyAmount, errorCode: int) = proc updateDeployFee*(self: View, ethCurrency: CurrencyAmount, fiatCurrency: CurrencyAmount, errorCode: int) =
self.deployFeeUpdated(newQVariant(ethCurrency), newQVariant(fiatCurrency), errorCode) self.deployFeeUpdated(newQVariant(ethCurrency), newQVariant(fiatCurrency), errorCode)

View File

@ -20,6 +20,7 @@ proc tableToJsonArray[A, B](t: var Table[A, B]): JsonNode =
type type
AsyncDeployOwnerContractsFeesArg = ref object of QObjectTaskArg AsyncDeployOwnerContractsFeesArg = ref object of QObjectTaskArg
chainId: int chainId: int
addressFrom: string
const asyncGetDeployOwnerContractsFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = const asyncGetDeployOwnerContractsFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncDeployOwnerContractsFeesArg](argEncoded) let arg = decode[AsyncDeployOwnerContractsFeesArg](argEncoded)
@ -33,6 +34,8 @@ const asyncGetDeployOwnerContractsFeesTask: Task = proc(argEncoded: string) {.gc
arg.finish(%* { arg.finish(%* {
"feeTable": tableToJsonArray(feeTable), "feeTable": tableToJsonArray(feeTable),
"gasTable": tableToJsonArray(gasTable), "gasTable": tableToJsonArray(gasTable),
"chainId": arg.chainId,
"addressFrom": arg.addressFrom,
"error": "", "error": "",
}) })
except Exception as e: except Exception as e:
@ -43,6 +46,7 @@ const asyncGetDeployOwnerContractsFeesTask: Task = proc(argEncoded: string) {.gc
type type
AsyncGetDeployFeesArg = ref object of QObjectTaskArg AsyncGetDeployFeesArg = ref object of QObjectTaskArg
chainId: int chainId: int
addressFrom: string
tokenType: TokenType tokenType: TokenType
const asyncGetDeployFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = const asyncGetDeployFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
@ -58,6 +62,8 @@ const asyncGetDeployFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.
arg.finish(%* { arg.finish(%* {
"feeTable": tableToJsonArray(feeTable), "feeTable": tableToJsonArray(feeTable),
"gasTable": tableToJsonArray(gasTable), "gasTable": tableToJsonArray(gasTable),
"chainId": arg.chainId,
"addressFrom": arg.addressFrom,
"error": "", "error": "",
}) })
except Exception as e: except Exception as e:
@ -84,6 +90,8 @@ const asyncGetRemoteBurnFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimc
arg.finish(%* { arg.finish(%* {
"feeTable": tableToJsonArray(feeTable), "feeTable": tableToJsonArray(feeTable),
"gasTable": tableToJsonArray(gasTable), "gasTable": tableToJsonArray(gasTable),
"chainId": arg.chainId,
"addressFrom": arg.addressFrom,
"error": "" }) "error": "" })
except Exception as e: except Exception as e:
arg.finish(%* { arg.finish(%* {
@ -109,6 +117,8 @@ const asyncGetBurnFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.}
arg.finish(%* { arg.finish(%* {
"feeTable": tableToJsonArray(feeTable), "feeTable": tableToJsonArray(feeTable),
"gasTable": tableToJsonArray(gasTable), "gasTable": tableToJsonArray(gasTable),
"chainId": arg.chainId,
"addressFrom": arg.addressFrom,
"error": "" }) "error": "" })
except Exception as e: except Exception as e:
arg.finish(%* { arg.finish(%* {
@ -119,6 +129,7 @@ type
AsyncGetMintFees = ref object of QObjectTaskArg AsyncGetMintFees = ref object of QObjectTaskArg
collectiblesAndAmounts: seq[CommunityTokenAndAmount] collectiblesAndAmounts: seq[CommunityTokenAndAmount]
walletAddresses: seq[string] walletAddresses: seq[string]
addressFrom: string
const asyncGetMintFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = const asyncGetMintFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncGetMintFees](argEncoded) let arg = decode[AsyncGetMintFees](argEncoded)
@ -134,12 +145,13 @@ const asyncGetMintFeesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.}
# get gas for smart contract # get gas for smart contract
let gas = community_tokens.estimateMintTokens(chainId, let gas = community_tokens.estimateMintTokens(chainId,
collectibleAndAmount.communityToken.address, collectibleAndAmount.communityToken.deployer, collectibleAndAmount.communityToken.address, arg.addressFrom,
arg.walletAddresses, collectibleAndAmount.amount).result.getInt arg.walletAddresses, collectibleAndAmount.amount).result.getInt
gasTable[(chainId, collectibleAndAmount.communityToken.address)] = gas gasTable[(chainId, collectibleAndAmount.communityToken.address)] = gas
arg.finish(%* { arg.finish(%* {
"feeTable": tableToJsonArray(feeTable), "feeTable": tableToJsonArray(feeTable),
"gasTable": tableToJsonArray(gasTable), "gasTable": tableToJsonArray(gasTable),
"addressFrom": arg.addressFrom,
"error": "" }) "error": "" })
except Exception as e: except Exception as e:
let output = %* { let output = %* {

View File

@ -229,8 +229,7 @@ QtObject:
tokenService: token_service.Service tokenService: token_service.Service
settingsService: settings_service.Service settingsService: settings_service.Service
walletAccountService: wallet_account_service.Service walletAccountService: wallet_account_service.Service
tempAccountAddress: string
tempChainId: int
tokenOwnersTimer: QTimer tokenOwnersTimer: QTimer
tokenOwners1SecTimer: QTimer # used to update 1 sec after changes in owners tokenOwners1SecTimer: QTimer # used to update 1 sec after changes in owners
tempTokenOwnersToFetch: CommunityTokenDto # used by 1sec timer tempTokenOwnersToFetch: CommunityTokenDto # used by 1sec timer
@ -240,12 +239,6 @@ QtObject:
tempGasTable: Table[ContractTuple, int] # gas per contract, filled during gas computation, used during operation (deployment, mint, burn) tempGasTable: Table[ContractTuple, int] # gas per contract, filled during gas computation, used during operation (deployment, mint, burn)
tempTokensAndAmounts: seq[CommunityTokenAndAmount] tempTokensAndAmounts: seq[CommunityTokenAndAmount]
tempDeploymentChainId: int
tempDeploymentCommunityId: string
tempDeploymentParams: DeploymentParameters
tempDeploymentCroppedImageJson: string
tempDeploymentAddressFrom: string
# Forward declaration # Forward declaration
proc fetchAllTokenOwners*(self: Service) proc fetchAllTokenOwners*(self: Service)
proc getCommunityTokenOwners*(self: Service, communityId: string, chainId: int, contractAddress: string): seq[CommunityCollectibleOwner] proc getCommunityTokenOwners*(self: Service, communityId: string, chainId: int, contractAddress: string): seq[CommunityCollectibleOwner]
@ -620,10 +613,9 @@ QtObject:
except RpcException: except RpcException:
error "Error getting remote destructed amount", message = getCurrentExceptionMsg() error "Error getting remote destructed amount", message = getCurrentExceptionMsg()
proc airdropTokens*(self: Service, communityId: string, password: string, collectiblesAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string]) = proc airdropTokens*(self: Service, communityId: string, password: string, collectiblesAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string], addressFrom: string) =
try: try:
for collectibleAndAmount in collectiblesAndAmounts: for collectibleAndAmount in collectiblesAndAmounts:
let addressFrom = collectibleAndAmount.communityToken.deployer
let txData = self.buildTransactionDataDto(addressFrom, collectibleAndAmount.communityToken.chainId, collectibleAndAmount.communityToken.address) let txData = self.buildTransactionDataDto(addressFrom, collectibleAndAmount.communityToken.chainId, collectibleAndAmount.communityToken.address)
if txData.source == parseAddress(ZERO_ADDRESS): if txData.source == parseAddress(ZERO_ADDRESS):
return return
@ -647,7 +639,7 @@ QtObject:
except RpcException: except RpcException:
error "Error airdropping tokens", message = getCurrentExceptionMsg() error "Error airdropping tokens", message = getCurrentExceptionMsg()
proc computeAirdropFee*(self: Service, collectiblesAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string]) = proc computeAirdropFee*(self: Service, collectiblesAndAmounts: seq[CommunityTokenAndAmount], walletAddresses: seq[string], addressFrom: string) =
try: try:
self.tempTokensAndAmounts = collectiblesAndAmounts self.tempTokensAndAmounts = collectiblesAndAmounts
let arg = AsyncGetMintFees( let arg = AsyncGetMintFees(
@ -655,7 +647,8 @@ QtObject:
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),
slot: "onAirdropFees", slot: "onAirdropFees",
collectiblesAndAmounts: collectiblesAndAmounts, collectiblesAndAmounts: collectiblesAndAmounts,
walletAddresses: walletAddresses walletAddresses: walletAddresses,
addressFrom: addressFrom
) )
self.threadpool.start(arg) self.threadpool.start(arg)
except Exception as e: except Exception as e:
@ -673,13 +666,12 @@ QtObject:
if tokenType != TokenType.ERC20 and tokenType != TokenType.ERC721: if tokenType != TokenType.ERC20 and tokenType != TokenType.ERC721:
error "Error loading fees: unknown token type", tokenType = tokenType error "Error loading fees: unknown token type", tokenType = tokenType
return return
self.tempAccountAddress = accountAddress
self.tempChainId = chainId
let arg = AsyncGetDeployFeesArg( let arg = AsyncGetDeployFeesArg(
tptr: cast[ByteAddress](asyncGetDeployFeesTask), tptr: cast[ByteAddress](asyncGetDeployFeesTask),
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),
slot: "onDeployFees", slot: "onDeployFees",
chainId: chainId, chainId: chainId,
addressFrom: accountAddress,
tokenType: tokenType tokenType: tokenType
) )
self.threadpool.start(arg) self.threadpool.start(arg)
@ -688,13 +680,12 @@ QtObject:
proc computeDeployOwnerContractsFee*(self: Service, chainId: int, accountAddress: string) = proc computeDeployOwnerContractsFee*(self: Service, chainId: int, accountAddress: string) =
try: try:
self.tempAccountAddress = accountAddress
self.tempChainId = chainId
let arg = AsyncDeployOwnerContractsFeesArg( let arg = AsyncDeployOwnerContractsFeesArg(
tptr: cast[ByteAddress](asyncGetDeployOwnerContractsFeesTask), tptr: cast[ByteAddress](asyncGetDeployOwnerContractsFeesTask),
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),
slot: "onDeployOwnerContractsFees", slot: "onDeployOwnerContractsFees",
chainId: chainId, chainId: chainId,
addressFrom: accountAddress
) )
self.threadpool.start(arg) self.threadpool.start(arg)
except Exception as e: except Exception as e:
@ -733,13 +724,12 @@ QtObject:
error "Can't find token ids to burn" error "Can't find token ids to burn"
return tokenIds return tokenIds
proc selfDestructCollectibles*(self: Service, communityId: string, password: string, walletAndAmounts: seq[WalletAndAmount], contractUniqueKey: string) = proc selfDestructCollectibles*(self: Service, communityId: string, password: string, walletAndAmounts: seq[WalletAndAmount], contractUniqueKey: string, addressFrom: string) =
try: try:
let contract = self.findContractByUniqueId(contractUniqueKey) let contract = self.findContractByUniqueId(contractUniqueKey)
let tokenIds = self.getTokensToBurn(walletAndAmounts, contract) let tokenIds = self.getTokensToBurn(walletAndAmounts, contract)
if len(tokenIds) == 0: if len(tokenIds) == 0:
return return
let addressFrom = contract.deployer
let txData = self.buildTransactionDataDto(addressFrom, contract.chainId, contract.address) let txData = self.buildTransactionDataDto(addressFrom, contract.chainId, contract.address)
debug "Remote destruct collectibles ", chainId=contract.chainId, address=contract.address, tokens=tokenIds debug "Remote destruct collectibles ", chainId=contract.chainId, address=contract.address, tokens=tokenIds
let response = tokens_backend.remoteBurn(contract.chainId, contract.address, %txData, password, tokenIds) let response = tokens_backend.remoteBurn(contract.chainId, contract.address, %txData, password, tokenIds)
@ -765,11 +755,9 @@ QtObject:
except Exception as e: except Exception as e:
error "Remote self destruct error", msg = e.msg error "Remote self destruct error", msg = e.msg
proc computeSelfDestructFee*(self: Service, walletAndAmountList: seq[WalletAndAmount], contractUniqueKey: string) = proc computeSelfDestructFee*(self: Service, walletAndAmountList: seq[WalletAndAmount], contractUniqueKey: string, addressFrom: string) =
try: try:
let contract = self.findContractByUniqueId(contractUniqueKey) let contract = self.findContractByUniqueId(contractUniqueKey)
self.tempAccountAddress = contract.deployer
self.tempChainId = contract.chainId
let tokenIds = self.getTokensToBurn(walletAndAmountList, contract) let tokenIds = self.getTokensToBurn(walletAndAmountList, contract)
if len(tokenIds) == 0: if len(tokenIds) == 0:
warn "token list is empty" warn "token list is empty"
@ -781,7 +769,7 @@ QtObject:
chainId: contract.chainId, chainId: contract.chainId,
contractAddress: contract.address, contractAddress: contract.address,
tokenIds: tokenIds, tokenIds: tokenIds,
addressFrom: contract.deployer addressFrom: addressFrom
) )
self.threadpool.start(arg) self.threadpool.start(arg)
except Exception as e: except Exception as e:
@ -803,10 +791,9 @@ QtObject:
errorCode = ComputeFeeErrorCode.Infura errorCode = ComputeFeeErrorCode.Infura
return errorCode return errorCode
proc burnTokens*(self: Service, communityId: string, password: string, contractUniqueKey: string, amount: Uint256) = proc burnTokens*(self: Service, communityId: string, password: string, contractUniqueKey: string, amount: Uint256, addressFrom: string) =
try: try:
var contract = self.findContractByUniqueId(contractUniqueKey) var contract = self.findContractByUniqueId(contractUniqueKey)
let addressFrom = contract.deployer
let txData = self.buildTransactionDataDto(addressFrom, contract.chainId, contract.address) let txData = self.buildTransactionDataDto(addressFrom, contract.chainId, contract.address)
debug "Burn tokens ", chainId=contract.chainId, address=contract.address, amount=amount debug "Burn tokens ", chainId=contract.chainId, address=contract.address, amount=amount
let response = tokens_backend.burn(contract.chainId, contract.address, %txData, password, amount) let response = tokens_backend.burn(contract.chainId, contract.address, %txData, password, amount)
@ -829,11 +816,9 @@ QtObject:
except Exception as e: except Exception as e:
error "Burn error", msg = e.msg error "Burn error", msg = e.msg
proc computeBurnFee*(self: Service, contractUniqueKey: string, amount: Uint256) = proc computeBurnFee*(self: Service, contractUniqueKey: string, amount: Uint256, addressFrom: string) =
try: try:
let contract = self.findContractByUniqueId(contractUniqueKey) let contract = self.findContractByUniqueId(contractUniqueKey)
self.tempAccountAddress = contract.deployer
self.tempChainId = contract.chainId
let arg = AsyncGetBurnFees( let arg = AsyncGetBurnFees(
tptr: cast[ByteAddress](asyncGetBurnFeesTask), tptr: cast[ByteAddress](asyncGetBurnFeesTask),
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),
@ -841,7 +826,7 @@ QtObject:
chainId: contract.chainId, chainId: contract.chainId,
contractAddress: contract.address, contractAddress: contract.address,
amount: amount, amount: amount,
addressFrom: contract.deployer addressFrom: addressFrom
) )
self.threadpool.start(arg) self.threadpool.start(arg)
except Exception as e: except Exception as e:
@ -911,14 +896,16 @@ QtObject:
return return
let gasTable = responseJson{"gasTable"}.toGasTable let gasTable = responseJson{"gasTable"}.toGasTable
let feeTable = responseJson{"feeTable"}.toFeeTable let feeTable = responseJson{"feeTable"}.toFeeTable
let chainId = responseJson{"chainId"}.getInt
let addressFrom = responseJson{"addressFrom"}.getStr
self.tempGasTable = gasTable self.tempGasTable = gasTable
self.tempFeeTable = feeTable self.tempFeeTable = feeTable
let gasUnits = toSeq(gasTable.values())[0] let gasUnits = toSeq(gasTable.values())[0]
let suggestedFees = toSeq(feeTable.values())[0] let suggestedFees = toSeq(feeTable.values())[0]
let data = self.createComputeFeeArgs(gasUnits, suggestedFees, self.tempChainId, self.tempAccountAddress) let data = self.createComputeFeeArgs(gasUnits, suggestedFees, chainId, addressFrom)
self.events.emit(signalName, data) self.events.emit(signalName, data)
except Exception: except Exception:
error "Error creating self destruct fee args", message = getCurrentExceptionMsg() error "Error creating fee args", message = getCurrentExceptionMsg()
let data = self.createComputeFeeArgsWithError(getCurrentExceptionMsg()) let data = self.createComputeFeeArgsWithError(getCurrentExceptionMsg())
self.events.emit(signalName, data) self.events.emit(signalName, data)
@ -958,6 +945,7 @@ QtObject:
let gasTable = responseJson{"gasTable"}.toGasTable let gasTable = responseJson{"gasTable"}.toGasTable
let feeTable = responseJson{"feeTable"}.toFeeTable let feeTable = responseJson{"feeTable"}.toFeeTable
let addressFrom = responseJson{"addressFrom"}.getStr
self.tempGasTable = gasTable self.tempGasTable = gasTable
self.tempFeeTable = feeTable self.tempFeeTable = feeTable
@ -967,8 +955,7 @@ QtObject:
let gasUnits = self.tempGasTable[(collectibleAndAmount.communityToken.chainId, collectibleAndAmount.communityToken.address)] let gasUnits = self.tempGasTable[(collectibleAndAmount.communityToken.chainId, collectibleAndAmount.communityToken.address)]
let suggestedFees = self.tempFeeTable[collectibleAndAmount.communityToken.chainId] let suggestedFees = self.tempFeeTable[collectibleAndAmount.communityToken.chainId]
let ethValue = self.computeEthValue(gasUnits, suggestedFees) let ethValue = self.computeEthValue(gasUnits, suggestedFees)
let walletAddress = collectibleAndAmount.communityToken.deployer wholeEthCostForChainWallet[(collectibleAndAmount.communityToken.chainId, addressFrom)] = wholeEthCostForChainWallet.getOrDefault((collectibleAndAmount.communityToken.chainId, addressFrom), 0.0) + ethValue
wholeEthCostForChainWallet[(collectibleAndAmount.communityToken.chainId, walletAddress)] = wholeEthCostForChainWallet.getOrDefault((collectibleAndAmount.communityToken.chainId, walletAddress), 0.0) + ethValue
ethValuesForContracts[(collectibleAndAmount.communityToken.chainId, collectibleAndAmount.communityToken.address)] = ethValue ethValuesForContracts[(collectibleAndAmount.communityToken.chainId, collectibleAndAmount.communityToken.address)] = ethValue
var totalEthVal = 0.0 var totalEthVal = 0.0
@ -978,9 +965,8 @@ QtObject:
let contractTuple = (chainId: collectibleAndAmount.communityToken.chainId, let contractTuple = (chainId: collectibleAndAmount.communityToken.chainId,
address: collectibleAndAmount.communityToken.address) address: collectibleAndAmount.communityToken.address)
let ethValue = ethValuesForContracts[contractTuple] let ethValue = ethValuesForContracts[contractTuple]
let walletAddress = collectibleAndAmount.communityToken.deployer var balance = self.getWalletBalanceForChain(addressFrom, contractTuple.chainId)
var balance = self.getWalletBalanceForChain(walletAddress, contractTuple.chainId) if balance < wholeEthCostForChainWallet[(contractTuple.chainId, addressFrom)]:
if balance < wholeEthCostForChainWallet[(contractTuple.chainId, walletAddress)]:
# if wallet balance for this chain is less than the whole cost # if wallet balance for this chain is less than the whole cost
# then we can't afford it; setting balance to 0.0 will set balance error code in Args # then we can't afford it; setting balance to 0.0 will set balance error code in Args
balance = 0.0 balance = 0.0

View File

@ -698,6 +698,7 @@ StackView {
onOpened: { onOpened: {
root.setFeeLoading() root.setFeeLoading()
signTransactionPopup.isRemotelyDestructTransaction signTransactionPopup.isRemotelyDestructTransaction
? root.remotelyDestructFeesRequest(footer.walletsAndAmounts, tokenKey, footer.accountAddress) ? root.remotelyDestructFeesRequest(footer.walletsAndAmounts, tokenKey, footer.accountAddress)
: root.signBurnTransactionOpened(tokenKey, footer.burnAmount, footer.accountAddress) : root.signBurnTransactionOpened(tokenKey, footer.burnAmount, footer.accountAddress)

View File

@ -118,38 +118,32 @@ QtObject {
* ] * ]
*/ */
function computeSelfDestructFee(walletsAndAmounts, tokenKey, accountAddress) { function computeSelfDestructFee(walletsAndAmounts, tokenKey, accountAddress) {
//TODO uncomment accountAddress when supported in backend communityTokensModuleInst.computeSelfDestructFee(JSON.stringify(walletsAndAmounts), tokenKey, accountAddress)
communityTokensModuleInst.computeSelfDestructFee(JSON.stringify(walletsAndAmounts), tokenKey, /*accountAddress*/)
} }
function remoteSelfDestructCollectibles(communityId, walletsAndAmounts, tokenKey, accountAddress) { function remoteSelfDestructCollectibles(communityId, walletsAndAmounts, tokenKey, accountAddress) {
//TODO uncomment accountAddress when supported in backend communityTokensModuleInst.selfDestructCollectibles(communityId, JSON.stringify(walletsAndAmounts), tokenKey, accountAddress)
communityTokensModuleInst.selfDestructCollectibles(communityId, JSON.stringify(walletsAndAmounts), tokenKey, /*accountAddress*/)
} }
// Burn: // Burn:
function computeBurnFee(tokenKey, amount, accountAddress) { function computeBurnFee(tokenKey, amount, accountAddress) {
console.assert(typeof amount === "string") console.assert(typeof amount === "string")
// TODO: Backend. It should include the account address in the calculation. communityTokensModuleInst.computeBurnFee(tokenKey, amount, accountAddress)
communityTokensModuleInst.computeBurnFee(tokenKey, amount/*, accountAddress*/)
} }
function burnToken(communityId, tokenKey, burnAmount, accountAddress) { function burnToken(communityId, tokenKey, burnAmount, accountAddress) {
console.assert(typeof burnAmount === "string") console.assert(typeof burnAmount === "string")
// TODO: Backend. It should include the account address in the burn action. communityTokensModuleInst.burnTokens(communityId, tokenKey, burnAmount, accountAddress)
communityTokensModuleInst.burnTokens(communityId, tokenKey, burnAmount/*, accountAddress*/)
} }
// Airdrop tokens: // Airdrop tokens:
function airdrop(communityId, airdropTokens, addresses, feeAccountAddress) { function airdrop(communityId, airdropTokens, addresses, feeAccountAddress) {
// TODO: Take `feeAccountAddress` into account for the airdrop communityTokensModuleInst.airdropTokens(communityId, JSON.stringify(airdropTokens), JSON.stringify(addresses), feeAccountAddress)
communityTokensModuleInst.airdropTokens(communityId, JSON.stringify(airdropTokens), JSON.stringify(addresses))
} }
function computeAirdropFee(communityId, contractKeysAndAmounts, addresses, feeAccountAddress) { function computeAirdropFee(communityId, contractKeysAndAmounts, addresses, feeAccountAddress) {
// TODO: Take `feeAccountAddress` into account when calculating fee
communityTokensModuleInst.computeAirdropFee( communityTokensModuleInst.computeAirdropFee(
communityId, JSON.stringify(contractKeysAndAmounts), communityId, JSON.stringify(contractKeysAndAmounts),
JSON.stringify(addresses)) JSON.stringify(addresses), feeAccountAddress)
} }
} }