-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/ra 58 add withdraws to transactions (#118)
* feat: Initial Implementation for adding withdrawals to Transactions. * fix: merged main, generated new testdata due to yaci changes * fix: added tests, renamed class due to typo
- Loading branch information
Showing
25 changed files
with
351 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ain/java/org/cardanofoundation/rosetta/api/block/mapper/WithdrawalEntityToWithdrawal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.cardanofoundation.rosetta.api.block.mapper; | ||
|
||
import java.util.Optional; | ||
import lombok.AllArgsConstructor; | ||
import org.cardanofoundation.rosetta.api.block.model.domain.Withdrawal; | ||
import org.cardanofoundation.rosetta.api.block.model.entity.WithdrawalEntity; | ||
import org.cardanofoundation.rosetta.common.annotation.OpenApiMapper; | ||
import org.modelmapper.ModelMapper; | ||
|
||
@OpenApiMapper | ||
@AllArgsConstructor | ||
public class WithdrawalEntityToWithdrawal { | ||
|
||
private final ModelMapper modelMapper; | ||
|
||
public Withdrawal fromEntity(WithdrawalEntity model) { | ||
return Optional | ||
.ofNullable(modelMapper.getTypeMap(WithdrawalEntity.class, Withdrawal.class)) | ||
.orElseGet(() -> modelMapper.createTypeMap(WithdrawalEntity.class, Withdrawal.class)) | ||
.addMappings(mp -> { | ||
mp.map(WithdrawalEntity::getAddress, Withdrawal::setStakeAddress); | ||
}) | ||
.map(model); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
api/src/main/java/org/cardanofoundation/rosetta/api/block/mapper/WithdrawalToOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.cardanofoundation.rosetta.api.block.mapper; | ||
|
||
import java.util.Optional; | ||
import lombok.AllArgsConstructor; | ||
import org.cardanofoundation.rosetta.api.block.model.domain.Withdrawal; | ||
import org.cardanofoundation.rosetta.common.annotation.OpenApiMapper; | ||
import org.cardanofoundation.rosetta.common.enumeration.OperationType; | ||
import org.modelmapper.ModelMapper; | ||
import org.modelmapper.spi.MappingContext; | ||
import org.openapitools.client.model.Amount; | ||
import org.openapitools.client.model.Operation; | ||
import org.openapitools.client.model.OperationStatus; | ||
|
||
@OpenApiMapper | ||
@AllArgsConstructor | ||
public class WithdrawalToOperation extends AbstractToOperation<Withdrawal>{ | ||
|
||
private final ModelMapper modelMapper; | ||
|
||
@Override | ||
public Operation toDto(Withdrawal model, OperationStatus status, int index) { | ||
return Optional | ||
.ofNullable(modelMapper.getTypeMap(Withdrawal.class, Operation.class)) | ||
.orElseGet(() -> modelMapper.createTypeMap(Withdrawal.class, Operation.class)) | ||
.addMappings(mp -> { | ||
mp.map(f -> status.getStatus(), Operation::setStatus); | ||
mp.map(f -> OperationType.WITHDRAWAL.getValue(), Operation::setType); | ||
mp.<String>map(Withdrawal::getStakeAddress, (d, v) -> d.getAccount().setAddress(v)); | ||
mp.<Amount>map(f -> getDepositAmount("-" + f.getAmount()), (d, v) -> d.getMetadata().setWithdrawalAmount(v)); | ||
mp.<Long>map(f -> index, (d, v) -> d.getOperationIdentifier().setIndex(v)); | ||
}) | ||
.setPostConverter(MappingContext::getDestination) | ||
.map(model); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
api/src/main/java/org/cardanofoundation/rosetta/api/block/model/domain/Withdrawal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.cardanofoundation.rosetta.api.block.model.domain; | ||
|
||
import java.math.BigInteger; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.cardanofoundation.rosetta.api.block.model.entity.WithdrawalEntity; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Withdrawal { | ||
private String stakeAddress; | ||
private BigInteger amount; | ||
} |
39 changes: 39 additions & 0 deletions
39
api/src/main/java/org/cardanofoundation/rosetta/api/block/model/entity/WithdrawalEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.cardanofoundation.rosetta.api.block.model.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.IdClass; | ||
import jakarta.persistence.Table; | ||
import java.math.BigInteger; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@SuperBuilder | ||
@Entity | ||
@Table(name = "withdrawal") | ||
@IdClass(WithdrawalId.class) | ||
public class WithdrawalEntity extends BlockAwareEntity { | ||
@Id | ||
@Column(name = "address") | ||
private String address; | ||
|
||
@Id | ||
@Column(name = "tx_hash") | ||
private String txHash; | ||
|
||
@Column(name = "amount") | ||
private BigInteger amount; | ||
|
||
@Column(name = "epoch") | ||
private Integer epoch; | ||
|
||
@Column(name = "slot") | ||
private Long slot; | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
api/src/main/java/org/cardanofoundation/rosetta/api/block/model/entity/WithdrawalId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.cardanofoundation.rosetta.api.block.model.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import java.io.Serializable; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@EqualsAndHashCode | ||
public class WithdrawalId implements Serializable { | ||
@Column(name = "address") | ||
private String address; | ||
|
||
@Column(name = "tx_hash") | ||
private String txHash; | ||
} |
11 changes: 11 additions & 0 deletions
11
...n/java/org/cardanofoundation/rosetta/api/block/model/repository/WithdrawalRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.cardanofoundation.rosetta.api.block.model.repository; | ||
|
||
import java.util.List; | ||
import org.cardanofoundation.rosetta.api.block.model.entity.WithdrawalEntity; | ||
import org.cardanofoundation.rosetta.api.block.model.entity.WithdrawalId; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface WithdrawalRepository extends JpaRepository<WithdrawalEntity, WithdrawalId> { | ||
|
||
List<WithdrawalEntity> findByTxHash(String txHash); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.