Skip to content

Commit

Permalink
feat: Add hold token event for the EVM action - MEED-6663 - Meeds-io/…
Browse files Browse the repository at this point in the history
…MIPs#118 (#48)

This change will add some adjustments to the hold action.
  • Loading branch information
MayTekayaa committed Jun 14, 2024
1 parent ea85919 commit d65ceeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +50,9 @@ public class EvmRuleUpdateListener extends Listener<Map<String, String>, String>
@Autowired
private ListenerService listenerService;

@Autowired
private EventService eventService;

@PostConstruct
public void init() {
for (String eventName : SUPPORTED_EVENTS) {
Expand All @@ -64,9 +69,13 @@ public void onEvent(Event<Map<String, String>, String> event) throws ObjectNotFo
if (rule == null) {
throw new ObjectNotFoundException(String.format("Rule with id %s wasn't found", rule.getId()));
}
Map<String, String> map = rule.getEvent().getProperties();
map.put(Utils.LAST_ID_PROCCED, lastIdToSave.toString());
rule.getEvent().setProperties(map);
if (rule.getEvent() != null) {
Map<String, String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public List<RuleDTO> 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 {
Expand Down

0 comments on commit d65ceeb

Please sign in to comment.