Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle new certs in conway era #95

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.cardanofoundation.ledgersync.explorerconsumer.factory;

import com.bloxbean.cardano.yaci.core.model.certs.Certificate;
import com.bloxbean.cardano.yaci.core.model.certs.*;
import jakarta.annotation.PostConstruct;
import org.cardanofoundation.explorer.consumercommon.entity.Delegation;
import org.cardanofoundation.explorer.consumercommon.entity.Redeemer;
import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress;
import org.cardanofoundation.explorer.consumercommon.entity.Tx;
import org.cardanofoundation.ledgersync.explorerconsumer.aggregate.AggregatedBlock;
import org.cardanofoundation.ledgersync.explorerconsumer.service.CertificateSyncService;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
Expand Down Expand Up @@ -38,13 +40,12 @@ void init() {
public void handle(AggregatedBlock aggregatedBlock,
Certificate certificate, int certificateIdx, Tx tx, Redeemer redeemer,
Map<String, StakeAddress> stakeAddressMap) {
//TODO: This will happen for new certificates types introduced in Conway era
if (serviceMap.get(certificate.getClass()) == null) {
return;
} else {
serviceMap.get(certificate.getClass()).handle(
aggregatedBlock, certificate, certificateIdx, tx,
redeemer, stakeAddressMap);
}
serviceMap.get(certificate.getClass()).handle(
aggregatedBlock, certificate, certificateIdx, tx,
redeemer, stakeAddressMap);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,36 @@ private void mapCertificateStakeAddressToTxHash(
blockDataService.saveFirstAppearedTxHashForStakeAddress(stakeAddressHex, txHash);
});
break;
case REG_CERT:
RegCert regCert = (RegCert) certificate;
blockDataService.saveFirstAppearedTxHashForStakeAddress(AddressUtil
.getRewardAddressString(regCert.getStakeCredential(), network), txHash);
break;
case UNREG_CERT:
UnregCert unregCert = (UnregCert) certificate;
blockDataService.saveFirstAppearedTxHashForStakeAddress(AddressUtil
.getRewardAddressString(unregCert.getStakeCredential(), network), txHash);
break;
case STAKE_REG_DELEG_CERT:
StakeRegDelegCert stakeRegDelegCert = (StakeRegDelegCert) certificate;
blockDataService.saveFirstAppearedTxHashForStakeAddress(AddressUtil
.getRewardAddressString(stakeRegDelegCert.getStakeCredential(), network), txHash);
break;
case STAKE_VOTE_DELEG_CERT:
StakeVoteDelegCert stakeVoteDelegCert = (StakeVoteDelegCert) certificate;
blockDataService.saveFirstAppearedTxHashForStakeAddress(AddressUtil
.getRewardAddressString(stakeVoteDelegCert.getStakeCredential(), network), txHash);
break;
case VOTE_REG_DELEG_CERT:
VoteRegDelegCert voteRegDelegCert = (VoteRegDelegCert) certificate;
blockDataService.saveFirstAppearedTxHashForStakeAddress(AddressUtil
.getRewardAddressString(voteRegDelegCert.getStakeCredential(), network), txHash);
break;
case STAKE_VOTE_REG_DELEG_CERT:
StakeVoteRegDelegCert stakeVoteRegDelegCert = (StakeVoteRegDelegCert) certificate;
blockDataService.saveFirstAppearedTxHashForStakeAddress(AddressUtil
.getRewardAddressString(stakeVoteRegDelegCert.getStakeCredential(), network), txHash);
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.cardanofoundation.ledgersync.explorerconsumer.service.impl.certificate;

import com.bloxbean.cardano.yaci.core.model.certs.RegCert;
import com.bloxbean.cardano.yaci.core.model.certs.StakeRegistration;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.cardanofoundation.explorer.consumercommon.entity.Redeemer;
import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress;
import org.cardanofoundation.explorer.consumercommon.entity.Tx;
import org.cardanofoundation.ledgersync.explorerconsumer.aggregate.AggregatedBlock;
import org.cardanofoundation.ledgersync.explorerconsumer.service.CertificateSyncService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@Slf4j
public class RegCertServiceImpl extends CertificateSyncService<RegCert> {
StakeRegistrationServiceImpl stakeRegistrationService;

@Override
public void handle(AggregatedBlock aggregatedBlock,
RegCert certificate, int certificateIdx, Tx tx, Redeemer redeemer,
Map<String, StakeAddress> stakeAddressMap) {
var stakeRegistration = StakeRegistration.builder().stakeCredential(certificate.getStakeCredential()).build();

stakeRegistrationService.handle(aggregatedBlock, stakeRegistration, certificateIdx, tx, redeemer, stakeAddressMap);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.cardanofoundation.ledgersync.explorerconsumer.service.impl.certificate;

import com.bloxbean.cardano.yaci.core.model.certs.*;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.cardanofoundation.explorer.consumercommon.entity.Redeemer;
import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress;
import org.cardanofoundation.explorer.consumercommon.entity.Tx;
import org.cardanofoundation.ledgersync.explorerconsumer.aggregate.AggregatedBlock;
import org.cardanofoundation.ledgersync.explorerconsumer.service.CertificateSyncService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@Slf4j
public class StakeRegDelegCertServiceImpl extends CertificateSyncService<StakeRegDelegCert> {

StakeDelegationServiceImpl stakeDelegationService;
StakeRegistrationServiceImpl stakeRegistrationService;

@Override
public void handle(AggregatedBlock aggregatedBlock, StakeRegDelegCert certificate, int certificateIdx,
Tx tx, Redeemer redeemer, Map<String, StakeAddress> stakeAddressMap) {
var stakeDelegation = StakeDelegation.builder().stakeCredential(certificate.getStakeCredential())
.stakePoolId(StakePoolId
.builder()
.poolKeyHash(certificate.getPoolKeyHash())
.build()).build();
var stakeRegistration = StakeRegistration.builder().stakeCredential(certificate.getStakeCredential()).build();

stakeDelegationService.handle(aggregatedBlock, stakeDelegation, certificateIdx, tx, redeemer, stakeAddressMap);
stakeRegistrationService.handle(aggregatedBlock, stakeRegistration, certificateIdx, tx, redeemer, stakeAddressMap);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.cardanofoundation.ledgersync.explorerconsumer.service.impl.certificate;

import com.bloxbean.cardano.yaci.core.model.certs.StakeDelegation;
import com.bloxbean.cardano.yaci.core.model.certs.StakePoolId;
import com.bloxbean.cardano.yaci.core.model.certs.StakeVoteDelegCert;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.cardanofoundation.explorer.consumercommon.entity.Redeemer;
import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress;
import org.cardanofoundation.explorer.consumercommon.entity.Tx;
import org.cardanofoundation.ledgersync.explorerconsumer.aggregate.AggregatedBlock;
import org.cardanofoundation.ledgersync.explorerconsumer.service.CertificateSyncService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@Slf4j
public class StakeVoteDelegCertServiceImpl extends CertificateSyncService<StakeVoteDelegCert> {

StakeDelegationServiceImpl stakeDelegationService;

@Override
public void handle(AggregatedBlock aggregatedBlock, StakeVoteDelegCert certificate, int certificateIdx, Tx tx,
Redeemer redeemer, Map<String, StakeAddress> stakeAddressMap) {
var stakeDelegation = StakeDelegation.builder().stakeCredential(certificate.getStakeCredential())
.stakePoolId(StakePoolId
.builder()
.poolKeyHash(certificate.getPoolKeyHash())
.build())
.build();

stakeDelegationService.handle(aggregatedBlock, stakeDelegation, certificateIdx, tx, redeemer, stakeAddressMap);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.cardanofoundation.ledgersync.explorerconsumer.service.impl.certificate;

import com.bloxbean.cardano.yaci.core.model.certs.StakeDelegation;
import com.bloxbean.cardano.yaci.core.model.certs.StakePoolId;
import com.bloxbean.cardano.yaci.core.model.certs.StakeRegistration;
import com.bloxbean.cardano.yaci.core.model.certs.StakeVoteRegDelegCert;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.cardanofoundation.explorer.consumercommon.entity.Redeemer;
import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress;
import org.cardanofoundation.explorer.consumercommon.entity.Tx;
import org.cardanofoundation.ledgersync.explorerconsumer.aggregate.AggregatedBlock;
import org.cardanofoundation.ledgersync.explorerconsumer.service.CertificateSyncService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@Slf4j
public class StakeVoteRegDelegCertServiceImpl extends CertificateSyncService<StakeVoteRegDelegCert> {

StakeDelegationServiceImpl stakeDelegationService;
StakeRegistrationServiceImpl stakeRegistrationService;

@Override
public void handle(AggregatedBlock aggregatedBlock, StakeVoteRegDelegCert certificate, int certificateIdx, Tx tx,
Redeemer redeemer, Map<String, StakeAddress> stakeAddressMap) {
var stakeRegistration = StakeRegistration.builder().stakeCredential(certificate.getStakeCredential()).build();
var stakeDelegation = StakeDelegation.builder().stakeCredential(certificate.getStakeCredential())
.stakePoolId(StakePoolId
.builder()
.poolKeyHash(certificate.getPoolKeyHash())
.build()).build();

stakeRegistrationService.handle(aggregatedBlock, stakeRegistration, certificateIdx, tx, redeemer, stakeAddressMap);
stakeDelegationService.handle(aggregatedBlock, stakeDelegation, certificateIdx, tx, redeemer, stakeAddressMap);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.cardanofoundation.ledgersync.explorerconsumer.service.impl.certificate;

import com.bloxbean.cardano.yaci.core.model.certs.StakeDeregistration;
import com.bloxbean.cardano.yaci.core.model.certs.UnregCert;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.cardanofoundation.explorer.consumercommon.entity.Redeemer;
import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress;
import org.cardanofoundation.explorer.consumercommon.entity.Tx;
import org.cardanofoundation.ledgersync.explorerconsumer.aggregate.AggregatedBlock;
import org.cardanofoundation.ledgersync.explorerconsumer.service.CertificateSyncService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@Slf4j
public class UnregCertServiceImpl extends CertificateSyncService<UnregCert> {

StakeDeregistrationServiceImpl stakeDeregistrationService;

@Override
public void handle(AggregatedBlock aggregatedBlock, UnregCert certificate, int certificateIdx, Tx tx,
Redeemer redeemer, Map<String, StakeAddress> stakeAddressMap) {
var stakeDerigistration = StakeDeregistration.builder().stakeCredential(certificate.getStakeCredential()).build();

stakeDeregistrationService.handle(aggregatedBlock, stakeDerigistration, certificateIdx, tx, redeemer, stakeAddressMap);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.cardanofoundation.ledgersync.explorerconsumer.service.impl.certificate;

import com.bloxbean.cardano.yaci.core.model.certs.StakeRegistration;
import com.bloxbean.cardano.yaci.core.model.certs.VoteRegDelegCert;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.cardanofoundation.explorer.consumercommon.entity.Redeemer;
import org.cardanofoundation.explorer.consumercommon.entity.StakeAddress;
import org.cardanofoundation.explorer.consumercommon.entity.Tx;
import org.cardanofoundation.ledgersync.explorerconsumer.aggregate.AggregatedBlock;
import org.cardanofoundation.ledgersync.explorerconsumer.service.CertificateSyncService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@Slf4j
public class VoteRegDelegCertServiceImpl extends CertificateSyncService<VoteRegDelegCert> {

StakeRegistrationServiceImpl stakeRegistrationService;

@Override
public void handle(AggregatedBlock aggregatedBlock, VoteRegDelegCert certificate, int certificateIdx, Tx tx,
Redeemer redeemer, Map<String, StakeAddress> stakeAddressMap) {
var stakeRegistration = StakeRegistration.builder().stakeCredential(certificate.getStakeCredential()).build();

stakeRegistrationService.handle(aggregatedBlock, stakeRegistration, certificateIdx, tx, redeemer, stakeAddressMap);
}
}
Loading