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

[ANCHOR-555] Add client_domain and client_name to Platform transactions #1210

Merged
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
Expand Up @@ -89,6 +89,12 @@ public class PlatformTransactionData {
@SerializedName("withdraw_anchor_account")
String withdrawAnchorAccount;

@SerializedName("client_domain")
String clientDomain;

@SerializedName("client_name")
String clientName;

Customers customers;
StellarId creator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import org.stellar.anchor.config.ClientsConfig.ClientConfig;
import org.stellar.anchor.config.Sep10Config;

/** Finds the client ID for a SEP-10 JWT. */
/** Finds the client name for a SEP-10 JWT. */
@RequiredArgsConstructor
public class ClientFinder {
@NonNull private final Sep10Config sep10Config;
@NonNull private final ClientsConfig clientsConfig;

/**
* Returns the client ID for a SEP-10 JWT. If the client attribution is not required, the client
* Returns the client name for a SEP-10 JWT. If the client attribution is not required, the client
* ID is returned if the client is found. If the client attribution is required, the client ID is
* returned if the client is found and the client domain and name are allowed.
*
Expand All @@ -25,7 +25,7 @@ public class ClientFinder {
* @throws BadRequestException if the client is not found or the client domain or name is not
*/
@Nullable
public String getClientId(Sep10Jwt token) throws BadRequestException {
public String getClientName(Sep10Jwt token) throws BadRequestException {
ClientsConfig.ClientConfig client = getClient(token);

// If client attribution is not required, return the client name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.stellar.anchor.asset.AssetService;
import org.stellar.anchor.auth.JwtService;
import org.stellar.anchor.auth.Sep10Jwt;
import org.stellar.anchor.client.ClientFinder;
import org.stellar.anchor.config.AppConfig;
import org.stellar.anchor.config.ClientsConfig;
import org.stellar.anchor.config.CustodyConfig;
Expand All @@ -62,6 +63,7 @@ public class Sep24Service {
final ClientsConfig clientsConfig;
final AssetService assetService;
final JwtService jwtService;
final ClientFinder clientFinder;
final Sep24TransactionStore txnStore;
final EventService.Session eventSession;
final InteractiveUrlConstructor interactiveUrlConstructor;
Expand Down Expand Up @@ -93,6 +95,7 @@ public Sep24Service(
ClientsConfig clientsConfig,
AssetService assetService,
JwtService jwtService,
ClientFinder clientFinder,
Sep24TransactionStore txnStore,
EventService eventService,
InteractiveUrlConstructor interactiveUrlConstructor,
Expand All @@ -106,6 +109,7 @@ public Sep24Service(
this.clientsConfig = clientsConfig;
this.assetService = assetService;
this.jwtService = jwtService;
this.clientFinder = clientFinder;
this.txnStore = txnStore;
this.eventSession = eventService.createSession(this.getClass().getName(), TRANSACTION);
this.interactiveUrlConstructor = interactiveUrlConstructor;
Expand Down Expand Up @@ -209,7 +213,8 @@ public InteractiveTransactionResponse withdraw(
.sep10AccountMemo(token.getAccountMemo())
.fromAccount(sourceAccount)
.toAccount(asset.getDistributionAccount())
.clientDomain(token.getClientDomain());
.clientDomain(token.getClientDomain())
.clientName(clientFinder.getClientName(token));

if (!isEmpty(asset.getDistributionAccount())) {
builder.withdrawAnchorAccount(asset.getDistributionAccount());
Expand Down Expand Up @@ -397,6 +402,7 @@ public InteractiveTransactionResponse deposit(Sep10Jwt token, Map<String, String
.sep10AccountMemo(token.getAccountMemo())
.toAccount(destinationAccount)
.clientDomain(token.getClientDomain())
.clientName(clientFinder.getClientName(token))
.claimableBalanceSupported(claimableSupported);

if (memo != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ public interface Sep24Transaction extends SepTransaction {

void setClientDomain(String domainClient);

/**
* The name of the client that initiated the transaction.
*
* @return the client name.
*/
String getClientName();

void setClientName(String nameClient);

/**
* True if the client supports receiving deposit transactions as a claimable balance, false
* otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public Sep24TransactionBuilder clientDomain(String domainClient) {
return this;
}

public Sep24TransactionBuilder clientName(String clientName) {
txn.setClientName(clientName);
return this;
}

public Sep24TransactionBuilder claimableBalanceSupported(Boolean claimableBalanceSupported) {
txn.setClaimableBalanceSupported(claimableBalanceSupported);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public Sep31PostTransactionResponse postTransaction(
.requiredInfoMessage(null)
.quoteId(request.getQuoteId())
.clientDomain(sep10Jwt.getClientDomain())
.clientName(getClientName())
.requiredInfoUpdates(null)
.fields(request.getFields().getTransaction())
.refunded(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public interface Sep31Transaction extends SepTransaction {

void setClientDomain(String clientDomain);

String getClientName();

void setClientName(String clientName);

void setSenderId(String sourceId);

String getSenderId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ public Sep31TransactionBuilder clientDomain(String clientDomain) {
return this;
}

public Sep31TransactionBuilder clientName(String clientName) {
txn.setClientName(clientName);
return this;
}

public Sep31TransactionBuilder senderId(String senderId) {
txn.setSenderId(senderId);
return this;
Expand Down
15 changes: 14 additions & 1 deletion core/src/main/java/org/stellar/anchor/sep6/Sep6Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.stellar.anchor.api.sep.sep6.InfoResponse.*;
import org.stellar.anchor.asset.AssetService;
import org.stellar.anchor.auth.Sep10Jwt;
import org.stellar.anchor.client.ClientFinder;
import org.stellar.anchor.config.Sep6Config;
import org.stellar.anchor.event.EventService;
import org.stellar.anchor.sep6.ExchangeAmountsCalculator.Amounts;
Expand All @@ -25,6 +26,8 @@ public class Sep6Service {
private final Sep6Config sep6Config;
private final AssetService assetService;
private final RequestValidator requestValidator;

private final ClientFinder clientFinder;
private final Sep6TransactionStore txnStore;
private final ExchangeAmountsCalculator exchangeAmountsCalculator;
private final EventService.Session eventSession;
Expand All @@ -35,12 +38,14 @@ public Sep6Service(
Sep6Config sep6Config,
AssetService assetService,
RequestValidator requestValidator,
ClientFinder clientFinder,
Sep6TransactionStore txnStore,
ExchangeAmountsCalculator exchangeAmountsCalculator,
EventService eventService) {
this.sep6Config = sep6Config;
this.assetService = assetService;
this.requestValidator = requestValidator;
this.clientFinder = clientFinder;
this.txnStore = txnStore;
this.exchangeAmountsCalculator = exchangeAmountsCalculator;
this.eventSession =
Expand Down Expand Up @@ -93,7 +98,9 @@ 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())
.clientName(clientFinder.getClientName(token));

if (memo != null) {
builder.memo(memo.toString());
Expand Down Expand Up @@ -185,6 +192,8 @@ public StartDepositResponse depositExchange(Sep10Jwt token, StartDepositExchange
.sep10Account(token.getAccount())
.sep10AccountMemo(token.getAccountMemo())
.toAccount(request.getAccount())
.clientDomain(token.getClientDomain())
.clientName(clientFinder.getClientName(token))
.quoteId(request.getQuoteId());

if (memo != null) {
Expand Down Expand Up @@ -253,6 +262,8 @@ public StartWithdrawResponse withdraw(Sep10Jwt token, StartWithdrawRequest reque
.sep10Account(token.getAccount())
.sep10AccountMemo(token.getAccountMemo())
.fromAccount(sourceAccount)
.clientDomain(token.getClientDomain())
.clientName(clientFinder.getClientName(token))
.refundMemo(request.getRefundMemo())
.refundMemoType(request.getRefundMemoType());

Expand Down Expand Up @@ -339,6 +350,8 @@ public StartWithdrawResponse withdrawExchange(
.sep10Account(token.getAccount())
.sep10AccountMemo(token.getAccountMemo())
.fromAccount(sourceAccount)
.clientDomain(token.getClientDomain())
.clientName(clientFinder.getClientName(token))
.refundMemo(request.getRefundMemo())
.refundMemoType(request.getRefundMemoType())
.quoteId(request.getQuoteId());
Expand Down
18 changes: 18 additions & 0 deletions core/src/main/java/org/stellar/anchor/sep6/Sep6Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@ 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a part of the standard, isn't it?
https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md#transaction-history
Why do we want to add client_domain ?
Should we use client_name instead? Derived from the configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a part of the standard, isn't it?

It will only be visible by querying the Platform API, it is not being mapped on the SEP side. https://github.com/stellar/java-stellar-anchor-sdk/blob/7e42b5ccc7cf82a19a29a84716a6141208b0cb7c/core/src/main/java/org/stellar/anchor/sep6/Sep6TransactionUtils.java#L37-L63

Why do we want to add client_domain ?
Should we use client_name instead? Derived from the configuration?

I can add client_name, but should we keep client_domain as well? In SEP-24 both are included in the interactive JWT.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in general it's easier to work with client_name including both sounds like a good idea. But won't it require to add client_name to other SEPs too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But won't it require to add client_name to other SEPs too?

Yeah, this PR already adds the client_domain to SEP-24 and SEP-31. I will do the same for client_name.


void setClientDomain(String clientDomain);

/**
* The name of the client that initiated the transaction.
*
* @return the client name.
*/
String getClientName();

void setClientName(String clientName);

/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ public Sep6TransactionBuilder memoType(String memoType) {
return this;
}

public Sep6TransactionBuilder clientDomain(String clientDomain) {
txn.setClientDomain(clientDomain);
return this;
}

public Sep6TransactionBuilder clientName(String clientName) {
txn.setClientName(clientName);
return this;
}

public Sep6TransactionBuilder quoteId(String quoteId) {
txn.setQuoteId(quoteId);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public static GetTransactionResponse toGetTransactionResponse(Sep31Transaction t
.refunds(refunds)
.stellarTransactions(txn.getStellarTransactions())
.externalTransactionId(txn.getExternalTransactionId())
.clientDomain(txn.getClientDomain())
.clientName(txn.getClientName())
.customers(txn.getCustomers())
.creator(txn.getCreator())
.build();
Expand Down Expand Up @@ -145,6 +147,8 @@ public static GetTransactionResponse toGetTransactionResponse(
.externalTransactionId(txn.getExternalTransactionId())
.memo(txn.getMemo())
.memoType(txn.getMemoType())
.clientDomain(txn.getClientDomain())
.clientName(txn.getClientName())
.refundMemo(txn.getRefundMemo())
.refundMemoType(txn.getRefundMemoType())
.requiredInfoMessage(txn.getRequiredInfoMessage())
Expand Down Expand Up @@ -190,6 +194,8 @@ public static GetTransactionResponse toGetTransactionResponse(
.externalTransactionId(txn.getExternalTransactionId())
.memo(txn.getMemo())
.memoType(txn.getMemoType())
.clientDomain(txn.getClientDomain())
.clientName(txn.getClientName())
.refundMemo(txn.getRefundMemo())
.refundMemoType(txn.getRefundMemoType())
.quoteId(txn.getQuoteId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class PojoSep24Transaction implements Sep24Transaction {
String memo;
String protocol;
String clientDomain;
String clientName;
Boolean claimableBalanceSupported;
String amountIn;
String amountOut;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class PojoSep31Transaction implements Sep31Transaction {
String requiredInfoMessage;
String quoteId;
String clientDomain;
String clientName;
Sep31Operation.Fields requiredInfoUpdates;
Map<String, String> fields;
Boolean refunded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class PojoSep6Transaction implements Sep6Transaction {
String toAccount;
String memo;
String memoType;
String clientDomain;
String clientName;
String quoteId;
String message;
Refunds refunds;
Expand Down
10 changes: 10 additions & 0 deletions core/src/test/kotlin/org/stellar/anchor/sep24/Sep24ServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.stellar.anchor.auth.JwtService
import org.stellar.anchor.auth.JwtService.CLIENT_DOMAIN
import org.stellar.anchor.auth.Sep10Jwt
import org.stellar.anchor.auth.Sep24InteractiveUrlJwt
import org.stellar.anchor.client.ClientFinder
import org.stellar.anchor.config.*
import org.stellar.anchor.event.EventService
import org.stellar.anchor.sep38.PojoSep38Quote
Expand Down Expand Up @@ -106,6 +107,8 @@ internal class Sep24ServiceTest {

@MockK(relaxed = true) lateinit var feeIntegration: FeeIntegration

@MockK(relaxed = true) lateinit var clientFinder: ClientFinder

@MockK(relaxed = true) lateinit var txnStore: Sep24TransactionStore

@MockK(relaxed = true) lateinit var interactiveUrlConstructor: InteractiveUrlConstructor
Expand Down Expand Up @@ -148,6 +151,7 @@ internal class Sep24ServiceTest {
every { moreInfoUrlConstructor.construct(any()) } returns
"${TEST_SEP24_MORE_INFO_URL}?lang=en&token=$strToken"
every { clientsConfig.getClientConfigByDomain(any()) } returns clientConfig
every { clientFinder.getClientName(any()) } returns TEST_CLIENT_NAME
calculator = ExchangeAmountsCalculator(sep38QuoteStore)

sep24Service =
Expand All @@ -157,6 +161,7 @@ internal class Sep24ServiceTest {
clientsConfig,
assetService,
jwtService,
clientFinder,
txnStore,
eventService,
interactiveUrlConstructor,
Expand Down Expand Up @@ -195,6 +200,7 @@ internal class Sep24ServiceTest {
)
assertEquals(TEST_ACCOUNT, slotTxn.captured.fromAccount)
assertEquals(TEST_CLIENT_DOMAIN, slotTxn.captured.clientDomain)
assertEquals(TEST_CLIENT_NAME, slotTxn.captured.clientName)

val params = URLEncodedUtils.parse(URI(response.url), Charset.forName("UTF-8"))
val tokenStrings = params.filter { pair -> pair.name.equals("token") }
Expand Down Expand Up @@ -244,6 +250,7 @@ internal class Sep24ServiceTest {
assertEquals(TEST_MEMO, slotTxn.captured.sep10AccountMemo)
assertEquals(TEST_ACCOUNT, slotTxn.captured.fromAccount)
assertEquals(TEST_CLIENT_DOMAIN, slotTxn.captured.clientDomain)
assertEquals(TEST_CLIENT_NAME, slotTxn.captured.clientName)
}

@Test
Expand Down Expand Up @@ -343,6 +350,7 @@ internal class Sep24ServiceTest {
assertEquals(TEST_ASSET_ISSUER_ACCOUNT_ID, slotTxn.captured.requestAssetIssuer)
assertEquals(TEST_ACCOUNT, slotTxn.captured.toAccount)
assertEquals(TEST_CLIENT_DOMAIN, slotTxn.captured.clientDomain)
assertEquals(TEST_CLIENT_NAME, slotTxn.captured.clientName)
}

@Test
Expand Down Expand Up @@ -377,6 +385,7 @@ internal class Sep24ServiceTest {
assertEquals(TEST_MEMO, slotTxn.captured.sep10AccountMemo)
assertEquals(TEST_ACCOUNT, slotTxn.captured.fromAccount)
assertEquals(TEST_CLIENT_DOMAIN, slotTxn.captured.clientDomain)
assertEquals(TEST_CLIENT_NAME, slotTxn.captured.clientName)
}

@Test
Expand Down Expand Up @@ -442,6 +451,7 @@ internal class Sep24ServiceTest {
assertEquals(TEST_ASSET_ISSUER_ACCOUNT_ID, slotTxn.captured.requestAssetIssuer)
assertEquals(whitelistedAccount, slotTxn.captured.toAccount)
assertEquals(TEST_CLIENT_DOMAIN, slotTxn.captured.clientDomain)
assertEquals(TEST_CLIENT_NAME, slotTxn.captured.clientName)
}

@Test
Expand Down
Loading
Loading