diff --git a/core/src/main/java/org/stellar/anchor/horizon/Horizon.java b/core/src/main/java/org/stellar/anchor/horizon/Horizon.java deleted file mode 100644 index d648264363..0000000000 --- a/core/src/main/java/org/stellar/anchor/horizon/Horizon.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.stellar.anchor.horizon; - -import static org.stellar.anchor.api.asset.AssetInfo.NATIVE_ASSET_CODE; - -import java.util.List; -import lombok.Getter; -import org.stellar.anchor.config.AppConfig; -import org.stellar.anchor.util.AssetHelper; -import org.stellar.sdk.AssetTypeCreditAlphaNum; -import org.stellar.sdk.Server; -import org.stellar.sdk.TrustLineAsset; -import org.stellar.sdk.exception.NetworkException; -import org.stellar.sdk.requests.PaymentsRequestBuilder; -import org.stellar.sdk.responses.AccountResponse; -import org.stellar.sdk.responses.operations.OperationResponse; -import org.stellar.sdk.xdr.AssetType; - -/** The horizon-server. */ -public class Horizon { - - @Getter private final String horizonUrl; - @Getter private final String stellarNetworkPassphrase; - private final Server horizonServer; - - public Horizon(AppConfig appConfig) { - this.horizonUrl = appConfig.getHorizonUrl(); - this.stellarNetworkPassphrase = appConfig.getStellarNetworkPassphrase(); - this.horizonServer = new Server(appConfig.getHorizonUrl()); - } - - public Server getServer() { - return this.horizonServer; - } - - public boolean isTrustlineConfigured(String account, String asset) throws NetworkException { - String assetCode = AssetHelper.getAssetCode(asset); - if (NATIVE_ASSET_CODE.equals(assetCode)) { - return true; - } - String assetIssuer = AssetHelper.getAssetIssuer(asset); - - AccountResponse accountResponse = getServer().accounts().account(account); - return accountResponse.getBalances().stream() - .anyMatch( - balance -> { - TrustLineAsset trustLineAsset = balance.getTrustLineAsset(); - if (trustLineAsset.getAssetType() == AssetType.ASSET_TYPE_CREDIT_ALPHANUM4 - || trustLineAsset.getAssetType() == AssetType.ASSET_TYPE_CREDIT_ALPHANUM12) { - AssetTypeCreditAlphaNum creditAsset = - (AssetTypeCreditAlphaNum) trustLineAsset.getAsset(); - assert creditAsset != null; - return creditAsset.getCode().equals(assetCode) - && creditAsset.getIssuer().equals(assetIssuer); - } - return false; - }); - } - - /** - * Get payment operations for a transaction. - * - * @param stellarTxnId the transaction id - * @return the operations - * @throws NetworkException request failed, see {@link PaymentsRequestBuilder#execute()} - */ - public List getStellarTxnOperations(String stellarTxnId) { - return getServer() - .payments() - .includeTransactions(true) - .forTransaction(stellarTxnId) - .execute() - .getRecords(); - } -} diff --git a/core/src/main/java/org/stellar/anchor/ledger/Horizon.java b/core/src/main/java/org/stellar/anchor/ledger/Horizon.java new file mode 100644 index 0000000000..bfd064384d --- /dev/null +++ b/core/src/main/java/org/stellar/anchor/ledger/Horizon.java @@ -0,0 +1,145 @@ +package org.stellar.anchor.ledger; + +import static org.stellar.anchor.api.asset.AssetInfo.NATIVE_ASSET_CODE; + +import java.util.List; +import java.util.stream.Collectors; +import lombok.Getter; +import org.stellar.anchor.config.AppConfig; +import org.stellar.anchor.ledger.LedgerTransaction.LedgerTransactionResponse; +import org.stellar.anchor.util.AssetHelper; +import org.stellar.sdk.*; +import org.stellar.sdk.exception.NetworkException; +import org.stellar.sdk.requests.PaymentsRequestBuilder; +import org.stellar.sdk.responses.AccountResponse; +import org.stellar.sdk.responses.TransactionResponse; +import org.stellar.sdk.responses.operations.OperationResponse; +import org.stellar.sdk.xdr.AssetType; + +/** The horizon-server. */ +public class Horizon implements LedgerApi { + + @Getter private final String horizonUrl; + @Getter private final String stellarNetworkPassphrase; + private final Server horizonServer; + + public Horizon(AppConfig appConfig) { + this.horizonUrl = appConfig.getHorizonUrl(); + this.stellarNetworkPassphrase = appConfig.getStellarNetworkPassphrase(); + this.horizonServer = new Server(appConfig.getHorizonUrl()); + } + + public Server getServer() { + return this.horizonServer; + } + + public boolean hasTrustline(String account, String asset) throws NetworkException { + String assetCode = AssetHelper.getAssetCode(asset); + if (NATIVE_ASSET_CODE.equals(assetCode)) { + return true; + } + String assetIssuer = AssetHelper.getAssetIssuer(asset); + + AccountResponse accountResponse = getServer().accounts().account(account); + return accountResponse.getBalances().stream() + .anyMatch( + balance -> { + TrustLineAsset trustLineAsset = balance.getTrustLineAsset(); + if (trustLineAsset.getAssetType() == AssetType.ASSET_TYPE_CREDIT_ALPHANUM4 + || trustLineAsset.getAssetType() == AssetType.ASSET_TYPE_CREDIT_ALPHANUM12) { + AssetTypeCreditAlphaNum creditAsset = + (AssetTypeCreditAlphaNum) trustLineAsset.getAsset(); + assert creditAsset != null; + return creditAsset.getCode().equals(assetCode) + && creditAsset.getIssuer().equals(assetIssuer); + } + return false; + }); + } + + @Override + public Account getAccount(String account) throws NetworkException { + AccountResponse response = getServer().accounts().account(account); + AccountResponse.Thresholds thresholds = response.getThresholds(); + + return Account.builder() + .accountId(response.getAccountId()) + .sequenceNumber(response.getSequenceNumber()) + .thresholds( + LedgerApi.Thresholds.builder() + .lowThreshold(thresholds.getLowThreshold()) + .medThreshold(thresholds.getMedThreshold()) + .highThreshold(thresholds.getHighThreshold()) + .build()) + .balances( + response.getBalances().stream() + .map( + b -> + Balance.builder() + .assetType(b.getAssetType()) + .assetCode(b.getAssetCode()) + .assetIssuer(b.getAssetIssuer()) + .liquidityPoolId(b.getLiquidityPoolId()) + .limit(b.getLimit()) + .build()) + .collect(Collectors.toList())) + .signers( + response.getSigners().stream() + .map( + s -> + Signer.builder() + .key(s.getKey()) + .type(s.getType()) + .weight(s.getWeight()) + .sponsor(s.getSponsor()) + .build()) + .collect(Collectors.toList())) + .build(); + } + + @Override + public LedgerTransaction getTransaction(String transactionId) throws NetworkException { + TransactionResponse response = getServer().transactions().transaction(transactionId); + return LedgerTransaction.builder() + .hash(response.getHash()) + .sourceAccount(response.getSourceAccount()) + .envelopeXdr(response.getEnvelopeXdr()) + .metaXdr(response.getResultMetaXdr()) + .sourceAccount(response.getSourceAccount()) + .memo(response.getMemo()) + .sequenceNumber(response.getSourceAccountSequence()) + .createdAt(response.getCreatedAt()) + .build(); + } + + @Override + public LedgerTransactionResponse submitTransaction(Transaction transaction) + throws NetworkException { + TransactionResponse txnR = getServer().submitTransaction(transaction, false); + + return LedgerTransactionResponse.builder() + .hash(txnR.getHash()) + .metaXdr(txnR.getEnvelopeXdr()) + .envelopXdr(txnR.getEnvelopeXdr()) + .sourceAccount(txnR.getSourceAccount()) + .feeCharged(txnR.getFeeCharged().toString()) + .createdAt(txnR.getCreatedAt()) + .build(); + } + + /** + * Get payment operations for a transaction. + * + * @param stellarTxnId the transaction id + * @return the operations + * @throws NetworkException request failed, see {@link PaymentsRequestBuilder#execute()} + */ + public List getStellarTxnOperations(String stellarTxnId) { + return getServer() + .payments() + .includeTransactions(true) + .forTransaction(stellarTxnId) + .execute() + .getRecords(); + } +} diff --git a/core/src/main/java/org/stellar/anchor/ledger/LedgerApi.java b/core/src/main/java/org/stellar/anchor/ledger/LedgerApi.java new file mode 100644 index 0000000000..8509a324c8 --- /dev/null +++ b/core/src/main/java/org/stellar/anchor/ledger/LedgerApi.java @@ -0,0 +1,110 @@ +package org.stellar.anchor.ledger; + +import java.io.IOException; +import java.util.List; +import lombok.Builder; +import lombok.Getter; +import lombok.Value; +import org.stellar.sdk.KeyPair; +import org.stellar.sdk.Transaction; +import org.stellar.sdk.TransactionBuilderAccount; +import org.stellar.sdk.exception.NetworkException; + +public interface LedgerApi { + /** + * Check if the account has a trustline for the given asset. + * + * @param account The account to check. + * @param asset The asset to check. + * @return True if the account has a trustline for the asset. + * @throws NetworkException If there was an error communicating with the network. + */ + boolean hasTrustline(String account, String asset) throws NetworkException, IOException; + + /** + * Get the account details for the given account. + * + * @param account The account to get. + * @return The account details. + * @throws NetworkException If there was an error communicating with the network. + */ + Account getAccount(String account) throws NetworkException; + + /** + * Get the operations for the given Stellar transaction. + * + * @param stellarTxnId The Stellar transaction ID. + * @return The operations for the transaction. + */ + LedgerTransaction getTransaction(String stellarTxnId); + + /** + * Submit a transaction to the network. + * + * @param transaction The transaction to submit. + * @return The transaction response. + * @throws NetworkException If there was an error communicating with the network. + */ + LedgerTransaction.LedgerTransactionResponse submitTransaction(Transaction transaction) + throws NetworkException; + + @Builder + @Getter + class Account implements TransactionBuilderAccount { + private String accountId; + private Long sequenceNumber; + + private Thresholds thresholds; + private List balances; + private List signers; + + @Override + public KeyPair getKeyPair() { + return KeyPair.fromAccountId(accountId); + } + + @Override + public void setSequenceNumber(long seqNum) { + sequenceNumber = seqNum; + } + + @Override + public Long getIncrementedSequenceNumber() { + return sequenceNumber + 1; + } + + /** Increments sequence number in this object by one. */ + public void incrementSequenceNumber() { + sequenceNumber++; + } + } + + @Builder + @Getter + class Thresholds { + Integer lowThreshold; + Integer medThreshold; + Integer highThreshold; + } + + @Builder + @Getter + class Balance { + String assetType; + String assetCode; + String assetIssuer; + String liquidityPoolId; + String limit; + String balance; + } + + @Value + @Builder + @Getter + class Signer { + String key; + String type; + Integer weight; + String sponsor; + } +} diff --git a/core/src/main/java/org/stellar/anchor/ledger/LedgerTransaction.java b/core/src/main/java/org/stellar/anchor/ledger/LedgerTransaction.java new file mode 100644 index 0000000000..00c637afb1 --- /dev/null +++ b/core/src/main/java/org/stellar/anchor/ledger/LedgerTransaction.java @@ -0,0 +1,70 @@ +package org.stellar.anchor.ledger; + +import java.util.List; +import lombok.Builder; +import lombok.Data; +import org.stellar.sdk.Asset; +import org.stellar.sdk.Memo; +import org.stellar.sdk.xdr.OperationType; + +@Builder +@Data +public class LedgerTransaction { + String hash; + String envelopeXdr; + String metaXdr; + String sourceAccount; + Asset sourceAsset; + Long fee; + Memo memo; + Long sequenceNumber; + String createdAt; + + List operations; + + @Builder + @Data + public static class LedgerOperation { + OperationType type; + LedgerPaymentOperation paymentOperation; + LedgerPathPaymentOperation pathPaymentOperation; + } + + @Builder + @Data + public static class LedgerPaymentOperation { + String assetType; + String sourceAccount; + String from; + String to; + String amount; + Asset asset; + } + + @Builder + @Data + public static class LedgerPathPaymentOperation { + String assetType; + String sourceAccount; + String sourceAmount; + String sourceAsset; + String sourceAssetType; + String from; + String to; + String amount; + Asset asset; + } + + @Builder + @Data + public static class LedgerTransactionResponse { + String hash; + String envelopXdr; + String metaXdr; + String sourceAccount; + String feeCharged; + Memo memo; + Long sequenceNumber; + String createdAt; + } +} diff --git a/core/src/main/java/org/stellar/anchor/ledger/StellarRpc.java b/core/src/main/java/org/stellar/anchor/ledger/StellarRpc.java new file mode 100644 index 0000000000..b169085d3a --- /dev/null +++ b/core/src/main/java/org/stellar/anchor/ledger/StellarRpc.java @@ -0,0 +1,41 @@ +package org.stellar.anchor.ledger; + +import lombok.SneakyThrows; +import org.stellar.sdk.SorobanServer; +import org.stellar.sdk.Transaction; +import org.stellar.sdk.exception.NetworkException; + +public class StellarRpc implements LedgerApi { + String rpcServerUrl; + SorobanServer sorobanServer; + + public StellarRpc(String rpcServerUrl) { + this.rpcServerUrl = rpcServerUrl; + sorobanServer = new SorobanServer(rpcServerUrl); + } + + @SneakyThrows + @Override + public boolean hasTrustline(String account, String asset) throws NetworkException { + // TODO: Implement this method + return false; + } + + @Override + public Account getAccount(String account) throws NetworkException { + // TODO: Implement this method + return null; + } + + @Override + public LedgerTransaction getTransaction(String stellarTxnId) { + return null; + } + + @Override + public LedgerTransaction.LedgerTransactionResponse submitTransaction(Transaction transaction) + throws NetworkException { + // TODO: Implement this method + return null; + } +} diff --git a/core/src/main/java/org/stellar/anchor/sep10/Sep10Service.java b/core/src/main/java/org/stellar/anchor/sep10/Sep10Service.java index f8f1c8a4e7..fb140eeda6 100644 --- a/core/src/main/java/org/stellar/anchor/sep10/Sep10Service.java +++ b/core/src/main/java/org/stellar/anchor/sep10/Sep10Service.java @@ -31,7 +31,7 @@ import org.stellar.anchor.config.AppConfig; import org.stellar.anchor.config.SecretConfig; import org.stellar.anchor.config.Sep10Config; -import org.stellar.anchor.horizon.Horizon; +import org.stellar.anchor.ledger.LedgerApi; import org.stellar.anchor.util.Log; import org.stellar.sdk.*; import org.stellar.sdk.Sep10Challenge.ChallengeTransaction; @@ -39,14 +39,13 @@ import org.stellar.sdk.exception.NetworkException; import org.stellar.sdk.operations.ManageDataOperation; import org.stellar.sdk.operations.Operation; -import org.stellar.sdk.responses.AccountResponse; /** The Sep-10 protocol service. */ public class Sep10Service implements ISep10Service { final AppConfig appConfig; final SecretConfig secretConfig; final Sep10Config sep10Config; - final Horizon horizon; + final LedgerApi ledgerApi; final JwtService jwtService; final ClientFinder clientFinder; final String serverAccountId; @@ -57,7 +56,7 @@ public Sep10Service( AppConfig appConfig, SecretConfig secretConfig, Sep10Config sep10Config, - Horizon horizon, + LedgerApi ledgerApi, JwtService jwtService, ClientFinder clientFinder) { debug("appConfig:", appConfig); @@ -65,7 +64,7 @@ public Sep10Service( this.appConfig = appConfig; this.secretConfig = secretConfig; this.sep10Config = sep10Config; - this.horizon = horizon; + this.ledgerApi = ledgerApi; this.jwtService = jwtService; this.clientFinder = clientFinder; this.serverAccountId = @@ -127,11 +126,11 @@ public ValidationResponse validateChallenge(ValidationRequest request) // fetch the client domain from the transaction String clientDomain = fetchClientDomain(challenge); - // fetch the account response from the horizon - AccountResponse account = fetchAccount(request, challenge, clientDomain); + // fetch the account response from the ledgerApi + LedgerApi.Account account = fetchAccount(request, challenge, clientDomain); if (account == null) { - // The account does not exist from Horizon, using the client's master key to verify. + // The account does not exist from LedgerApi, using the client's master key to verify. return ValidationResponse.of(generateSep10Jwt(challenge, clientDomain, homeDomain)); } // Since the account exists, we should check the signers and the client domain @@ -388,7 +387,7 @@ void validateAccountFormat(ChallengeRequest request) throws SepException { } void validateChallengeRequest( - ValidationRequest request, AccountResponse account, String clientDomain) + ValidationRequest request, LedgerApi.Account account, String clientDomain) throws SepValidationException { // fetch the signers from the transaction Set signers = fetchSigners(account); @@ -414,7 +413,7 @@ void validateChallengeRequest( signers); } - Set fetchSigners(AccountResponse account) { + Set fetchSigners(LedgerApi.Account account) { // Find the signers of the client account. return account.getSigners().stream() .filter(as -> as.getType().equals("ed25519_public_key")) @@ -422,14 +421,14 @@ Set fetchSigners(AccountResponse account) { .collect(Collectors.toSet()); } - AccountResponse fetchAccount( + LedgerApi.Account fetchAccount( ValidationRequest request, ChallengeTransaction challenge, String clientDomain) throws SepValidationException { // Check the client's account - AccountResponse account; + LedgerApi.Account account; try { infoF("Checking if {} exists in the Stellar network", challenge.getClientAccountId()); - account = horizon.getServer().accounts().account(challenge.getClientAccountId()); + account = ledgerApi.getAccount(challenge.getClientAccountId()); traceF("challenge account: {}", account); sep10ChallengeValidatedCounter.increment(); return account; diff --git a/core/src/test/kotlin/org/stellar/anchor/horizon/HorizonTest.kt b/core/src/test/kotlin/org/stellar/anchor/ledger/HorizonTest.kt similarity index 86% rename from core/src/test/kotlin/org/stellar/anchor/horizon/HorizonTest.kt rename to core/src/test/kotlin/org/stellar/anchor/ledger/HorizonTest.kt index f23648b48b..f53d4932e4 100644 --- a/core/src/test/kotlin/org/stellar/anchor/horizon/HorizonTest.kt +++ b/core/src/test/kotlin/org/stellar/anchor/ledger/HorizonTest.kt @@ -1,4 +1,4 @@ -package org.stellar.anchor.horizon +package org.stellar.anchor.ledger import io.mockk.every import io.mockk.mockk @@ -37,7 +37,7 @@ internal class HorizonTest { } @Test - fun test_isTrustlineConfigured_native() { + fun test_hasTrustline_native() { val appConfig = mockk() every { appConfig.horizonUrl } returns TEST_HORIZON_URI every { appConfig.stellarNetworkPassphrase } returns TEST_HORIZON_PASSPHRASE @@ -47,11 +47,11 @@ internal class HorizonTest { val account = "testAccount" val asset = "stellar:native" - assertTrue(horizon.isTrustlineConfigured(account, asset)) + assertTrue(horizon.hasTrustline(account, asset)) } @Test - fun test_isTrustlineConfigured_horizonError() { + fun test_hasTrustline_horizonError() { val appConfig = mockk() val server = mockk() val account = "testAccount" @@ -63,13 +63,13 @@ internal class HorizonTest { val horizon = mockk() every { horizon.server } returns server - every { horizon.isTrustlineConfigured(account, asset) } answers { callOriginal() } + every { horizon.hasTrustline(account, asset) } answers { callOriginal() } - assertThrows { horizon.isTrustlineConfigured(account, asset) } + assertThrows { horizon.hasTrustline(account, asset) } } @Test - fun test_isTrustlineConfigured_present() { + fun test_hasTrustline_present() { val appConfig = mockk() val server = mockk() val account = "testAccount" @@ -99,12 +99,12 @@ internal class HorizonTest { val horizon = mockk() every { horizon.server } returns server - every { horizon.isTrustlineConfigured(account, asset) } answers { callOriginal() } - assertTrue(horizon.isTrustlineConfigured(account, asset)) + every { horizon.hasTrustline(account, asset) } answers { callOriginal() } + assertTrue(horizon.hasTrustline(account, asset)) } @Test - fun test_isTrustlineConfigured_absent() { + fun test_hasTrustline_absent() { val appConfig = mockk() val server = mockk() val account = "testAccount" @@ -139,7 +139,7 @@ internal class HorizonTest { val horizon = mockk() every { horizon.server } returns server - every { horizon.isTrustlineConfigured(account, asset) } answers { callOriginal() } - assertFalse(horizon.isTrustlineConfigured(account, asset)) + every { horizon.hasTrustline(account, asset) } answers { callOriginal() } + assertFalse(horizon.hasTrustline(account, asset)) } } diff --git a/core/src/test/kotlin/org/stellar/anchor/sep10/Sep10ServiceTest.kt b/core/src/test/kotlin/org/stellar/anchor/sep10/Sep10ServiceTest.kt index ebef7b94de..0327002735 100644 --- a/core/src/test/kotlin/org/stellar/anchor/sep10/Sep10ServiceTest.kt +++ b/core/src/test/kotlin/org/stellar/anchor/sep10/Sep10ServiceTest.kt @@ -54,7 +54,8 @@ import org.stellar.anchor.config.AppConfig import org.stellar.anchor.config.CustodySecretConfig import org.stellar.anchor.config.SecretConfig import org.stellar.anchor.config.Sep10Config -import org.stellar.anchor.horizon.Horizon +import org.stellar.anchor.ledger.Horizon +import org.stellar.anchor.ledger.LedgerApi import org.stellar.anchor.setupMock import org.stellar.anchor.util.FileUtil import org.stellar.anchor.util.GsonUtils @@ -65,7 +66,6 @@ import org.stellar.sdk.exception.BadRequestException import org.stellar.sdk.exception.InvalidSep10ChallengeException import org.stellar.sdk.operations.ManageDataOperation import org.stellar.sdk.operations.SetOptionsOperation -import org.stellar.sdk.responses.AccountResponse import org.stellar.walletsdk.auth.DefaultAuthHeaderSigner import org.stellar.walletsdk.auth.createAuthSignToken import org.stellar.walletsdk.horizon.AccountKeyPair @@ -79,10 +79,10 @@ internal class TestSigner( @SerializedName("weight") val weight: Int, @SerializedName("sponsor") val sponsor: String ) { - fun toSigner(): AccountResponse.Signer { + fun toSigner(): LedgerApi.Signer { val gson = GsonUtils.getInstance() val json = gson.toJson(this) - return gson.fromJson(json, AccountResponse.Signer::class.java) + return gson.fromJson(json, LedgerApi.Signer::class.java) } } @@ -119,7 +119,7 @@ internal class Sep10ServiceTest { @MockK(relaxed = true) lateinit var secretConfig: SecretConfig @MockK(relaxed = true) lateinit var custodySecretConfig: CustodySecretConfig @MockK(relaxed = true) lateinit var sep10Config: Sep10Config - @MockK(relaxed = true) lateinit var horizon: Horizon + @MockK(relaxed = true) lateinit var ledgerApi: LedgerApi @MockK(relaxed = true) lateinit var clientFinder: ClientFinder private lateinit var jwtService: JwtService @@ -142,7 +142,7 @@ internal class Sep10ServiceTest { this.jwtService = spyk(JwtService(secretConfig, custodySecretConfig)) this.sep10Service = - Sep10Service(appConfig, secretConfig, sep10Config, horizon, jwtService, clientFinder) + Sep10Service(appConfig, secretConfig, sep10Config, ledgerApi, jwtService, clientFinder) this.httpClient = `create httpClient`() } @@ -239,9 +239,10 @@ internal class Sep10ServiceTest { every { secretConfig.sep10SigningSeed } returns String(serverKP.secretSeed) every { appConfig.horizonUrl } returns horizonUrl every { appConfig.stellarNetworkPassphrase } returns TESTNET.networkPassphrase - val horizon = Horizon(appConfig) + val ledgerApi = Horizon(appConfig) + // TODO: to be parameterized for Stellar RPC and Horizon this.sep10Service = - Sep10Service(appConfig, secretConfig, sep10Config, horizon, jwtService, clientFinder) + Sep10Service(appConfig, secretConfig, sep10Config, ledgerApi, jwtService, clientFinder) // 3 ------ Run tests val validationRequest = ValidationRequest.of(transaction.toEnvelopeXdrBase64()) @@ -322,9 +323,9 @@ internal class Sep10ServiceTest { every { secretConfig.sep10SigningSeed } returns String(serverKP.secretSeed) every { appConfig.horizonUrl } returns mockHorizonUrl every { appConfig.stellarNetworkPassphrase } returns TESTNET.networkPassphrase - val horizon = Horizon(appConfig) + val ledgerApi = Horizon(appConfig) this.sep10Service = - Sep10Service(appConfig, secretConfig, sep10Config, horizon, jwtService, clientFinder) + Sep10Service(appConfig, secretConfig, sep10Config, ledgerApi, jwtService, clientFinder) // 3 ------ Run tests val validationRequest = ValidationRequest.of(transaction.toEnvelopeXdrBase64()) @@ -375,14 +376,14 @@ internal class Sep10ServiceTest { val mockSigners = listOf(TestSigner(clientKeyPair.accountId, "ed25519_public_key", 1, "").toSigner()) val accountResponse = - mockk { + mockk { every { accountId } returns clientKeyPair.accountId every { sequenceNumber } returns 1 every { signers } returns mockSigners every { thresholds.medThreshold } returns 1 } - every { horizon.server.accounts().account(ofType(String::class)) } returns accountResponse + every { ledgerApi.getAccount(any()) } returns accountResponse val response = sep10Service.validateChallenge(vr) val jwt = jwtService.decode(response.token, Sep10Jwt::class.java) @@ -399,14 +400,14 @@ internal class Sep10ServiceTest { ) val accountResponse = - mockk { + mockk { every { accountId } returns clientKeyPair.accountId every { sequenceNumber } returns 1 every { signers } returns mockSigners every { thresholds.medThreshold } returns 1 } - every { horizon.server.accounts().account(ofType(String::class)) } returns accountResponse + every { ledgerApi.getAccount(any()) } returns accountResponse val vr = ValidationRequest() vr.transaction = createTestChallenge(TEST_CLIENT_DOMAIN, TEST_HOME_DOMAIN, true) @@ -423,7 +424,7 @@ internal class Sep10ServiceTest { // Test when the transaction was not signed by the client domain and the client account not // exists - every { horizon.server.accounts().account(ofType(String::class)) } answers + every { ledgerApi.getAccount(any()) } answers { throw BadRequestException(400, "mock error", null, null) } @@ -437,7 +438,7 @@ internal class Sep10ServiceTest { val vr = ValidationRequest() vr.transaction = createTestChallenge("", TEST_HOME_DOMAIN, false) - every { horizon.server.accounts().account(ofType(String::class)) } answers + every { ledgerApi.getAccount(any()) } answers { throw BadRequestException(400, "mock error", null, null) } @@ -768,9 +769,9 @@ internal class Sep10ServiceTest { every { secretConfig.sep10SigningSeed } returns String(serverKP.secretSeed) every { appConfig.horizonUrl } returns horizonUrl every { appConfig.stellarNetworkPassphrase } returns network.networkPassphrase - val horizon = Horizon(appConfig) + val ledgerApi = Horizon(appConfig) this.sep10Service = - Sep10Service(appConfig, secretConfig, sep10Config, horizon, jwtService, clientFinder) + Sep10Service(appConfig, secretConfig, sep10Config, ledgerApi, jwtService, clientFinder) // 3 ------ Setup multisig val httpRequest = @@ -782,7 +783,7 @@ internal class Sep10ServiceTest { val response = httpClient.newCall(httpRequest).execute() assertEquals(200, response.code) - val clientAccount = horizon.server.accounts().account(clientMasterKP.accountId) + val clientAccount = ledgerApi.getAccount(clientMasterKP.accountId) val multisigTx = TransactionBuilder(clientAccount, network) .addPreconditions( @@ -801,7 +802,7 @@ internal class Sep10ServiceTest { ) .build() multisigTx.sign(clientMasterKP) - horizon.server.submitTransaction(multisigTx) + ledgerApi.submitTransaction(multisigTx) // 4 ------ Run tests val validationRequest = ValidationRequest.of(transaction.toEnvelopeXdrBase64()) diff --git a/platform/src/main/java/org/stellar/anchor/platform/component/custody/FireblocksBeans.java b/platform/src/main/java/org/stellar/anchor/platform/component/custody/FireblocksBeans.java index 881e3aff9b..ec624cfac8 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/component/custody/FireblocksBeans.java +++ b/platform/src/main/java/org/stellar/anchor/platform/component/custody/FireblocksBeans.java @@ -9,7 +9,7 @@ import org.stellar.anchor.api.custody.fireblocks.TransactionDetails; import org.stellar.anchor.api.exception.InvalidConfigException; import org.stellar.anchor.config.CustodySecretConfig; -import org.stellar.anchor.horizon.Horizon; +import org.stellar.anchor.ledger.Horizon; import org.stellar.anchor.platform.config.FireblocksConfig; import org.stellar.anchor.platform.custody.*; import org.stellar.anchor.platform.custody.fireblocks.FireblocksApiClient; diff --git a/platform/src/main/java/org/stellar/anchor/platform/component/platform/PlatformServerBeans.java b/platform/src/main/java/org/stellar/anchor/platform/component/platform/PlatformServerBeans.java index 985651f2ae..d1d5c6247a 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/component/platform/PlatformServerBeans.java +++ b/platform/src/main/java/org/stellar/anchor/platform/component/platform/PlatformServerBeans.java @@ -17,7 +17,7 @@ import org.stellar.anchor.filter.ApiKeyFilter; import org.stellar.anchor.filter.NoneFilter; import org.stellar.anchor.filter.PlatformAuthJwtFilter; -import org.stellar.anchor.horizon.Horizon; +import org.stellar.anchor.ledger.Horizon; import org.stellar.anchor.platform.apiclient.CustodyApiClient; import org.stellar.anchor.platform.config.PlatformApiConfig; import org.stellar.anchor.platform.config.PlatformServerConfig; diff --git a/platform/src/main/java/org/stellar/anchor/platform/component/platform/RpcActionBeans.java b/platform/src/main/java/org/stellar/anchor/platform/component/platform/RpcActionBeans.java index 98cbc2526c..b0facbb94f 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/component/platform/RpcActionBeans.java +++ b/platform/src/main/java/org/stellar/anchor/platform/component/platform/RpcActionBeans.java @@ -9,7 +9,7 @@ import org.stellar.anchor.config.CustodyConfig; import org.stellar.anchor.custody.CustodyService; import org.stellar.anchor.event.EventService; -import org.stellar.anchor.horizon.Horizon; +import org.stellar.anchor.ledger.Horizon; import org.stellar.anchor.metrics.MetricsService; import org.stellar.anchor.platform.component.sep.ApiClientBeans; import org.stellar.anchor.platform.config.PropertyCustodyConfig; diff --git a/platform/src/main/java/org/stellar/anchor/platform/component/sep/SepBeans.java b/platform/src/main/java/org/stellar/anchor/platform/component/sep/SepBeans.java index cf43c80a87..290086a1fe 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/component/sep/SepBeans.java +++ b/platform/src/main/java/org/stellar/anchor/platform/component/sep/SepBeans.java @@ -17,7 +17,7 @@ import org.stellar.anchor.config.*; import org.stellar.anchor.event.EventService; import org.stellar.anchor.filter.Sep10JwtFilter; -import org.stellar.anchor.horizon.Horizon; +import org.stellar.anchor.ledger.Horizon; import org.stellar.anchor.platform.condition.OnAllSepsEnabled; import org.stellar.anchor.platform.condition.OnAnySepsEnabled; import org.stellar.anchor.platform.config.*; diff --git a/platform/src/main/java/org/stellar/anchor/platform/component/share/UtilityBeans.java b/platform/src/main/java/org/stellar/anchor/platform/component/share/UtilityBeans.java index 1f88a541ab..0371d604c8 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/component/share/UtilityBeans.java +++ b/platform/src/main/java/org/stellar/anchor/platform/component/share/UtilityBeans.java @@ -15,7 +15,7 @@ import org.stellar.anchor.client.ClientService; import org.stellar.anchor.config.*; import org.stellar.anchor.healthcheck.HealthCheckable; -import org.stellar.anchor.horizon.Horizon; +import org.stellar.anchor.ledger.Horizon; import org.stellar.anchor.platform.config.*; import org.stellar.anchor.platform.service.HealthCheckService; import org.stellar.anchor.platform.service.Sep24MoreInfoUrlConstructor; diff --git a/platform/src/main/java/org/stellar/anchor/platform/custody/fireblocks/FireblocksEventService.java b/platform/src/main/java/org/stellar/anchor/platform/custody/fireblocks/FireblocksEventService.java index da0511ad8d..82fe2521f7 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/custody/fireblocks/FireblocksEventService.java +++ b/platform/src/main/java/org/stellar/anchor/platform/custody/fireblocks/FireblocksEventService.java @@ -22,7 +22,7 @@ import org.stellar.anchor.api.exception.BadRequestException; import org.stellar.anchor.api.exception.InvalidConfigException; import org.stellar.anchor.api.exception.SepException; -import org.stellar.anchor.horizon.Horizon; +import org.stellar.anchor.ledger.Horizon; import org.stellar.anchor.platform.config.FireblocksConfig; import org.stellar.anchor.platform.custody.*; import org.stellar.anchor.platform.data.JdbcCustodyTransactionRepo; diff --git a/platform/src/main/java/org/stellar/anchor/platform/job/TrustlineCheckJob.java b/platform/src/main/java/org/stellar/anchor/platform/job/TrustlineCheckJob.java index 7239f7a7a8..6099e318ad 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/job/TrustlineCheckJob.java +++ b/platform/src/main/java/org/stellar/anchor/platform/job/TrustlineCheckJob.java @@ -7,7 +7,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.stellar.anchor.api.exception.AnchorException; import org.stellar.anchor.api.rpc.method.NotifyTrustSetRequest; -import org.stellar.anchor.horizon.Horizon; +import org.stellar.anchor.ledger.Horizon; import org.stellar.anchor.platform.config.PropertyCustodyConfig; import org.stellar.anchor.platform.data.JdbcTransactionPendingTrust; import org.stellar.anchor.platform.data.JdbcTransactionPendingTrustRepo; @@ -49,7 +49,7 @@ public void checkTrust() throws AnchorException { } else { boolean trustlineConfigured; try { - trustlineConfigured = horizon.isTrustlineConfigured(t.getAccount(), t.getAsset()); + trustlineConfigured = horizon.hasTrustline(t.getAccount(), t.getAsset()); } catch (NetworkException ex) { trustlineConfigured = false; } diff --git a/platform/src/main/java/org/stellar/anchor/platform/observer/ObservedPayment.java b/platform/src/main/java/org/stellar/anchor/platform/observer/ObservedPayment.java index c1e436d3ac..188b0ce117 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/observer/ObservedPayment.java +++ b/platform/src/main/java/org/stellar/anchor/platform/observer/ObservedPayment.java @@ -1,10 +1,13 @@ package org.stellar.anchor.platform.observer; +import static org.stellar.anchor.ledger.LedgerTransaction.*; + import com.google.gson.annotations.SerializedName; import lombok.Builder; import lombok.Data; import org.stellar.anchor.api.asset.AssetInfo; import org.stellar.anchor.api.exception.SepException; +import org.stellar.anchor.ledger.LedgerTransaction; import org.stellar.anchor.util.MemoHelper; import org.stellar.sdk.AssetTypeCreditAlphaNum; import org.stellar.sdk.AssetTypeNative; @@ -42,6 +45,91 @@ public class ObservedPayment { String transactionMemoType; String transactionEnvelope; + public static ObservedPayment from(LedgerTransaction txn, LedgerPaymentOperation paymentOp) + throws SepException { + String assetCode = null, assetIssuer = null; + + if (paymentOp.getAsset() instanceof AssetTypeCreditAlphaNum issuedAsset) { + assetCode = issuedAsset.getCode(); + assetIssuer = issuedAsset.getIssuer(); + } else if (paymentOp.getAsset() instanceof AssetTypeNative) { + assetCode = AssetInfo.NATIVE_ASSET_CODE; + } + + String sourceAccount = + paymentOp.getSourceAccount() != null + ? paymentOp.getSourceAccount() + : txn.getSourceAccount(); + String from = paymentOp.getFrom() != null ? paymentOp.getFrom() : sourceAccount; + Memo memo = txn.getMemo(); + return ObservedPayment.builder() + .id(txn.getHash()) + .type(Type.PAYMENT) + .from(from) + .to(paymentOp.getTo()) + .amount(paymentOp.getAmount()) + .assetType(paymentOp.getAssetType()) + .assetCode(assetCode) + .assetIssuer(assetIssuer) + .assetName(paymentOp.getAsset().toString()) + .sourceAccount(sourceAccount) + .createdAt(txn.getCreatedAt()) + .transactionHash(txn.getHash()) + .transactionMemo(MemoHelper.memoAsString(txn.getMemo())) + .transactionMemoType(MemoHelper.memoTypeAsString(memo)) + .transactionEnvelope(txn.getEnvelopeXdr()) + .build(); + } + + public static ObservedPayment from( + LedgerTransaction txn, LedgerPathPaymentOperation pathPaymentOp) throws SepException { + String assetCode = null, assetIssuer = null; + if (pathPaymentOp.getAsset() instanceof AssetTypeCreditAlphaNum issuedAsset) { + assetCode = issuedAsset.getCode(); + assetIssuer = issuedAsset.getIssuer(); + } else if (pathPaymentOp.getAsset() instanceof AssetTypeNative) { + assetCode = AssetInfo.NATIVE_ASSET_CODE; + } + + String sourceAssetCode = null, sourceAssetIssuer = null; + if (txn.getSourceAsset() instanceof AssetTypeCreditAlphaNum sourceIssuedAsset) { + sourceAssetCode = sourceIssuedAsset.getCode(); + sourceAssetIssuer = sourceIssuedAsset.getIssuer(); + } else if (txn.getSourceAsset() instanceof AssetTypeNative) { + sourceAssetCode = AssetInfo.NATIVE_ASSET_CODE; + } + + String sourceAccount = + pathPaymentOp.getSourceAccount() != null + ? pathPaymentOp.getSourceAccount() + : txn.getSourceAccount(); + String from = pathPaymentOp.getFrom() != null ? pathPaymentOp.getFrom() : sourceAccount; + Memo memo = txn.getMemo(); + return ObservedPayment.builder() + .id(txn.getHash()) + .type(Type.PATH_PAYMENT) + .from(from) + .to(pathPaymentOp.getTo()) + .amount(pathPaymentOp.getAmount()) + .assetType(pathPaymentOp.getAssetType()) + .assetCode(assetCode) + .assetIssuer(assetIssuer) + .assetName(pathPaymentOp.getAsset().toString()) + .sourceAmount(pathPaymentOp.getSourceAmount()) + .sourceAssetType(pathPaymentOp.getSourceAssetType()) + .sourceAssetCode(sourceAssetCode) + .sourceAssetIssuer(sourceAssetIssuer) + .sourceAssetName(pathPaymentOp.getSourceAsset()) + .sourceAccount(sourceAccount) + .createdAt(txn.getCreatedAt()) + .transactionHash(txn.getHash()) + .transactionMemo(MemoHelper.memoAsString(memo)) + .transactionMemoType(MemoHelper.memoTypeAsString(memo)) + .transactionEnvelope(txn.getEnvelopeXdr()) + .build(); + } + + // TODO: Replace this method when refactoring the observer public static ObservedPayment fromPaymentOperationResponse(PaymentOperationResponse paymentOp) throws SepException { String assetCode = null, assetIssuer = null; @@ -78,6 +166,7 @@ public static ObservedPayment fromPaymentOperationResponse(PaymentOperationRespo .build(); } + // TODO: Replace this method when refactoring the observer public static ObservedPayment fromPathPaymentOperationResponse( PathPaymentBaseOperationResponse pathPaymentOp) throws SepException { String assetCode = null, assetIssuer = null; diff --git a/platform/src/main/java/org/stellar/anchor/platform/rpc/DoStellarPaymentHandler.java b/platform/src/main/java/org/stellar/anchor/platform/rpc/DoStellarPaymentHandler.java index 8617e1fc4e..90194cfa98 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/rpc/DoStellarPaymentHandler.java +++ b/platform/src/main/java/org/stellar/anchor/platform/rpc/DoStellarPaymentHandler.java @@ -24,7 +24,7 @@ import org.stellar.anchor.config.CustodyConfig; import org.stellar.anchor.custody.CustodyService; import org.stellar.anchor.event.EventService; -import org.stellar.anchor.horizon.Horizon; +import org.stellar.anchor.ledger.Horizon; import org.stellar.anchor.metrics.MetricsService; import org.stellar.anchor.platform.data.*; import org.stellar.anchor.platform.validator.RequestValidator; @@ -92,13 +92,12 @@ protected SepTransactionStatus getNextStatus( switch (Sep.from(txn.getProtocol())) { case SEP_6: JdbcSep6Transaction txn6 = (JdbcSep6Transaction) txn; - trustlineConfigured = - horizon.isTrustlineConfigured(txn6.getToAccount(), txn6.getAmountOutAsset()); + trustlineConfigured = horizon.hasTrustline(txn6.getToAccount(), txn6.getAmountOutAsset()); break; case SEP_24: JdbcSep24Transaction txn24 = (JdbcSep24Transaction) txn; trustlineConfigured = - horizon.isTrustlineConfigured(txn24.getToAccount(), txn24.getAmountOutAsset()); + horizon.hasTrustline(txn24.getToAccount(), txn24.getAmountOutAsset()); break; default: break; @@ -148,8 +147,7 @@ protected void updateTransactionWithRpcRequest( JdbcSep6Transaction txn6 = (JdbcSep6Transaction) txn; try { - trustlineConfigured = - horizon.isTrustlineConfigured(txn6.getToAccount(), txn6.getAmountOutAsset()); + trustlineConfigured = horizon.hasTrustline(txn6.getToAccount(), txn6.getAmountOutAsset()); } catch (NetworkException ex) { trustlineConfigured = false; } @@ -171,7 +169,7 @@ protected void updateTransactionWithRpcRequest( try { trustlineConfigured = - horizon.isTrustlineConfigured(txn24.getToAccount(), txn24.getAmountOutAsset()); + horizon.hasTrustline(txn24.getToAccount(), txn24.getAmountOutAsset()); } catch (NetworkException ex) { trustlineConfigured = false; } diff --git a/platform/src/main/java/org/stellar/anchor/platform/rpc/NotifyOnchainFundsReceivedHandler.java b/platform/src/main/java/org/stellar/anchor/platform/rpc/NotifyOnchainFundsReceivedHandler.java index 463169e6c1..8fa766be33 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/rpc/NotifyOnchainFundsReceivedHandler.java +++ b/platform/src/main/java/org/stellar/anchor/platform/rpc/NotifyOnchainFundsReceivedHandler.java @@ -24,7 +24,7 @@ import org.stellar.anchor.api.sep.SepTransactionStatus; import org.stellar.anchor.asset.AssetService; import org.stellar.anchor.event.EventService; -import org.stellar.anchor.horizon.Horizon; +import org.stellar.anchor.ledger.Horizon; import org.stellar.anchor.metrics.MetricsService; import org.stellar.anchor.platform.data.JdbcSep24Transaction; import org.stellar.anchor.platform.data.JdbcSep31Transaction; diff --git a/platform/src/main/java/org/stellar/anchor/platform/rpc/NotifyOnchainFundsSentHandler.java b/platform/src/main/java/org/stellar/anchor/platform/rpc/NotifyOnchainFundsSentHandler.java index 1bbf62f71a..ba9a5c8866 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/rpc/NotifyOnchainFundsSentHandler.java +++ b/platform/src/main/java/org/stellar/anchor/platform/rpc/NotifyOnchainFundsSentHandler.java @@ -23,7 +23,7 @@ import org.stellar.anchor.api.sep.SepTransactionStatus; import org.stellar.anchor.asset.AssetService; import org.stellar.anchor.event.EventService; -import org.stellar.anchor.horizon.Horizon; +import org.stellar.anchor.ledger.Horizon; import org.stellar.anchor.metrics.MetricsService; import org.stellar.anchor.platform.data.JdbcSep24Transaction; import org.stellar.anchor.platform.data.JdbcSep6Transaction; diff --git a/platform/src/test/kotlin/org/stellar/anchor/platform/custody/fireblocks/FireblocksEventServiceTest.kt b/platform/src/test/kotlin/org/stellar/anchor/platform/custody/fireblocks/FireblocksEventServiceTest.kt index bce1f5d309..4fef9b487b 100644 --- a/platform/src/test/kotlin/org/stellar/anchor/platform/custody/fireblocks/FireblocksEventServiceTest.kt +++ b/platform/src/test/kotlin/org/stellar/anchor/platform/custody/fireblocks/FireblocksEventServiceTest.kt @@ -18,7 +18,7 @@ import org.stellar.anchor.api.custody.fireblocks.TransactionDetails import org.stellar.anchor.api.custody.fireblocks.TransactionStatus import org.stellar.anchor.api.exception.BadRequestException import org.stellar.anchor.api.exception.InvalidConfigException -import org.stellar.anchor.horizon.Horizon +import org.stellar.anchor.ledger.Horizon import org.stellar.anchor.platform.config.FireblocksConfig import org.stellar.anchor.platform.config.PropertyCustodySecretConfig import org.stellar.anchor.platform.custody.CustodyPayment diff --git a/platform/src/test/kotlin/org/stellar/anchor/platform/job/TrustlineCheckJobTest.kt b/platform/src/test/kotlin/org/stellar/anchor/platform/job/TrustlineCheckJobTest.kt index cf8fe616f5..09eeffaef3 100644 --- a/platform/src/test/kotlin/org/stellar/anchor/platform/job/TrustlineCheckJobTest.kt +++ b/platform/src/test/kotlin/org/stellar/anchor/platform/job/TrustlineCheckJobTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test import org.skyscreamer.jsonassert.JSONAssert import org.skyscreamer.jsonassert.JSONCompareMode import org.stellar.anchor.api.rpc.method.NotifyTrustSetRequest -import org.stellar.anchor.horizon.Horizon +import org.stellar.anchor.ledger.Horizon import org.stellar.anchor.platform.config.PropertyCustodyConfig import org.stellar.anchor.platform.config.PropertyCustodyConfig.Trustline import org.stellar.anchor.platform.data.JdbcTransactionPendingTrust @@ -56,7 +56,7 @@ class TrustlineCheckJobTest { every { transactionPendingTrustRepo.findAll() } returns listOf(txnPendingTrust) every { custodyConfig.trustline } returns trustline - every { horizon.isTrustlineConfigured(ACCOUNT, ASSET) } returns false + every { horizon.hasTrustline(ACCOUNT, ASSET) } returns false trustlineCheckJob.checkTrust() @@ -78,7 +78,7 @@ class TrustlineCheckJobTest { every { transactionPendingTrustRepo.findAll() } returns listOf(txnPendingTrust) every { custodyConfig.trustline } returns trustline - every { horizon.isTrustlineConfigured(ACCOUNT, ASSET) } returns true + every { horizon.hasTrustline(ACCOUNT, ASSET) } returns true every { notifyTrustSetHandler.handle(capture(notifyTrustSetRequestCapture)) } returns null trustlineCheckJob.checkTrust() diff --git a/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/DoStellarPaymentHandlerTest.kt b/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/DoStellarPaymentHandlerTest.kt index 9c3e78c121..6f23066fa8 100644 --- a/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/DoStellarPaymentHandlerTest.kt +++ b/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/DoStellarPaymentHandlerTest.kt @@ -32,7 +32,7 @@ import org.stellar.anchor.custody.CustodyService import org.stellar.anchor.event.EventService import org.stellar.anchor.event.EventService.EventQueue.TRANSACTION import org.stellar.anchor.event.EventService.Session -import org.stellar.anchor.horizon.Horizon +import org.stellar.anchor.ledger.Horizon import org.stellar.anchor.metrics.MetricsService import org.stellar.anchor.platform.data.JdbcSep24Transaction import org.stellar.anchor.platform.data.JdbcSep6Transaction @@ -245,7 +245,7 @@ class DoStellarPaymentHandlerTest { every { txn31Store.findByTransactionId(any()) } returns null every { txn24Store.save(capture(sep24TxnCapture)) } returns null every { custodyConfig.isCustodyIntegrationEnabled } returns true - every { horizon.isTrustlineConfigured(TO_ACCOUNT, AMOUNT_OUT_ASSET) } returns true + every { horizon.hasTrustline(TO_ACCOUNT, AMOUNT_OUT_ASSET) } returns true every { eventSession.publish(capture(anchorEventCapture)) } just Runs every { metricsService.counter(PLATFORM_RPC_TRANSACTION, "SEP", "sep24") } returns sepTransactionCounter @@ -330,7 +330,7 @@ class DoStellarPaymentHandlerTest { every { txn31Store.findByTransactionId(any()) } returns null every { txn24Store.save(capture(sep24TxnCapture)) } returns null every { custodyConfig.isCustodyIntegrationEnabled } returns true - every { horizon.isTrustlineConfigured(TO_ACCOUNT, AMOUNT_OUT_ASSET) } returns false + every { horizon.hasTrustline(TO_ACCOUNT, AMOUNT_OUT_ASSET) } returns false every { transactionPendingTrustRepo.save(capture(txnPendingTrustCapture)) } returns JdbcTransactionPendingTrust() every { eventSession.publish(capture(anchorEventCapture)) } just Runs @@ -504,7 +504,7 @@ class DoStellarPaymentHandlerTest { every { txn31Store.findByTransactionId(any()) } returns null every { txn6Store.save(capture(sep6TxnCapture)) } returns null every { custodyConfig.isCustodyIntegrationEnabled } returns true - every { horizon.isTrustlineConfigured(TO_ACCOUNT, AMOUNT_OUT_ASSET) } returns true + every { horizon.hasTrustline(TO_ACCOUNT, AMOUNT_OUT_ASSET) } returns true every { eventSession.publish(capture(anchorEventCapture)) } just Runs every { metricsService.counter(PLATFORM_RPC_TRANSACTION, "SEP", "sep6") } returns sepTransactionCounter @@ -591,7 +591,7 @@ class DoStellarPaymentHandlerTest { every { txn31Store.findByTransactionId(any()) } returns null every { txn6Store.save(capture(sep6TxnCapture)) } returns null every { custodyConfig.isCustodyIntegrationEnabled } returns true - every { horizon.isTrustlineConfigured(TO_ACCOUNT, AMOUNT_OUT_ASSET) } returns false + every { horizon.hasTrustline(TO_ACCOUNT, AMOUNT_OUT_ASSET) } returns false every { transactionPendingTrustRepo.save(capture(txnPendingTrustCapture)) } returns JdbcTransactionPendingTrust() every { eventSession.publish(capture(anchorEventCapture)) } just Runs diff --git a/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/NotifyOnchainFundsReceivedHandlerTest.kt b/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/NotifyOnchainFundsReceivedHandlerTest.kt index 1839456cb5..1bdaf3ba1d 100644 --- a/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/NotifyOnchainFundsReceivedHandlerTest.kt +++ b/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/NotifyOnchainFundsReceivedHandlerTest.kt @@ -33,7 +33,7 @@ import org.stellar.anchor.asset.DefaultAssetService import org.stellar.anchor.event.EventService import org.stellar.anchor.event.EventService.EventQueue.TRANSACTION import org.stellar.anchor.event.EventService.Session -import org.stellar.anchor.horizon.Horizon +import org.stellar.anchor.ledger.Horizon import org.stellar.anchor.metrics.MetricsService import org.stellar.anchor.platform.data.JdbcSep24Transaction import org.stellar.anchor.platform.data.JdbcSep31Transaction diff --git a/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/NotifyOnchainFundsSentHandlerTest.kt b/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/NotifyOnchainFundsSentHandlerTest.kt index 5dbbf13962..70fa54505e 100644 --- a/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/NotifyOnchainFundsSentHandlerTest.kt +++ b/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/NotifyOnchainFundsSentHandlerTest.kt @@ -34,7 +34,7 @@ import org.stellar.anchor.asset.AssetService import org.stellar.anchor.event.EventService import org.stellar.anchor.event.EventService.EventQueue.TRANSACTION import org.stellar.anchor.event.EventService.Session -import org.stellar.anchor.horizon.Horizon +import org.stellar.anchor.ledger.Horizon import org.stellar.anchor.metrics.MetricsService import org.stellar.anchor.platform.data.JdbcSep24Transaction import org.stellar.anchor.platform.data.JdbcSep6Transaction diff --git a/platform/src/test/kotlin/org/stellar/anchor/platform/service/PaymentOperationToEventListenerTest.kt b/platform/src/test/kotlin/org/stellar/anchor/platform/service/LedgerPathPaymentOperationToEventListenerTest.kt similarity index 99% rename from platform/src/test/kotlin/org/stellar/anchor/platform/service/PaymentOperationToEventListenerTest.kt rename to platform/src/test/kotlin/org/stellar/anchor/platform/service/LedgerPathPaymentOperationToEventListenerTest.kt index cd35f7bf96..3b28d5ebf6 100644 --- a/platform/src/test/kotlin/org/stellar/anchor/platform/service/PaymentOperationToEventListenerTest.kt +++ b/platform/src/test/kotlin/org/stellar/anchor/platform/service/LedgerPathPaymentOperationToEventListenerTest.kt @@ -24,7 +24,7 @@ import org.stellar.sdk.Asset import org.stellar.sdk.Asset.create import org.stellar.sdk.AssetTypeNative -class PaymentOperationToEventListenerTest { +class LedgerPathPaymentOperationToEventListenerTest { @MockK(relaxed = true) private lateinit var sep31TransactionStore: JdbcSep31TransactionStore @MockK(relaxed = true) private lateinit var sep24TransactionStore: JdbcSep24TransactionStore @MockK(relaxed = true) private lateinit var sep6TransactionStore: JdbcSep6TransactionStore