From 6bf03273867353cc4aad2ef06d9c52a6d903a276 Mon Sep 17 00:00:00 2001 From: philipliu Date: Thu, 23 Nov 2023 16:32:32 -0500 Subject: [PATCH] Add client_domain to SEP-6 transaction --- .../api/platform/PlatformTransactionData.java | 3 +++ .../org/stellar/anchor/sep6/Sep6Service.java | 6 ++++- .../stellar/anchor/sep6/Sep6Transaction.java | 9 ++++++++ .../anchor/sep6/Sep6TransactionBuilder.java | 5 +++++ .../anchor/util/TransactionHelper.java | 3 +++ .../anchor/sep6/PojoSep6Transaction.java | 1 + .../anchor/sep6/Sep6ServiceTestData.kt | 22 ++++++++++++++++--- .../platform/data/JdbcSep6Transaction.java | 4 ++++ .../db/migration/V11__sep6_client_domain.sql | 1 + 9 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 platform/src/main/resources/db/migration/V11__sep6_client_domain.sql diff --git a/api-schema/src/main/java/org/stellar/anchor/api/platform/PlatformTransactionData.java b/api-schema/src/main/java/org/stellar/anchor/api/platform/PlatformTransactionData.java index 831161534b..cd3ebbc629 100644 --- a/api-schema/src/main/java/org/stellar/anchor/api/platform/PlatformTransactionData.java +++ b/api-schema/src/main/java/org/stellar/anchor/api/platform/PlatformTransactionData.java @@ -89,6 +89,9 @@ public class PlatformTransactionData { @SerializedName("withdraw_anchor_account") String withdrawAnchorAccount; + @SerializedName("client_domain") + String clientDomain; + Customers customers; StellarId creator; diff --git a/core/src/main/java/org/stellar/anchor/sep6/Sep6Service.java b/core/src/main/java/org/stellar/anchor/sep6/Sep6Service.java index 60a5cb26ea..9b7bfc61d7 100644 --- a/core/src/main/java/org/stellar/anchor/sep6/Sep6Service.java +++ b/core/src/main/java/org/stellar/anchor/sep6/Sep6Service.java @@ -93,7 +93,8 @@ public StartDepositResponse deposit(Sep10Jwt token, StartDepositRequest request) .startedAt(Instant.now()) .sep10Account(token.getAccount()) .sep10AccountMemo(token.getAccountMemo()) - .toAccount(request.getAccount()); + .toAccount(request.getAccount()) + .clientDomain(token.getClientDomain()); if (memo != null) { builder.memo(memo.toString()); @@ -185,6 +186,7 @@ public StartDepositResponse depositExchange(Sep10Jwt token, StartDepositExchange .sep10Account(token.getAccount()) .sep10AccountMemo(token.getAccountMemo()) .toAccount(request.getAccount()) + .clientDomain(token.getClientDomain()) .quoteId(request.getQuoteId()); if (memo != null) { @@ -253,6 +255,7 @@ public StartWithdrawResponse withdraw(Sep10Jwt token, StartWithdrawRequest reque .sep10Account(token.getAccount()) .sep10AccountMemo(token.getAccountMemo()) .fromAccount(sourceAccount) + .clientDomain(token.getClientDomain()) .refundMemo(request.getRefundMemo()) .refundMemoType(request.getRefundMemoType()); @@ -339,6 +342,7 @@ public StartWithdrawResponse withdrawExchange( .sep10Account(token.getAccount()) .sep10AccountMemo(token.getAccountMemo()) .fromAccount(sourceAccount) + .clientDomain(token.getClientDomain()) .refundMemo(request.getRefundMemo()) .refundMemoType(request.getRefundMemoType()) .quoteId(request.getQuoteId()); diff --git a/core/src/main/java/org/stellar/anchor/sep6/Sep6Transaction.java b/core/src/main/java/org/stellar/anchor/sep6/Sep6Transaction.java index 0d5d97091e..05f0c65b77 100644 --- a/core/src/main/java/org/stellar/anchor/sep6/Sep6Transaction.java +++ b/core/src/main/java/org/stellar/anchor/sep6/Sep6Transaction.java @@ -276,6 +276,15 @@ public interface Sep6Transaction extends SepTransaction { void setMemoType(String memoType); + /** + * The client domain of the wallet that initiated the transaction. + * + * @return the client domain. + */ + String getClientDomain(); + + void setClientDomain(String clientDomain); + /** * The ID returned from a SEP-38 quote response. IF this is set, the user must deliver the deposit * funds to the anchor before the quote expires, otherwise the anchor may not honor the quote. diff --git a/core/src/main/java/org/stellar/anchor/sep6/Sep6TransactionBuilder.java b/core/src/main/java/org/stellar/anchor/sep6/Sep6TransactionBuilder.java index 2a06129b65..0b79ad1290 100644 --- a/core/src/main/java/org/stellar/anchor/sep6/Sep6TransactionBuilder.java +++ b/core/src/main/java/org/stellar/anchor/sep6/Sep6TransactionBuilder.java @@ -148,6 +148,11 @@ public Sep6TransactionBuilder memoType(String memoType) { return this; } + public Sep6TransactionBuilder clientDomain(String clientDomain) { + txn.setClientDomain(clientDomain); + return this; + } + public Sep6TransactionBuilder quoteId(String quoteId) { txn.setQuoteId(quoteId); return this; diff --git a/core/src/main/java/org/stellar/anchor/util/TransactionHelper.java b/core/src/main/java/org/stellar/anchor/util/TransactionHelper.java index 4ae9e63399..baf0475195 100644 --- a/core/src/main/java/org/stellar/anchor/util/TransactionHelper.java +++ b/core/src/main/java/org/stellar/anchor/util/TransactionHelper.java @@ -108,6 +108,7 @@ public static GetTransactionResponse toGetTransactionResponse(Sep31Transaction t .refunds(refunds) .stellarTransactions(txn.getStellarTransactions()) .externalTransactionId(txn.getExternalTransactionId()) + .clientDomain(txn.getClientDomain()) .customers(txn.getCustomers()) .creator(txn.getCreator()) .build(); @@ -145,6 +146,7 @@ public static GetTransactionResponse toGetTransactionResponse( .externalTransactionId(txn.getExternalTransactionId()) .memo(txn.getMemo()) .memoType(txn.getMemoType()) + .clientDomain(txn.getClientDomain()) .refundMemo(txn.getRefundMemo()) .refundMemoType(txn.getRefundMemoType()) .requiredInfoMessage(txn.getRequiredInfoMessage()) @@ -190,6 +192,7 @@ public static GetTransactionResponse toGetTransactionResponse( .externalTransactionId(txn.getExternalTransactionId()) .memo(txn.getMemo()) .memoType(txn.getMemoType()) + .clientDomain(txn.getClientDomain()) .refundMemo(txn.getRefundMemo()) .refundMemoType(txn.getRefundMemoType()) .build(); diff --git a/core/src/test/java/org/stellar/anchor/sep6/PojoSep6Transaction.java b/core/src/test/java/org/stellar/anchor/sep6/PojoSep6Transaction.java index 191dd09a1c..063656b6c4 100644 --- a/core/src/test/java/org/stellar/anchor/sep6/PojoSep6Transaction.java +++ b/core/src/test/java/org/stellar/anchor/sep6/PojoSep6Transaction.java @@ -40,6 +40,7 @@ public class PojoSep6Transaction implements Sep6Transaction { String toAccount; String memo; String memoType; + String clientDomain; String quoteId; String message; Refunds refunds; diff --git a/core/src/test/kotlin/org/stellar/anchor/sep6/Sep6ServiceTestData.kt b/core/src/test/kotlin/org/stellar/anchor/sep6/Sep6ServiceTestData.kt index 4fbdb95c2e..a49f7dced5 100644 --- a/core/src/test/kotlin/org/stellar/anchor/sep6/Sep6ServiceTestData.kt +++ b/core/src/test/kotlin/org/stellar/anchor/sep6/Sep6ServiceTestData.kt @@ -169,7 +169,8 @@ class Sep6ServiceTestData { "amountExpected": "100", "sep10Account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "sep10AccountMemo": "123", - "toAccount": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO" + "toAccount": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "clientDomain": "vibrant.stellar.org" } """ .trimIndent() @@ -188,6 +189,7 @@ class Sep6ServiceTestData { "asset": "stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP" }, "destination_account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "client_domain": "vibrant.stellar.org", "customers": { "sender": { "account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", @@ -212,7 +214,8 @@ class Sep6ServiceTestData { "requestAssetIssuer": "GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP", "sep10Account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "sep10AccountMemo": "123", - "toAccount": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO" + "toAccount": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "clientDomain": "vibrant.stellar.org" } """ @@ -231,6 +234,7 @@ class Sep6ServiceTestData { "asset": "stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP" }, "destination_account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "client_domain": "vibrant.stellar.org", "customers": { "sender": { "account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", @@ -264,6 +268,7 @@ class Sep6ServiceTestData { "sep10Account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "sep10AccountMemo": "123", "toAccount": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "clientDomain": "vibrant.stellar.org", "quoteId": "test-quote-id" } """ @@ -293,6 +298,7 @@ class Sep6ServiceTestData { }, "quote_id": "test-quote-id", "destination_account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "client_domain": "vibrant.stellar.org", "customers": { "sender": { "account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", @@ -325,7 +331,8 @@ class Sep6ServiceTestData { "amountExpected": "100", "sep10Account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "sep10AccountMemo": "123", - "toAccount": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO" + "toAccount": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "clientDomain": "vibrant.stellar.org" } """ .trimIndent() @@ -351,6 +358,7 @@ class Sep6ServiceTestData { }, "amount_fee": { "amount": "0", "asset": "iso4217:USD" }, "destination_account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "client_domain": "vibrant.stellar.org", "customers": { "sender": { "account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", @@ -387,6 +395,7 @@ class Sep6ServiceTestData { "sep10Account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "sep10AccountMemo": "123", "fromAccount": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "clientDomain": "vibrant.stellar.org", "refundMemo": "some text", "refundMemoType": "text" } @@ -413,6 +422,7 @@ class Sep6ServiceTestData { "source_account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "refund_memo": "some text", "refund_memo_type": "text", + "client_domain": "vibrant.stellar.org", "customers": { "sender": { "account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", @@ -439,6 +449,7 @@ class Sep6ServiceTestData { "sep10Account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "sep10AccountMemo": "123", "fromAccount": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "clientDomain": "vibrant.stellar.org", "refundMemo": "some text", "refundMemoType": "text" } @@ -460,6 +471,7 @@ class Sep6ServiceTestData { "source_account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "refund_memo": "some text", "refund_memo_type": "text", + "client_domain": "vibrant.stellar.org", "customers": { "sender": { "account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", @@ -493,6 +505,7 @@ class Sep6ServiceTestData { "sep10Account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "sep10AccountMemo": "123", "fromAccount": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "clientDomain": "vibrant.stellar.org", "quoteId": "test-quote-id", "refundMemo": "some text", "refundMemoType": "text" @@ -523,6 +536,7 @@ class Sep6ServiceTestData { "source_account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "refund_memo": "some text", "refund_memo_type": "text", + "client_domain": "vibrant.stellar.org", "customers": { "sender": { "account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", @@ -556,6 +570,7 @@ class Sep6ServiceTestData { "sep10Account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "sep10AccountMemo": "123", "fromAccount": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", + "clientDomain": "vibrant.stellar.org", "refundMemo": "some text", "refundMemoType": "text" } @@ -588,6 +603,7 @@ class Sep6ServiceTestData { "source_account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", "refund_memo": "some text", "refund_memo_type": "text", + "client_domain": "vibrant.stellar.org", "customers": { "sender": { "account": "GBLGJA4TUN5XOGTV6WO2BWYUI2OZR5GYQ5PDPCRMQ5XEPJOYWB2X4CJO", diff --git a/platform/src/main/java/org/stellar/anchor/platform/data/JdbcSep6Transaction.java b/platform/src/main/java/org/stellar/anchor/platform/data/JdbcSep6Transaction.java index 6823677ccd..afd9ee347a 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/data/JdbcSep6Transaction.java +++ b/platform/src/main/java/org/stellar/anchor/platform/data/JdbcSep6Transaction.java @@ -87,6 +87,10 @@ public String getProtocol() { @Column(name = "memo_type") String memoType; + @SerializedName("client_domain") + @Column(name = "client_domain") + String clientDomain; + @SerializedName("quote_id") @Column(name = "quote_id") String quoteId; diff --git a/platform/src/main/resources/db/migration/V11__sep6_client_domain.sql b/platform/src/main/resources/db/migration/V11__sep6_client_domain.sql new file mode 100644 index 0000000000..80def739b1 --- /dev/null +++ b/platform/src/main/resources/db/migration/V11__sep6_client_domain.sql @@ -0,0 +1 @@ +ALTER TABLE sep6_transaction ADD client_domain VARCHAR(255); \ No newline at end of file