From d65ceeb1e91fe34167879ec48137ae6d21b3e97e Mon Sep 17 00:00:00 2001 From: MayTekayaa <100131287+MayTekayaa@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:09:51 +0100 Subject: [PATCH] feat: Add hold token event for the EVM action - MEED-6663 - Meeds-io/MIPs#118 (#48) This change will add some adjustments to the hold action. --- .../listener/EvmRuleUpdateListener.java | 15 ++++++++++++--- .../service/EvmContractTransferService.java | 6 +++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gamification-evm-services/src/main/java/io/meeds/evm/gamification/listener/EvmRuleUpdateListener.java b/gamification-evm-services/src/main/java/io/meeds/evm/gamification/listener/EvmRuleUpdateListener.java index 65e7e42..a7aa512 100644 --- a/gamification-evm-services/src/main/java/io/meeds/evm/gamification/listener/EvmRuleUpdateListener.java +++ b/gamification-evm-services/src/main/java/io/meeds/evm/gamification/listener/EvmRuleUpdateListener.java @@ -19,7 +19,9 @@ package io.meeds.evm.gamification.listener; import io.meeds.evm.gamification.utils.Utils; +import io.meeds.gamification.model.EventDTO; import io.meeds.gamification.model.RuleDTO; +import io.meeds.gamification.service.EventService; import io.meeds.gamification.service.RuleService; import jakarta.annotation.PostConstruct; import org.exoplatform.commons.api.persistence.ExoTransactional; @@ -48,6 +50,9 @@ public class EvmRuleUpdateListener extends Listener, String> @Autowired private ListenerService listenerService; + @Autowired + private EventService eventService; + @PostConstruct public void init() { for (String eventName : SUPPORTED_EVENTS) { @@ -64,9 +69,13 @@ public void onEvent(Event, String> event) throws ObjectNotFo if (rule == null) { throw new ObjectNotFoundException(String.format("Rule with id %s wasn't found", rule.getId())); } - Map map = rule.getEvent().getProperties(); - map.put(Utils.LAST_ID_PROCCED, lastIdToSave.toString()); - rule.getEvent().setProperties(map); + if (rule.getEvent() != null) { + Map map = rule.getEvent().getProperties(); + map.put(Utils.LAST_ID_PROCCED, lastIdToSave.toString()); + rule.getEvent().setProperties(map); + EventDTO eventDTO = eventService.updateEvent(rule.getEvent()); + rule.setEvent(eventDTO); + } ruleService.updateRule(rule); } } diff --git a/gamification-evm-services/src/main/java/io/meeds/evm/gamification/service/EvmContractTransferService.java b/gamification-evm-services/src/main/java/io/meeds/evm/gamification/service/EvmContractTransferService.java index 32fa218..cb0c251 100644 --- a/gamification-evm-services/src/main/java/io/meeds/evm/gamification/service/EvmContractTransferService.java +++ b/gamification-evm-services/src/main/java/io/meeds/evm/gamification/service/EvmContractTransferService.java @@ -82,9 +82,9 @@ public List getFilteredEVMRules() { private Long getLastIdProcced(RuleDTO rule, String contractAddress, Long networkId) { Long lastIdProcced = 0l; if (StringUtils.isBlank(rule.getEvent().getProperties().get(Utils.LAST_ID_PROCCED))) { - if (evmTransactionService.getTransactionByContractAddressAndNetworkIdOrderByIdDesc(contractAddress, networkId) != null) { - lastIdProcced = evmTransactionService.getTransactionByContractAddressAndNetworkIdOrderByIdDesc(contractAddress, networkId) - .getId(); + EvmTransaction lastTransaction = evmTransactionService.getTransactionByContractAddressAndNetworkIdOrderByIdDesc(contractAddress, networkId); + if (lastTransaction != null) { + lastIdProcced = lastTransaction.getId(); } broadcastEvmActionEvent(lastIdProcced.toString(), rule.getId().toString()); } else {