Skip to content

Commit 8c8d23b

Browse files
author
Mateusz Czeladka
committed
feat: drep vote delegation available in network operations.
1 parent f6bf7c3 commit 8c8d23b

File tree

18 files changed

+688
-62
lines changed

18 files changed

+688
-62
lines changed

api/src/main/java/org/cardanofoundation/rosetta/api/block/mapper/TransactionMapper.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,21 @@ public interface TransactionMapper {
4747
@Mapping(target = "operationIdentifier", source = "index", qualifiedByName = "OperationIdentifier")
4848
Operation mapPoolRetirementToOperation(PoolRetirement model, OperationStatus status, int index);
4949

50-
StakePoolDelegation mapDelegationEntityToDelegation(DelegationEntity entity);
50+
@Mapping(source = "txHash", target = "txHash")
51+
@Mapping(source = "certIndex", target = "certIndex")
52+
@Mapping(source = "address", target = "address")
53+
@Mapping(source = "drepHash", target = "drep.drepId") // no this is not a mistake we don't have bech32 representation in rosetta
54+
@Mapping(source = "drepType", target = "drep.drepType", qualifiedByName = "convertYaciDrepType")
55+
DRepDelegation mapEntityToDRepDelegation(DrepVoteDelegationEntity entity);
56+
57+
@Mapping(source = "txHash", target = "txHash")
58+
@Mapping(source = "certIndex", target = "certIndex")
59+
@Mapping(source = "address", target = "address")
60+
@Mapping(source = "drep.drepId", target = "drepHash") // no this is not a mistake we don't have bech32 representation in rosetta
61+
@Mapping(source = "drep.drepType", target = "drepType", qualifiedByName = "convertClientDrepType")
62+
DrepVoteDelegationEntity mapDRepDelegationToEntity(DRepDelegation dRepDelegation);
63+
64+
StakePoolDelegation mapPoolDelegationEntityToDelegation(PoolDelegationEntity entity);
5165

5266
@Mapping(target = "status", source = "status.status")
5367
@Mapping(target = "type", constant = Constants.OPERATION_TYPE_STAKE_DELEGATION)
@@ -56,6 +70,50 @@ public interface TransactionMapper {
5670
@Mapping(target = "metadata.poolKeyHash", source = "model.poolId")
5771
Operation mapStakeDelegationToOperation(StakePoolDelegation model, OperationStatus status, int index);
5872

73+
default DRepDelegation mapDrepVoteDelegationEntityToDRepDelegation(DrepVoteDelegationEntity entity) {
74+
if (entity == null) {
75+
return null;
76+
}
77+
78+
return DRepDelegation.builder()
79+
.txHash(entity.getTxHash())
80+
.certIndex(entity.getCertIndex())
81+
.address(entity.getAddress())
82+
.drep(new DRepDelegation.DRep(
83+
entity.getDrepHash(),
84+
convertYaciDrepType(entity.getDrepType())
85+
))
86+
.build();
87+
}
88+
89+
@Named("convertYaciDrepType")
90+
default com.bloxbean.cardano.client.transaction.spec.governance.DRepType convertYaciDrepType(
91+
com.bloxbean.cardano.yaci.core.model.governance.DrepType yaciDrepType) {
92+
if (yaciDrepType == null) {
93+
return null;
94+
}
95+
return switch (yaciDrepType) {
96+
case ADDR_KEYHASH -> com.bloxbean.cardano.client.transaction.spec.governance.DRepType.ADDR_KEYHASH;
97+
case SCRIPTHASH -> com.bloxbean.cardano.client.transaction.spec.governance.DRepType.SCRIPTHASH;
98+
case ABSTAIN -> com.bloxbean.cardano.client.transaction.spec.governance.DRepType.ABSTAIN;
99+
case NO_CONFIDENCE -> com.bloxbean.cardano.client.transaction.spec.governance.DRepType.NO_CONFIDENCE;
100+
};
101+
}
102+
103+
@Named("convertClientDrepType")
104+
default com.bloxbean.cardano.yaci.core.model.governance.DrepType convertClientDrepType(
105+
com.bloxbean.cardano.client.transaction.spec.governance.DRepType clientDrepType) {
106+
if (clientDrepType == null) {
107+
return null;
108+
}
109+
return switch (clientDrepType) {
110+
case ADDR_KEYHASH -> com.bloxbean.cardano.yaci.core.model.governance.DrepType.ADDR_KEYHASH;
111+
case SCRIPTHASH -> com.bloxbean.cardano.yaci.core.model.governance.DrepType.SCRIPTHASH;
112+
case ABSTAIN -> com.bloxbean.cardano.yaci.core.model.governance.DrepType.ABSTAIN;
113+
case NO_CONFIDENCE -> com.bloxbean.cardano.yaci.core.model.governance.DrepType.NO_CONFIDENCE;
114+
};
115+
}
116+
59117
@Mapping(target = "status", source = "status.status")
60118
@Mapping(target = "type", constant = Constants.OPERATION_TYPE_DREP_VOTE_DELEGATION)
61119
@Mapping(target = "operationIdentifier", source = "index", qualifiedByName = "OperationIdentifier")

api/src/main/java/org/cardanofoundation/rosetta/api/block/mapper/TransactionMapperUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ public DRepParams convertDRepFromRosetta(DRepDelegation.DRep drep) {
8484
return DRepDelegation.DRep.convertDRepFromRosetta(drep);
8585
}
8686

87+
@Named("convertDrepTypeStringToEnum")
88+
public com.bloxbean.cardano.client.transaction.spec.governance.DRepType convertDrepTypeStringToEnum(@Nullable String drepType) {
89+
if (drepType == null) {
90+
return null;
91+
}
92+
93+
return switch (drepType) {
94+
case "ADDR_KEYHASH" -> com.bloxbean.cardano.client.transaction.spec.governance.DRepType.ADDR_KEYHASH;
95+
case "SCRIPTHASH" -> com.bloxbean.cardano.client.transaction.spec.governance.DRepType.SCRIPTHASH;
96+
case "ABSTAIN" -> com.bloxbean.cardano.client.transaction.spec.governance.DRepType.ABSTAIN;
97+
case "NO_CONFIDENCE" -> com.bloxbean.cardano.client.transaction.spec.governance.DRepType.NO_CONFIDENCE;
98+
default -> null;
99+
};
100+
}
101+
87102
@Named("mapAmountsToOperationMetadataInputWithCache")
88103
public OperationMetadata mapToOperationMetaDataInputWithCache(List<Amt> amounts,
89104
@Context Map<AssetFingerprint, TokenRegistryCurrencyData> metadataMap) {

api/src/main/java/org/cardanofoundation/rosetta/api/block/model/domain/DRepDelegation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@Builder
1111
@NoArgsConstructor
1212
@AllArgsConstructor
13+
@Setter
1314
public class DRepDelegation {
1415

1516
private String txHash;
@@ -20,6 +21,7 @@ public class DRepDelegation {
2021
@AllArgsConstructor
2122
@NoArgsConstructor
2223
@Getter
24+
@Setter
2325
public static class DRep {
2426

2527
private String drepId;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.cardanofoundation.rosetta.api.block.model.entity;
2+
3+
import com.bloxbean.cardano.yaci.core.model.certs.StakeCredType;
4+
import com.bloxbean.cardano.yaci.core.model.governance.DrepType;
5+
import jakarta.persistence.*;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Getter;
8+
import lombok.NoArgsConstructor;
9+
import lombok.Setter;
10+
11+
import java.time.LocalDateTime;
12+
13+
@Getter
14+
@Setter
15+
@NoArgsConstructor
16+
@AllArgsConstructor
17+
@Entity
18+
@Table(name = "delegation_vote")
19+
@IdClass(DrepVoteDelegationId.class)
20+
public class DrepVoteDelegationEntity {
21+
22+
@jakarta.persistence.Id
23+
@Column(name = "tx_hash")
24+
private String txHash;
25+
26+
@jakarta.persistence.Id
27+
@Column(name = "cert_index")
28+
private long certIndex;
29+
30+
@Column(name = "slot")
31+
private Long slot;
32+
33+
@Column(name = "block")
34+
private Long blockNumber;
35+
36+
@Column(name = "block_time")
37+
private Long blockTime;
38+
39+
@Column(name = "update_datetime")
40+
private LocalDateTime updateDateTime;
41+
42+
@Column(name = "address")
43+
private String address;
44+
45+
@Column(name = "drep_hash") // actual drep id as hex hash
46+
private String drepHash;
47+
48+
@Column(name = "drep_id") // bech 32
49+
private String drepId;
50+
51+
@Column(name = "drep_type")
52+
@Enumerated(EnumType.STRING)
53+
private DrepType drepType;
54+
55+
@Column(name = "credential")
56+
private String credential;
57+
58+
@Column(name = "cred_type")
59+
@Enumerated(EnumType.STRING)
60+
private StakeCredType credType;
61+
62+
@Column(name = "epoch")
63+
private Integer epoch;
64+
65+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.cardanofoundation.rosetta.api.block.model.entity;
2+
3+
import jakarta.persistence.Column;
4+
import lombok.EqualsAndHashCode;
5+
6+
import java.io.Serializable;
7+
8+
@EqualsAndHashCode
9+
public class DrepVoteDelegationId implements Serializable {
10+
11+
@Column(name = "tx_hash")
12+
private String txHash;
13+
14+
@Column(name = "cert_index")
15+
private long certIndex;
16+
17+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
@NoArgsConstructor
1212
@Entity
1313
@Table(name = "delegation")
14-
@IdClass(DelegationId.class)
15-
public class DelegationEntity {
14+
@IdClass(PoolDelegationId.class)
15+
public class PoolDelegationEntity {
1616

1717
@Id
1818
@Column(name = "tx_hash")

api/src/main/java/org/cardanofoundation/rosetta/api/block/model/entity/DelegationId.java renamed to api/src/main/java/org/cardanofoundation/rosetta/api/block/model/entity/PoolDelegationId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import lombok.EqualsAndHashCode;
66

77
@EqualsAndHashCode
8-
public class DelegationId implements Serializable {
8+
public class PoolDelegationId implements Serializable {
99

1010
private String txHash;
1111
private long certIndex;

api/src/main/java/org/cardanofoundation/rosetta/api/block/model/repository/DelegationRepository.java

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.cardanofoundation.rosetta.api.block.model.repository;
2+
3+
import java.util.List;
4+
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.stereotype.Repository;
7+
8+
import org.cardanofoundation.rosetta.api.block.model.entity.DrepVoteDelegationEntity;
9+
import org.cardanofoundation.rosetta.api.block.model.entity.DrepVoteDelegationId;
10+
11+
@Repository
12+
public interface DrepVoteDelegationRepository extends JpaRepository<DrepVoteDelegationEntity, DrepVoteDelegationId> {
13+
14+
List<DrepVoteDelegationEntity> findByTxHashInAndCertIndex(List<String> txHashes, long certIndex);
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.cardanofoundation.rosetta.api.block.model.repository;
2+
3+
import java.util.List;
4+
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.stereotype.Repository;
7+
8+
import org.cardanofoundation.rosetta.api.block.model.entity.PoolDelegationEntity;
9+
import org.cardanofoundation.rosetta.api.block.model.entity.PoolDelegationId;
10+
11+
@Repository
12+
public interface PoolDelegationRepository extends JpaRepository<PoolDelegationEntity, PoolDelegationId> {
13+
14+
List<PoolDelegationEntity> findByTxHashIn(List<String> txHashes);
15+
16+
}

0 commit comments

Comments
 (0)