parent
57425e77bd
commit
3e550bf9a5
|
@ -0,0 +1,29 @@
|
||||||
|
import json
|
||||||
|
include ../../common/json_utils
|
||||||
|
|
||||||
|
type
|
||||||
|
AirdropDetails* = object
|
||||||
|
chainId*: int
|
||||||
|
contractAddress*: string
|
||||||
|
walletAddresses*: seq[string]
|
||||||
|
amount*: int
|
||||||
|
|
||||||
|
proc toJsonNode*(self: AirdropDetails): JsonNode =
|
||||||
|
result = %* {
|
||||||
|
"chainId": self.chainId,
|
||||||
|
"contractAddress": self.contractAddress,
|
||||||
|
"walletAddresses": self.walletAddresses,
|
||||||
|
"amount": self.amount
|
||||||
|
}
|
||||||
|
|
||||||
|
proc toAirdropDetails*(jsonObj: JsonNode): AirdropDetails =
|
||||||
|
result = AirdropDetails()
|
||||||
|
discard jsonObj.getProp("chainId", result.chainId)
|
||||||
|
discard jsonObj.getProp("contractAddress", result.contractAddress)
|
||||||
|
|
||||||
|
var walletsObj: JsonNode
|
||||||
|
if(jsonObj.getProp("walletAddresses", walletsObj) and walletsObj.kind == JArray):
|
||||||
|
for walletAddr in walletsObj:
|
||||||
|
result.walletAddresses.add(walletAddr.getStr)
|
||||||
|
|
||||||
|
discard jsonObj.getProp("amount", result.amount)
|
|
@ -1,4 +1,4 @@
|
||||||
import json, json, sequtils
|
import json, sequtils
|
||||||
import ../../../../backend/response_type
|
import ../../../../backend/response_type
|
||||||
include ../../../common/json_utils
|
include ../../../common/json_utils
|
||||||
import ../../../common/conversion
|
import ../../../common/conversion
|
||||||
|
|
|
@ -18,6 +18,8 @@ import ../community/dto/community
|
||||||
|
|
||||||
import ./dto/deployment_parameters
|
import ./dto/deployment_parameters
|
||||||
import ./dto/community_token
|
import ./dto/community_token
|
||||||
|
import ./airdrop_details
|
||||||
|
|
||||||
include async_tasks
|
include async_tasks
|
||||||
|
|
||||||
export community_token
|
export community_token
|
||||||
|
@ -105,6 +107,19 @@ QtObject:
|
||||||
let data = CommunityTokenDeployedStatusArgs(communityId: tokenDto.communityId, contractAddress: tokenDto.address, deployState: deployState)
|
let data = CommunityTokenDeployedStatusArgs(communityId: tokenDto.communityId, contractAddress: tokenDto.address, deployState: deployState)
|
||||||
self.events.emit(SIGNAL_COMMUNITY_TOKEN_DEPLOY_STATUS, data)
|
self.events.emit(SIGNAL_COMMUNITY_TOKEN_DEPLOY_STATUS, data)
|
||||||
|
|
||||||
|
self.events.on(PendingTransactionTypeDto.CollectibleAirdrop.event) do(e: Args):
|
||||||
|
var receivedData = TransactionMinedArgs(e)
|
||||||
|
let airdropDetails = toAirdropDetails(parseJson(receivedData.data))
|
||||||
|
if not receivedData.success:
|
||||||
|
error "Collectible airdrop failed", contractAddress=airdropDetails.contractAddress
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
# add holders to db
|
||||||
|
discard addTokenOwners(airdropDetails.chainId, airdropDetails.contractAddress,
|
||||||
|
airdropDetails.walletAddresses, airdropDetails.amount)
|
||||||
|
except RpcException:
|
||||||
|
error "Error adding collectible token owners", message = getCurrentExceptionMsg()
|
||||||
|
|
||||||
proc deployCollectiblesEstimate*(self: Service): int =
|
proc deployCollectiblesEstimate*(self: Service): int =
|
||||||
try:
|
try:
|
||||||
let response = tokens_backend.deployCollectiblesEstimate()
|
let response = tokens_backend.deployCollectiblesEstimate()
|
||||||
|
@ -129,8 +144,8 @@ QtObject:
|
||||||
let response = tokens_backend.deployCollectibles(chainId, %deploymentParams, %txData, password)
|
let response = tokens_backend.deployCollectibles(chainId, %deploymentParams, %txData, password)
|
||||||
let contractAddress = response.result["contractAddress"].getStr()
|
let contractAddress = response.result["contractAddress"].getStr()
|
||||||
let transactionHash = response.result["transactionHash"].getStr()
|
let transactionHash = response.result["transactionHash"].getStr()
|
||||||
echo "!!! Contract address ", contractAddress
|
debug "Deployed contract address ", contractAddress=contractAddress
|
||||||
echo "!!! Transaction hash ", transactionHash
|
debug "Deployment transaction hash ", transactionHash=transactionHash
|
||||||
|
|
||||||
var communityToken: CommunityTokenDto
|
var communityToken: CommunityTokenDto
|
||||||
communityToken.tokenType = TokenType.ERC721
|
communityToken.tokenType = TokenType.ERC721
|
||||||
|
@ -193,7 +208,24 @@ QtObject:
|
||||||
let addressFrom = self.contractOwner(collectibleAndAmount.communityToken.chainId, collectibleAndAmount.communityToken.address)
|
let addressFrom = self.contractOwner(collectibleAndAmount.communityToken.chainId, collectibleAndAmount.communityToken.address)
|
||||||
let txData = TransactionDataDto(source: parseAddress(addressFrom)) #TODO estimate fee in UI
|
let txData = TransactionDataDto(source: parseAddress(addressFrom)) #TODO estimate fee in UI
|
||||||
let response = tokens_backend.mintTo(collectibleAndAmount.communityToken.chainId, collectibleAndAmount.communityToken.address, %txData, password, walletAddresses, collectibleAndAmount.amount)
|
let response = tokens_backend.mintTo(collectibleAndAmount.communityToken.chainId, collectibleAndAmount.communityToken.address, %txData, password, walletAddresses, collectibleAndAmount.amount)
|
||||||
echo "!!! Transaction hash ", response.result.getStr()
|
let transactionHash = response.result.getStr()
|
||||||
|
debug "Deployment transaction hash ", transactionHash=transactionHash
|
||||||
|
|
||||||
|
let airdropDetails = AirdropDetails(
|
||||||
|
chainId: collectibleAndAmount.communityToken.chainId,
|
||||||
|
contractAddress: collectibleAndAmount.communityToken.address,
|
||||||
|
walletAddresses: walletAddresses,
|
||||||
|
amount: collectibleAndAmount.amount)
|
||||||
|
|
||||||
|
# observe transaction state
|
||||||
|
self.transactionService.watchTransaction(
|
||||||
|
transactionHash,
|
||||||
|
addressFrom,
|
||||||
|
collectibleAndAmount.communityToken.address,
|
||||||
|
$PendingTransactionTypeDto.CollectibleAirdrop,
|
||||||
|
$airdropDetails.toJsonNode(),
|
||||||
|
collectibleAndAmount.communityToken.chainId,
|
||||||
|
)
|
||||||
except RpcException:
|
except RpcException:
|
||||||
error "Error minting collectibles", message = getCurrentExceptionMsg()
|
error "Error minting collectibles", message = getCurrentExceptionMsg()
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ type
|
||||||
BuyStickerPack = "BuyStickerPack"
|
BuyStickerPack = "BuyStickerPack"
|
||||||
WalletTransfer = "WalletTransfer"
|
WalletTransfer = "WalletTransfer"
|
||||||
CollectibleDeployment = "CollectibleDeployment"
|
CollectibleDeployment = "CollectibleDeployment"
|
||||||
|
CollectibleAirdrop = "CollectibleAirdrop"
|
||||||
|
|
||||||
proc event*(self:PendingTransactionTypeDto):string =
|
proc event*(self:PendingTransactionTypeDto):string =
|
||||||
result = "transaction:" & $self
|
result = "transaction:" & $self
|
||||||
|
|
|
@ -31,3 +31,7 @@ proc contractOwner*(chainId: int, contractAddress: string): RpcResponse[JsonNode
|
||||||
proc deployCollectiblesEstimate*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
proc deployCollectiblesEstimate*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
let payload = %*[]
|
let payload = %*[]
|
||||||
return core.callPrivateRPC("collectibles_deployCollectiblesEstimate", payload)
|
return core.callPrivateRPC("collectibles_deployCollectiblesEstimate", payload)
|
||||||
|
|
||||||
|
proc addTokenOwners*(chainId: int, contractAddress: string, walletAddresses: seq[string], amount: int): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
|
let payload = %* [chainId, contractAddress, walletAddresses, amount]
|
||||||
|
return core.callPrivateRPC("collectibles_addTokenOwners", payload)
|
||||||
|
|
Loading…
Reference in New Issue