From 75123c3d4a278d9546723a070ff49b3796e28ba8 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 24 Jul 2019 18:43:29 +0300 Subject: [PATCH 1/2] Updated on 2026-08-14 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9caa3ca724..1d7e11ec7a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,8 +36,8 @@ android { flavorDimensions "" productFlavors { tangemAccess { - versionCode 112 - versionName "0.907.1." + generateVersionName() + versionCode 113 + versionName "0.907.2." + generateVersionName() applicationId "com.tangem.wallet" signingConfig signingConfigs.debug } From effe72f480d1217c38d8ecc375da0ee0f8046445 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 26 Jul 2019 14:22:48 +0300 Subject: [PATCH 2/2] Updated on 2026-08-14 --- .../tangem/data/network/ServerApiStellar.java | 2 +- .../java/com/tangem/wallet/xlm/XlmEngine.java | 35 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/tangem/data/network/ServerApiStellar.java b/app/src/main/java/com/tangem/data/network/ServerApiStellar.java index ea844facbc..af38916d5d 100644 --- a/app/src/main/java/com/tangem/data/network/ServerApiStellar.java +++ b/app/src/main/java/com/tangem/data/network/ServerApiStellar.java @@ -138,7 +138,7 @@ public class ServerApiStellar { }); } - private void doStellarRequest(TangemContext ctx, StellarRequest.Base stellarRequest) throws IOException { + public void doStellarRequest(TangemContext ctx, StellarRequest.Base stellarRequest) throws IOException { stellarRequest.setError(null); try { Server server; diff --git a/app/src/main/java/com/tangem/wallet/xlm/XlmEngine.java b/app/src/main/java/com/tangem/wallet/xlm/XlmEngine.java index a2e848e234..ed2e360e63 100644 --- a/app/src/main/java/com/tangem/wallet/xlm/XlmEngine.java +++ b/app/src/main/java/com/tangem/wallet/xlm/XlmEngine.java @@ -18,7 +18,9 @@ import com.tangem.wallet.R; import com.tangem.wallet.TangemContext; import org.stellar.sdk.AssetTypeNative; +import org.stellar.sdk.CreateAccountOperation; import org.stellar.sdk.KeyPair; +import org.stellar.sdk.Operation; import org.stellar.sdk.PaymentOperation; import org.stellar.sdk.Transaction; import org.stellar.sdk.TransactionEx; @@ -361,7 +363,14 @@ public class XlmEngine extends CoinEngine { amountValue = new Amount(amountValue.subtract(feeValue), amountValue.getCurrency()); } - TransactionEx transaction = TransactionEx.buildEx(60, coinData.getAccountResponse(), new PaymentOperation.Builder(KeyPair.fromAccountId(targetAddress), new AssetTypeNative(), amountValue.toValueString()).build()); + Operation operation; + if (isAccountCreated(targetAddress)) + operation = new PaymentOperation.Builder(KeyPair.fromAccountId(targetAddress), new AssetTypeNative(), amountValue.toValueString()).build(); + else + operation = new CreateAccountOperation.Builder(KeyPair.fromAccountId(targetAddress), amountValue.toValueString()).build(); + + TransactionEx transaction = TransactionEx.buildEx(60, coinData.getAccountResponse(), operation); + if (transaction.getFee() != convertToInternalAmount(feeValue).intValueExact()) { throw new Exception("Invalid fee!"); @@ -408,6 +417,26 @@ public class XlmEngine extends CoinEngine { }; } + + // network call inside, don't use on main thread + private boolean isAccountCreated(String address) { + final ServerApiStellar serverApi = new ServerApiStellar(); + + StellarRequest.Balance request = new StellarRequest.Balance(address); + + try { + serverApi.doStellarRequest(ctx, request); + } catch (IOException e) { + Log.e(TAG, e.getMessage()); + return true; // suppose account is created if anything goes wrong TODO:check + } + + if (request.errorResponse != null && request.errorResponse.getCode() == 404) + return false; + else + return true; + } + @Override public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) { final ServerApiStellar serverApi = new ServerApiStellar(); @@ -539,6 +568,8 @@ public class XlmEngine extends CoinEngine { return false; } - public int pendingTransactionTimeoutInSeconds() { return 10; } + public int pendingTransactionTimeoutInSeconds() { + return 10; + } } \ No newline at end of file