From 4eec012f6c8a3183318fc4cb459abd369b79636a Mon Sep 17 00:00:00 2001 From: Anthony Buisset Date: Mon, 2 Sep 2024 16:05:07 +0200 Subject: [PATCH] add stellar transfer transaction --- .../stellar/StellarTransaction.java | 16 ++++-- .../stellar/StellarTransferTransaction.java | 49 +++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/main/java/onlydust/com/marketplace/kernel/model/blockchain/stellar/StellarTransferTransaction.java diff --git a/src/main/java/onlydust/com/marketplace/kernel/model/blockchain/stellar/StellarTransaction.java b/src/main/java/onlydust/com/marketplace/kernel/model/blockchain/stellar/StellarTransaction.java index 3260d53..8ebc789 100644 --- a/src/main/java/onlydust/com/marketplace/kernel/model/blockchain/stellar/StellarTransaction.java +++ b/src/main/java/onlydust/com/marketplace/kernel/model/blockchain/stellar/StellarTransaction.java @@ -1,14 +1,24 @@ package onlydust.com.marketplace.kernel.model.blockchain.stellar; -import lombok.EqualsAndHashCode; -import lombok.NonNull; +import lombok.*; +import lombok.experimental.Accessors; +import lombok.experimental.FieldDefaults; import onlydust.com.marketplace.kernel.model.blockchain.Blockchain; import onlydust.com.marketplace.kernel.model.blockchain.Blockchain.Transaction; import onlydust.com.marketplace.kernel.model.blockchain.HexHash; import java.time.ZonedDateTime; -public record StellarTransaction(Hash hash, ZonedDateTime timestamp, Status status) implements Transaction { +@AllArgsConstructor +@EqualsAndHashCode +@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) +@Getter +@Accessors(fluent = true) +public class StellarTransaction implements Transaction { + Hash hash; + ZonedDateTime timestamp; + Status status; + @Override public Blockchain blockchain() { return Blockchain.STELLAR; diff --git a/src/main/java/onlydust/com/marketplace/kernel/model/blockchain/stellar/StellarTransferTransaction.java b/src/main/java/onlydust/com/marketplace/kernel/model/blockchain/stellar/StellarTransferTransaction.java new file mode 100644 index 0000000..baa1aa7 --- /dev/null +++ b/src/main/java/onlydust/com/marketplace/kernel/model/blockchain/stellar/StellarTransferTransaction.java @@ -0,0 +1,49 @@ +package onlydust.com.marketplace.kernel.model.blockchain.stellar; + +import lombok.*; +import lombok.experimental.Accessors; +import lombok.experimental.FieldDefaults; +import onlydust.com.marketplace.kernel.model.blockchain.Blockchain.TransferTransaction; + +import java.math.BigDecimal; +import java.time.ZonedDateTime; +import java.util.Optional; + +@EqualsAndHashCode(callSuper = true) +@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) +@Getter +@Accessors(fluent = true) +@ToString +public class StellarTransferTransaction extends StellarTransaction implements TransferTransaction { + @NonNull + StellarAccountId sender; + @NonNull + StellarAccountId recipient; + @NonNull + BigDecimal amount; + StellarContractAddress contractAddress; + + public StellarTransferTransaction(final @NonNull Hash hash, final @NonNull ZonedDateTime timestamp, final @NonNull Status status, final @NonNull StellarAccountId sender, final @NonNull StellarAccountId recipient, final @NonNull BigDecimal amount, final StellarContractAddress contractAddress) { + super(hash, timestamp, status); + + this.sender = sender; + this.recipient = recipient; + this.amount = amount; + this.contractAddress = contractAddress; + } + + @Override + public String senderAddress() { + return sender.toString(); + } + + @Override + public String recipientAddress() { + return recipient.toString(); + } + + @Override + public Optional contractAddress() { + return Optional.ofNullable(contractAddress).map(StellarContractAddress::toString); + } +}