Skip to content

Commit

Permalink
[ANCHOR-388] SEP-6: Implement RPC actions (#1166)
Browse files Browse the repository at this point in the history
### Description

This updates the RPC actions for SEP-6 and updates the reference server
implementation to use them. This PR is quite large as it updates the
unit tests for most of the RPC actions but, implementation-wise, not
much has changed. It might helpful to start by reviewing the
`Sep6End2EndTest` to get a sense of what changed with this PR.

### Context

SEP-6 should support RPC API.

### Testing

- `./gradlew test`

### Known limitations

- Platform API integration tests do not test the new flow but are
covered by the SEP-6 e2e tests.
- Refunds and custody service integration have not been implemented.

Both of these will be addressed by ANCHOR-508
  • Loading branch information
philipliu authored Oct 31, 2023
1 parent 7e42b5c commit 86d95d4
Show file tree
Hide file tree
Showing 59 changed files with 5,635 additions and 1,505 deletions.
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.
// 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

0 comments on commit 86d95d4

Please sign in to comment.