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-388] SEP-6: Implement RPC actions #1166

Merged
merged 9 commits into from
Oct 31, 2023
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
@@ -1,5 +1,7 @@
package org.stellar.anchor.api.rpc.method;

import com.google.gson.annotations.SerializedName;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -9,4 +11,11 @@
@SuperBuilder
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class RequestCustomerInfoUpdateRequest extends RpcMethodParamsRequest {}
public class RequestCustomerInfoUpdateRequest extends RpcMethodParamsRequest {

@SerializedName("required_customer_info_message")
private String requiredCustomerInfoMessage;

@SerializedName("required_customer_info_updates")
private List<String> requiredCustomerInfoUpdates;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.stellar.anchor.api.rpc.method;

import com.google.gson.annotations.SerializedName;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import org.stellar.anchor.api.shared.InstructionField;

@Data
@SuperBuilder
Expand All @@ -23,4 +25,7 @@ public class RequestOffchainFundsRequest extends RpcMethodParamsRequest {

@SerializedName("amount_expected")
private AmountRequest amountExpected;

@SerializedName("instructions")
Map<String, InstructionField> instructions;
}
18 changes: 18 additions & 0 deletions core/src/main/java/org/stellar/anchor/sep6/Sep6Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public StartDepositResponse deposit(Sep10Jwt token, StartDepositRequest request)
.type(request.getType())
.assetCode(request.getAssetCode())
.assetIssuer(asset.getIssuer())
// NB: these are purposely set to incorrect values.
philipliu marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it mean there will be a state of the transaction in DB when it has incorrect amounts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the amounts are technically incorrect anyway since the Anchor updates fees asynchronously. Deposit instructions and withdraw anchor accounts (to be done in the next PR) will not be provided until the business server makes a request for funds RPC so there is no way for the user to accidentally submit the wrong amount.

Copy link
Contributor

Choose a reason for hiding this comment

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

But if the user requests the transaction, won't we return incorrect data? Shouldn't amount just be null instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. the NotifyAmountsUpdatedHandler validation requires the assets to be set so it can't be null (code). I guess we can remove the validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should probably think about this more, so I'll create a ticket to address this and merge it as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure RPC validation should just validate only the request having amount to not be null, if we expect transaction to start with null amounts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that makes sense. Created ANCHOR-525 to fix it.

// amount_out and amount_fee assets cannot be determined when the
// platform creates the transaction, but the RPC API requires
// these to be set during a notify_amounts_updated call.
.amountOut(request.getAmount())
.amountOutAsset(asset.getSep38AssetName())
.amountFee("0")
.amountFeeAsset(asset.getSep38AssetName())
.amountExpected(request.getAmount())
.startedAt(Instant.now())
.sep10Account(token.getAccount())
Expand Down Expand Up @@ -248,6 +256,16 @@ public StartWithdrawResponse withdraw(Sep10Jwt token, StartWithdrawRequest reque
.type(request.getType())
.assetCode(request.getAssetCode())
.assetIssuer(asset.getIssuer())
.amountIn(request.getAmount())
.amountInAsset(asset.getSep38AssetName())
// NB: these are purposely set to incorrect values.
// amount_out and amount_fee assets cannot be determined when the
// platform creates the transaction, but the RPC API requires
// these to be set during a notify_amounts_updated call.
.amountOut(request.getAmount())
.amountOutAsset(asset.getSep38AssetName())
.amountFee("0")
.amountFeeAsset(asset.getSep38AssetName())
.amountExpected(request.getAmount())
.startedAt(Instant.now())
.sep10Account(token.getAccount())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ public interface Sep6Transaction extends SepTransaction {

void setCompletedAt(Instant completedAt);

/**
* The date and time the user funds were received.
*
* @return the transfer received at timestamp.
*/
Instant getTransferReceivedAt();

void setTransferReceivedAt(Instant transferReceivedAt);

/**
* The deposit or withdrawal method used. E.g. <code>bank_account</code>, <code>cash</code>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public static GetTransactionResponse toGetTransactionResponse(
.startedAt(txn.getStartedAt())
.updatedAt(txn.getUpdatedAt())
.completedAt(txn.getCompletedAt())
.transferReceivedAt(txn.getTransferReceivedAt())
.message(txn.getMessage())
.refunds(txn.getRefunds())
.stellarTransactions(txn.getStellarTransactions())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class PojoSep6Transaction implements Sep6Transaction {
Instant startedAt;
Instant completedAt;
Instant updatedAt;
Instant transferReceivedAt;
String type;
String requestAssetCode;
String requestAssetIssuer;
Expand Down
Loading
Loading