diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000000..681f41ae2a
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,116 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 4d7051be33..ba1ec0f15a 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -51,8 +51,8 @@ android {
flavorDimensions ""
productFlavors {
tangemAccess {
- versionCode 115
- versionName "0.908.1." + generateVersionName()
+ versionCode 116
+ versionName "0.908.2." + generateVersionName()
applicationId "com.tangem.wallet"
signingConfig signingConfigs.debug
}
diff --git a/app/src/main/java/com/tangem/data/network/BlockchainInfoApi.java b/app/src/main/java/com/tangem/data/network/BlockchainInfoApi.java
new file mode 100644
index 0000000000..caa2e14013
--- /dev/null
+++ b/app/src/main/java/com/tangem/data/network/BlockchainInfoApi.java
@@ -0,0 +1,27 @@
+package com.tangem.data.network;
+
+import com.tangem.data.network.model.BlockchainInfoAddress;
+import com.tangem.data.network.model.BlockchainInfoUnspents;
+
+import io.reactivex.Observable;
+
+import io.reactivex.Single;
+import okhttp3.ResponseBody;
+import retrofit2.http.Field;
+import retrofit2.http.FormUrlEncoded;
+import retrofit2.http.GET;
+import retrofit2.http.POST;
+import retrofit2.http.Path;
+import retrofit2.http.Query;
+
+public interface BlockchainInfoApi {
+ @GET(Server.ApiBlockchainInfo.Method.ADDRESS)
+ Single blockchainInfoAddress(@Path("address") String address);
+
+ @GET(Server.ApiBlockchainInfo.Method.UTXO)
+ Single blockchainInfoUnspents(@Query("active") String address);
+
+ @FormUrlEncoded
+ @POST(Server.ApiBlockchainInfo.Method.PUSH)
+ Single blockchainInfoPush(@Field("tx") String tx);
+}
diff --git a/app/src/main/java/com/tangem/data/network/CoinmarketApi.java b/app/src/main/java/com/tangem/data/network/CoinmarketApi.java
index 0411ca2100..fd3699ba08 100644
--- a/app/src/main/java/com/tangem/data/network/CoinmarketApi.java
+++ b/app/src/main/java/com/tangem/data/network/CoinmarketApi.java
@@ -3,7 +3,6 @@ package com.tangem.data.network;
import com.tangem.data.network.model.RateInfoResponse;
import io.reactivex.Observable;
-import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.Query;
diff --git a/app/src/main/java/com/tangem/data/network/Server.java b/app/src/main/java/com/tangem/data/network/Server.java
index 943488dc02..1b0570150a 100644
--- a/app/src/main/java/com/tangem/data/network/Server.java
+++ b/app/src/main/java/com/tangem/data/network/Server.java
@@ -118,4 +118,15 @@ public class Server {
static final String PUSH = MAIN + "/txs/push";
}
}
+
+ public static class ApiBlockchainInfo {
+ public static final String URL_BLOCKCHAININFO = ServerURL.API_BLOCKCHAIN_INFO;
+
+ public static class Method {
+ static final String ADDRESS = URL_BLOCKCHAININFO + "rawaddr/{address}?limit=5";
+ static final String UTXO = URL_BLOCKCHAININFO + "unspent";
+// static final String TX = URL_BLOCKCHAININFO + "rawtx/{txHash}";
+ static final String PUSH = URL_BLOCKCHAININFO + "pushtx";
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiBlockchainInfo.java b/app/src/main/java/com/tangem/data/network/ServerApiBlockchainInfo.java
new file mode 100644
index 0000000000..42581e3d43
--- /dev/null
+++ b/app/src/main/java/com/tangem/data/network/ServerApiBlockchainInfo.java
@@ -0,0 +1,48 @@
+package com.tangem.data.network;
+
+import android.util.Log;
+
+import com.tangem.App;
+import com.tangem.data.network.model.BlockchainInfoAddress;
+import com.tangem.data.network.model.BlockchainInfoAddressAndUnspents;
+import com.tangem.data.network.model.BlockchainInfoUnspents;
+
+import java.util.ArrayList;
+
+import io.reactivex.Observable;
+import io.reactivex.Observer;
+import io.reactivex.Single;
+import io.reactivex.SingleObserver;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.schedulers.Schedulers;
+import okhttp3.ResponseBody;
+
+public class ServerApiBlockchainInfo {
+ private static String TAG = ServerApiBlockchainInfo.class.getSimpleName();
+
+ public void getAddressAndUnspents(String wallet, SingleObserver addressAndUnspentsObserver) {
+ Log.i(TAG, "new getAddressAndUnspents request");
+ BlockchainInfoApi api = App.Companion.getNetworkComponent().getRetrofitBlockchainInfo().create(BlockchainInfoApi.class);
+
+ Single addressObservable = api.blockchainInfoAddress(wallet);
+
+ Single unspentsObservable = api.blockchainInfoUnspents(wallet)
+ .onErrorReturnItem(new BlockchainInfoUnspents(new ArrayList<>()));
+
+ Single.zip(addressObservable, unspentsObservable, BlockchainInfoAddressAndUnspents::new)
+ .subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribe(addressAndUnspentsObserver);
+ }
+
+ public void sendTransaction(String tx, SingleObserver sendObserver) {
+ Log.i(TAG, "new getAddress request");
+ BlockchainInfoApi api = App.Companion.getNetworkComponent().getRetrofitBlockchainInfo().create(BlockchainInfoApi.class);
+
+ Single sendObservable = api.blockchainInfoPush(tx)
+ .subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread());
+
+ sendObservable.subscribe(sendObserver);
+ }
+}
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiBlockcypher.java b/app/src/main/java/com/tangem/data/network/ServerApiBlockcypher.java
index f593b1545c..04801cf607 100644
--- a/app/src/main/java/com/tangem/data/network/ServerApiBlockcypher.java
+++ b/app/src/main/java/com/tangem/data/network/ServerApiBlockcypher.java
@@ -17,7 +17,7 @@ import retrofit2.Callback;
import retrofit2.Response;
public class ServerApiBlockcypher {
- private static String TAG = ServerApiRipple.class.getSimpleName();
+ private static String TAG = ServerApiBlockcypher.class.getSimpleName();
public static final String BLOCKCYPHER_ADDRESS = "blockcypher_address";
public static final String BLOCKCYPHER_FEE = "blockcypher_fee";
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiEos.java b/app/src/main/java/com/tangem/data/network/ServerApiEos.java
index 81f666b50b..3f207b9a10 100644
--- a/app/src/main/java/com/tangem/data/network/ServerApiEos.java
+++ b/app/src/main/java/com/tangem/data/network/ServerApiEos.java
@@ -18,7 +18,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
public class ServerApiEos {
- private static String TAG = ServerApiBinance.class.getSimpleName();
+ private static String TAG = ServerApiEos.class.getSimpleName();
public static void getBalance(String wallet, Observer accountObserver) {
Log.i(TAG, "new getBalance request");
diff --git a/app/src/main/java/com/tangem/data/network/ServerURL.java b/app/src/main/java/com/tangem/data/network/ServerURL.java
index 362e064d50..45515132d2 100644
--- a/app/src/main/java/com/tangem/data/network/ServerURL.java
+++ b/app/src/main/java/com/tangem/data/network/ServerURL.java
@@ -14,4 +14,5 @@ class ServerURL {
static final String API_MATIC_TESTNET = "https://testnet2.matic.network";
static final String API_STELLAR = "https://horizon.stellar.org/";
static final String API_STELLAR_TESTNET = "https://horizon-testnet.stellar.org";
+ static final String API_BLOCKCHAIN_INFO = "https://blockchain.info/";
}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/data/network/model/BlockchainInfoResponse.kt b/app/src/main/java/com/tangem/data/network/model/BlockchainInfoResponse.kt
new file mode 100644
index 0000000000..fab1d0c88f
--- /dev/null
+++ b/app/src/main/java/com/tangem/data/network/model/BlockchainInfoResponse.kt
@@ -0,0 +1,43 @@
+package com.tangem.data.network.model
+
+import com.google.gson.annotations.SerializedName
+
+data class BlockchainInfoAddress(
+ @SerializedName("final_balance")
+ var final_balance: Long? = null,
+
+ @SerializedName("txs")
+ var txs: List? = null
+)
+
+data class BlockchainInfoTransaction(
+ @SerializedName("hash")
+ var hash: String? = null,
+
+ @SerializedName("block_height")
+ var block_height: Long? = null
+)
+
+data class BlockchainInfoUnspents(
+ @SerializedName("unspent_outputs")
+ var unspent_outputs: List
+)
+
+data class BlockchainInfoUtxo(
+ @SerializedName("tx_hash_big_endian")
+ var tx_hash_big_endian: String? = null,
+
+ @SerializedName("tx_output_n")
+ var tx_output_n: Int? = null,
+
+ @SerializedName("value")
+ var value: Long? = null,
+
+ @SerializedName("script")
+ var script: String? = null
+)
+
+data class BlockchainInfoAddressAndUnspents(
+ var address: BlockchainInfoAddress,
+ var unspents: BlockchainInfoUnspents
+)
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/di/NetworkComponent.kt b/app/src/main/java/com/tangem/di/NetworkComponent.kt
index 06182cb4a8..62f5c62650 100644
--- a/app/src/main/java/com/tangem/di/NetworkComponent.kt
+++ b/app/src/main/java/com/tangem/di/NetworkComponent.kt
@@ -38,6 +38,9 @@ interface NetworkComponent {
@get:Named(Server.ApiSoChain.URL)
val retrofitSoChain: Retrofit
+ @get:Named(Server.ApiBlockchainInfo.URL_BLOCKCHAININFO)
+ val retrofitBlockchainInfo: Retrofit
+
@get:Named("socket")
val socket: Socket
diff --git a/app/src/main/java/com/tangem/di/NetworkModule.kt b/app/src/main/java/com/tangem/di/NetworkModule.kt
index 4f1da7af02..c5ccc558e2 100644
--- a/app/src/main/java/com/tangem/di/NetworkModule.kt
+++ b/app/src/main/java/com/tangem/di/NetworkModule.kt
@@ -18,6 +18,7 @@ import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
+import retrofit2.converter.scalars.ScalarsConverterFactory
@Module
internal class NetworkModule {
@@ -121,6 +122,20 @@ internal class NetworkModule {
return builder.build()
}
+ @Singleton
+ @Provides
+ @Named(Server.ApiBlockchainInfo.URL_BLOCKCHAININFO)
+ fun provideRetrofitBlockchainInfo(): Retrofit {
+ val builder = Retrofit.Builder()
+ .baseUrl(Server.ApiBlockchainInfo.URL_BLOCKCHAININFO)
+ .addConverterFactory(GsonConverterFactory.create())
+ .addConverterFactory(ScalarsConverterFactory.create())
+ .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
+ if (BuildConfig.DEBUG)
+ builder.client(createOkHttpClient())
+ return builder.build()
+ }
+
private fun createOkHttpClient(): OkHttpClient {
return OkHttpClient.Builder().addInterceptor(createHttpLoggingInterceptor()).build()
}
diff --git a/app/src/main/java/com/tangem/wallet/btc/BtcData.java b/app/src/main/java/com/tangem/wallet/btc/BtcData.java
index 24d82d0ed0..ba4a6da025 100644
--- a/app/src/main/java/com/tangem/wallet/btc/BtcData.java
+++ b/app/src/main/java/com/tangem/wallet/btc/BtcData.java
@@ -19,17 +19,19 @@ public class BtcData extends CoinData {
private boolean useBlockcypher = false;
+ //for blockchain.info
+ private boolean hasUnconfirmed = false;
+
public String getUnspentInputsDescription() {
try {
int gatheredUnspents = 0;
- if( unspentTransactions==null ) return "";
+ if (unspentTransactions == null) return "";
for (int i = 0; i < unspentTransactions.size(); i++) {
- if (unspentTransactions.get(i).script != null && unspentTransactions.get(i).script.length() > 1) gatheredUnspents++;
+ if (unspentTransactions.get(i).script != null && unspentTransactions.get(i).script.length() > 1)
+ gatheredUnspents++;
}
return unspentTransactions.size() + " unspents (" + gatheredUnspents + " received)";
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
return "";
}
@@ -86,6 +88,7 @@ public class BtcData extends CoinData {
}
}
if (B.containsKey("UseBlockcypher")) useBlockcypher = B.getBoolean("UseBlockcypher");
+ if (B.containsKey("HasUnconfirmed")) useBlockcypher = B.getBoolean("HasUnconfirmed");
}
@Override
@@ -102,6 +105,7 @@ public class BtcData extends CoinData {
if (balanceConfirmed != null) B.putLong("BalanceConfirmed", balanceConfirmed);
if (balanceUnconfirmed != null) B.putLong("BalanceUnconfirmed", balanceUnconfirmed);
if (useBlockcypher) B.putBoolean("UseBlockcypher", true);
+ if (hasUnconfirmed) B.putBoolean("HasUnconfirmed", true);
} catch (Exception e) {
Log.e("Can't save to bundle ", e.getMessage());
}
@@ -116,7 +120,11 @@ public class BtcData extends CoinData {
}
public CoinEngine.InternalAmount getBalanceInInternalUnits() {
- return new CoinEngine.InternalAmount(BigDecimal.valueOf(balanceConfirmed).add(BigDecimal.valueOf(balanceUnconfirmed)),"Satoshi");
+ if (balanceConfirmed != null && balanceUnconfirmed != null) {
+ return new CoinEngine.InternalAmount(BigDecimal.valueOf(balanceConfirmed).add(BigDecimal.valueOf(balanceUnconfirmed)), "Satoshi");
+ } else {
+ return null;
+ }
}
public Long getBalanceUnconfirmed() {
@@ -142,4 +150,12 @@ public class BtcData extends CoinData {
public void setUseBlockcypher(boolean useBlockcypher) {
this.useBlockcypher = useBlockcypher;
}
+
+ public boolean isHasUnconfirmed() {
+ return hasUnconfirmed;
+ }
+
+ public void setHasUnconfirmed(boolean hasUnconfirmed) {
+ this.hasUnconfirmed = hasUnconfirmed;
+ }
}
diff --git a/app/src/main/java/com/tangem/wallet/btc/BtcEngine.java b/app/src/main/java/com/tangem/wallet/btc/BtcEngine.java
index 22d1075ccc..618d42f598 100644
--- a/app/src/main/java/com/tangem/wallet/btc/BtcEngine.java
+++ b/app/src/main/java/com/tangem/wallet/btc/BtcEngine.java
@@ -12,9 +12,15 @@ import com.tangem.card_common.util.Util;
import com.tangem.data.Blockchain;
import com.tangem.data.local.PendingTransactionsStorage;
import com.tangem.data.network.Server;
+import com.tangem.data.network.ServerApiBlockchainInfo;
import com.tangem.data.network.ServerApiBlockcypher;
import com.tangem.data.network.ServerApiCommon;
import com.tangem.data.network.ServerApiSoChain;
+import com.tangem.data.network.model.BlockchainInfoAddress;
+import com.tangem.data.network.model.BlockchainInfoAddressAndUnspents;
+import com.tangem.data.network.model.BlockchainInfoTransaction;
+import com.tangem.data.network.model.BlockchainInfoUnspents;
+import com.tangem.data.network.model.BlockchainInfoUtxo;
import com.tangem.data.network.model.BlockcypherFee;
import com.tangem.data.network.model.BlockcypherResponse;
import com.tangem.data.network.model.BlockcypherTx;
@@ -33,9 +39,8 @@ import com.tangem.wallet.TangemContext;
import com.tangem.wallet.Transaction;
import com.tangem.wallet.UnspentOutputInfo;
-import org.json.JSONException;
-
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
@@ -46,6 +51,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import io.reactivex.Observer;
+import io.reactivex.SingleObserver;
+import io.reactivex.observers.DefaultObserver;
+import io.reactivex.observers.DisposableSingleObserver;
+import okhttp3.ResponseBody;
+
public class BtcEngine extends CoinEngine {
private static final String TAG = BtcEngine.class.getSimpleName();
@@ -263,7 +274,7 @@ public class BtcEngine extends CoinEngine {
// return;
// }
- if (coinData.getBalanceUnconfirmed() != 0) {
+ if (coinData.getBalanceUnconfirmed() != 0 || coinData.isHasUnconfirmed()) {
balanceValidator.setScore(0);
balanceValidator.setFirstLine("Transaction in progress");
balanceValidator.setSecondLine("Wait for confirmation in blockchain");
@@ -537,120 +548,67 @@ public class BtcEngine extends CoinEngine {
public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) throws Exception {
ctx.setError(null);
- if (!coinData.isUseBlockcypher()) {
- final ServerApiSoChain serverApiSoChain = new ServerApiSoChain();
+ //SoChain request can be found at LtcEngine
+ if (!coinData.isUseBlockcypher() && ctx.getBlockchain() != Blockchain.BitcoinTestNet) {
+ final ServerApiBlockchainInfo serverApiBlockchainInfo = new ServerApiBlockchainInfo();
- ServerApiSoChain.AddressInfoListener addressInfoListener = new ServerApiSoChain.AddressInfoListener() {
+ SingleObserver addressAndUnspentsObserver = new DisposableSingleObserver() {
@Override
- public void onSuccess(SoChain.Response.AddressBalance response) {
- try {
- String walletAddress = response.getData().getAddress();
- if (!walletAddress.equals(coinData.getWallet())) {
- // todo - check
- throw new Exception("Invalid wallet address in answer!");
- }
- Long confBalance = convertToInternalAmount(convertToAmount(response.getData().getConfirmed_balance(), getBalanceCurrency())).longValueExact();
- Long unconfirmedBalance = convertToInternalAmount(convertToAmount(response.getData().getUnconfirmed_balance(), getBalanceCurrency())).longValueExact();
+ public void onSuccess(BlockchainInfoAddressAndUnspents blockchainInfoAddressAndUnspents) {
+ BlockchainInfoAddress blockchainInfoAddress = blockchainInfoAddressAndUnspents.getAddress();
+ BlockchainInfoUnspents blockchainInfoUnspents = blockchainInfoAddressAndUnspents.getUnspents();
+
+ if (blockchainInfoAddress.getFinal_balance() != null) {
coinData.setBalanceReceived(true);
- coinData.setBalanceConfirmed(confBalance);
- coinData.setBalanceUnconfirmed(unconfirmedBalance);
- coinData.setValidationNodeDescription(Server.ApiSoChain.URL);
- } catch (JSONException e) {
- e.printStackTrace();
- Log.e(TAG, "FAIL METHOD_GetBalance JSONException");
- ctx.setError("FAIL METHOD_GetBalance JSONException");
- } catch (Exception e) {
- e.printStackTrace();
- Log.e(TAG, "FAIL METHOD_GetBalance Exception");
- ctx.setError("FAIL METHOD_GetBalance Exception");
- }
- if (serverApiSoChain.isRequestsSequenceCompleted()) {
- if (!coinData.isUseBlockcypher()) {
- checkPending(blockchainRequestsCallbacks);
- } else {
- try {
- requestBalanceAndUnspentTransactions(blockchainRequestsCallbacks);
- } catch (Exception e) {
- ctx.setError(e.getMessage());
- blockchainRequestsCallbacks.onComplete(false);
+ coinData.setBalanceConfirmed(blockchainInfoAddress.getFinal_balance());
+ coinData.setBalanceUnconfirmed(0L);
+ coinData.setValidationNodeDescription(Server.ApiBlockchainInfo.URL_BLOCKCHAININFO);
+
+ for (BlockchainInfoTransaction tx : blockchainInfoAddress.getTxs()) {
+ if (tx.getBlock_height() == null) {
+ coinData.setHasUnconfirmed(true);
+ }
+ }
+
+ if (App.pendingTransactionsStorage.hasTransactions(ctx.getCard())) {
+ for (PendingTransactionsStorage.TransactionInfo pendingTx : App.pendingTransactionsStorage.getTransactions(ctx.getCard()).getTransactions()) {
+ String pendingTxId = BTCUtils.toHex(BTCUtils.reverse(CryptoUtil.doubleSha256(BTCUtils.fromHex(pendingTx.getTx()))));
+ for (BlockchainInfoTransaction responseTx : blockchainInfoAddress.getTxs()) {
+ if (responseTx.getHash().equals(pendingTxId)) {
+ App.pendingTransactionsStorage.removeTransaction(ctx.getCard(), pendingTx.getTx());
+ }
+ }
}
}
- } else {
- blockchainRequestsCallbacks.onProgress();
}
+ for (BlockchainInfoUtxo utxo : blockchainInfoUnspents.getUnspent_outputs()) {
+ BtcData.UnspentTransaction trUnspent = new BtcData.UnspentTransaction();
+ trUnspent.txID = utxo.getTx_hash_big_endian();
+ trUnspent.amount = utxo.getValue();
+ trUnspent.outputN = utxo.getTx_output_n();
+ trUnspent.script = utxo.getScript();
+ coinData.getUnspentTransactions().add(trUnspent);
+ }
+
+ blockchainRequestsCallbacks.onComplete(true);
}
@Override
- public void onSuccess(SoChain.Response.TxUnspent response) {
- String walletAddress = response.getData().getAddress();
- try {
- if (!walletAddress.equals(coinData.getWallet())) {
- // todo - check
- throw new Exception("Invalid wallet address in answer!");
- }
- coinData.getUnspentTransactions().clear();
- if (response.getData().getTxs() != null)
- for (SoChain.Response.TxUnspent.Data.Tx tx : response.getData().getTxs()) {
- BtcData.UnspentTransaction trUnspent = new BtcData.UnspentTransaction();
- trUnspent.txID = tx.getTxid();
- trUnspent.amount = convertToInternalAmount(convertToAmount(tx.getValue(), getBalanceCurrency())).longValueExact();
- trUnspent.outputN = tx.getOutput_no();
- trUnspent.script = tx.getScript_hex();
- coinData.getUnspentTransactions().add(trUnspent);
-
-// if (blockchainRequestsCallbacks.allowAdvance()) {
-// //serverApiSoChain.requestData(ctx, ElectrumRequest.getTransaction(walletAddress, hash));
-// } else {
-// ctx.setError("Terminated by user");
-// }
- }
- } catch (Exception e) {
- e.printStackTrace();
- Log.e(TAG, "FAIL METHOD_ListUnspent JSONException");
- }
-
- if (serverApiSoChain.isRequestsSequenceCompleted()) {
- if (!coinData.isUseBlockcypher()) {
- checkPending(blockchainRequestsCallbacks);
- } else {
- try {
- requestBalanceAndUnspentTransactions(blockchainRequestsCallbacks);
- } catch (Exception e) {
- ctx.setError(e.getMessage());
- blockchainRequestsCallbacks.onComplete(false);
- }
- }
- } else {
- blockchainRequestsCallbacks.onProgress();
- }
-
- }
-
- @Override
- public void onFail(String message) {
- Log.i(TAG, "onFail: " + message);
+ public void onError(Throwable e) {
+ Log.i(TAG, "onError: getAddress" + e.getMessage());
coinData.setUseBlockcypher(true);
-// ctx.setError(R.string.cannot_obtain_data_from_blockchain);
- if (serverApiSoChain.isRequestsSequenceCompleted()) {
-// blockchainRequestsCallbacks.onComplete(false);//serverApiElectrum.isErrorOccurred(), serverApiElectrum.getError());
- try {
- requestBalanceAndUnspentTransactions(blockchainRequestsCallbacks);
- } catch (Exception e) {
- ctx.setError(e.getMessage());
- blockchainRequestsCallbacks.onComplete(false);
- }
- } else {
- blockchainRequestsCallbacks.onProgress();
+ try {
+ requestBalanceAndUnspentTransactions(blockchainRequestsCallbacks);
+ } catch (Exception ex) {
+ ctx.setError(ex.getMessage());
+ blockchainRequestsCallbacks.onComplete(false);
}
}
};
+ serverApiBlockchainInfo.getAddressAndUnspents(coinData.getWallet(), addressAndUnspentsObserver);
- serverApiSoChain.setAddressInfoListener(addressInfoListener);
-
- serverApiSoChain.requestAddressBalance(ctx.getBlockchain(), coinData.getWallet());
- serverApiSoChain.requestUnspentTx(ctx.getBlockchain(), coinData.getWallet());
} else {
final ServerApiBlockcypher serverApiBlockcypher = new ServerApiBlockcypher();
@@ -716,93 +674,48 @@ public class BtcEngine extends CoinEngine {
private void checkPending(BlockchainRequestsCallbacks blockchainRequestsCallbacks) {
if (App.pendingTransactionsStorage.hasTransactions(ctx.getCard())) {
+ ServerApiBlockcypher serverApiBlockcypher = new ServerApiBlockcypher();
- if (!coinData.isUseBlockcypher()) {
- ServerApiSoChain serverApiSoChain = new ServerApiSoChain();
-
- ServerApiSoChain.TransactionInfoListener listener = new ServerApiSoChain.TransactionInfoListener() {
- @Override
- public void onSuccess(SoChain.Response.GetTx response) {
- Log.i(TAG, "onSuccess: GetTx");
- try {
- if (response.getData() != null && response.getData().getTx_hex() != null && response.getData().getTxid() != null) {
- App.pendingTransactionsStorage.removeTransaction(ctx.getCard(), response.getData().getTx_hex());
- }
- } catch (Exception e) {
- Log.e(TAG, "onFail: GetTx" + response);
- }
- if (serverApiSoChain.isRequestsSequenceCompleted()) {
- blockchainRequestsCallbacks.onComplete(!ctx.hasError());
- } else {
- blockchainRequestsCallbacks.onProgress();
- }
- }
-
- @Override
- public void onFail(String message) {
- Log.i(TAG, "onFail: GetTx " + message);
- if (serverApiSoChain.isRequestsSequenceCompleted()) {
- blockchainRequestsCallbacks.onComplete(!ctx.hasError());//serverApiElectrum.isErrorOccurred(), serverApiElectrum.getError());
- } else {
- blockchainRequestsCallbacks.onProgress();
- }
- }
- };
-
- serverApiSoChain.setTransactionInfoListener(listener);
- for (PendingTransactionsStorage.TransactionInfo pendingTx : App.pendingTransactionsStorage.getTransactions(ctx.getCard()).getTransactions()) {
- String txId = BTCUtils.toHex(BTCUtils.reverse(CryptoUtil.doubleSha256(BTCUtils.fromHex(pendingTx.getTx()))));
+ ServerApiBlockcypher.TxResponseListener listener = new ServerApiBlockcypher.TxResponseListener() {
+ @Override
+ public void onSuccess(BlockcypherTx response) {
+ Log.i(TAG, "onSuccess: BlockcypherTx");
try {
- serverApiSoChain.requestTransactionInfo(ctx.getBlockchain(), txId);
+ if (response.getHex() != null) {
+ App.pendingTransactionsStorage.removeTransaction(ctx.getCard(), response.getHex());
+ }
} catch (Exception e) {
- e.printStackTrace();
+ Log.e(TAG, "onFail: BlockcypherTx" + response);
+ }
+ if (serverApiBlockcypher.isRequestsSequenceCompleted()) {
blockchainRequestsCallbacks.onComplete(!ctx.hasError());
+ } else {
+ blockchainRequestsCallbacks.onProgress();
}
}
- } else {
- ServerApiBlockcypher serverApiBlockcypher = new ServerApiBlockcypher();
- ServerApiBlockcypher.TxResponseListener listener = new ServerApiBlockcypher.TxResponseListener() {
-
- @Override
- public void onSuccess(BlockcypherTx response) {
- Log.i(TAG, "onSuccess: BlockcypherTx");
- try {
- if (response.getHex() != null) {
- App.pendingTransactionsStorage.removeTransaction(ctx.getCard(), response.getHex());
- }
- } catch (Exception e) {
- Log.e(TAG, "onFail: BlockcypherTx" + response);
- }
- if (serverApiBlockcypher.isRequestsSequenceCompleted()) {
- blockchainRequestsCallbacks.onComplete(!ctx.hasError());
- } else {
- blockchainRequestsCallbacks.onProgress();
- }
+ @Override
+ public void onFail(String message) {
+ Log.i(TAG, "onFail: BlockcypherTx " + message);
+ if (serverApiBlockcypher.isRequestsSequenceCompleted()) {
+ blockchainRequestsCallbacks.onComplete(!ctx.hasError());//serverApiElectrum.isErrorOccurred(), serverApiElectrum.getError());
+ } else {
+ blockchainRequestsCallbacks.onProgress();
}
+ }
+ };
+ serverApiBlockcypher.setTxResponseListener(listener);
- @Override
- public void onFail(String message) {
- Log.i(TAG, "onFail: BlockcypherTx " + message);
- if (serverApiBlockcypher.isRequestsSequenceCompleted()) {
- blockchainRequestsCallbacks.onComplete(!ctx.hasError());//serverApiElectrum.isErrorOccurred(), serverApiElectrum.getError());
- } else {
- blockchainRequestsCallbacks.onProgress();
- }
- }
- };
- serverApiBlockcypher.setTxResponseListener(listener);
-
- for (PendingTransactionsStorage.TransactionInfo pendingTx : App.pendingTransactionsStorage.getTransactions(ctx.getCard()).getTransactions()) {
- String txId = BTCUtils.toHex(BTCUtils.reverse(CryptoUtil.doubleSha256(BTCUtils.fromHex(pendingTx.getTx()))));
- try {
- serverApiBlockcypher.requestData(ctx.getBlockchain().getID(), ServerApiBlockcypher.BLOCKCYPHER_TXS, "", txId);
- } catch (Exception e) {
- e.printStackTrace();
- blockchainRequestsCallbacks.onComplete(!ctx.hasError());
- }
+ for (PendingTransactionsStorage.TransactionInfo pendingTx : App.pendingTransactionsStorage.getTransactions(ctx.getCard()).getTransactions()) {
+ String txId = BTCUtils.toHex(BTCUtils.reverse(CryptoUtil.doubleSha256(BTCUtils.fromHex(pendingTx.getTx()))));
+ try {
+ serverApiBlockcypher.requestData(ctx.getBlockchain().getID(), ServerApiBlockcypher.BLOCKCYPHER_TXS, "", txId);
+ } catch (Exception e) {
+ e.printStackTrace();
+ blockchainRequestsCallbacks.onComplete(!ctx.hasError());
}
}
+
} else {
blockchainRequestsCallbacks.onComplete(!ctx.hasError());
}
@@ -1026,42 +939,40 @@ public class BtcEngine extends CoinEngine {
@Override
public void requestSendTransaction(BlockchainRequestsCallbacks blockchainRequestsCallbacks, byte[] txForSend) throws Exception {
final String txStr = BTCUtils.toHex(txForSend);
- if (!coinData.isUseBlockcypher()) {
- final ServerApiSoChain serverApiSoChain = new ServerApiSoChain();
- ServerApiSoChain.SendTxListener listener = new ServerApiSoChain.SendTxListener() {
+ //SoChain request can be found at LtcEngine
+ if (!coinData.isUseBlockcypher()) {
+ final ServerApiBlockchainInfo serverApiBlockchainInfo = new ServerApiBlockchainInfo();
+
+ SingleObserver responseObserver = new DisposableSingleObserver() {
@Override
- public void onSuccess(SoChain.Response.SendTx response) {
+ public void onSuccess(ResponseBody response) {
try {
- if (response.getStatus() == null || response.getData() == null) {
- ctx.setError("Rejected by node: invalid answer received");
- blockchainRequestsCallbacks.onComplete(false);
- } else if (response.getStatus().equals("fail") || response.getData().getTxid() == null) {
- ctx.setError("Rejected by node: " + response.getData());
- blockchainRequestsCallbacks.onComplete(false);
- } else {
- ctx.setError(null);
- blockchainRequestsCallbacks.onComplete(true);
- }
- } catch (Exception e) {
- if (e.getMessage() != null) {
- ctx.setError(e.getMessage());
- blockchainRequestsCallbacks.onComplete(false);
- } else {
- ctx.setError(e.getClass().getName());
- blockchainRequestsCallbacks.onComplete(false);
+ Log.i(TAG, response.string());
+ if (!response.string().equals("Transaction Submitted")) {
+ ctx.setError(response.string());
}
+ } catch (IOException e) {
+ e.printStackTrace();
+ ctx.setError(e.getMessage());
+ }
+
+ if (ctx.hasError()) {
+ blockchainRequestsCallbacks.onComplete(false);
+ } else {
+ blockchainRequestsCallbacks.onComplete(true);
}
}
@Override
- public void onFail(String message) {
- ctx.setError(message);
+ public void onError(Throwable e) {
+ Log.e(TAG, e.getMessage());
+ ctx.setError(e.getMessage());
blockchainRequestsCallbacks.onComplete(false);
}
};
- serverApiSoChain.setSendTxListener(listener);
- serverApiSoChain.requestSendTransaction(ctx.getBlockchain(), txStr);
+
+ serverApiBlockchainInfo.sendTransaction(txStr, responseObserver);
} else {
final ServerApiBlockcypher serverApiBlockcypher = new ServerApiBlockcypher();
diff --git a/app/src/main/java/com/tangem/wallet/ltc/LtcEngine.java b/app/src/main/java/com/tangem/wallet/ltc/LtcEngine.java
index 680c112119..b8b581bd36 100644
--- a/app/src/main/java/com/tangem/wallet/ltc/LtcEngine.java
+++ b/app/src/main/java/com/tangem/wallet/ltc/LtcEngine.java
@@ -2,7 +2,18 @@ package com.tangem.wallet.ltc;
import android.net.Uri;
import android.text.InputFilter;
+import android.util.Log;
+import com.tangem.App;
+import com.tangem.data.local.PendingTransactionsStorage;
+import com.tangem.data.network.Server;
+import com.tangem.data.network.ServerApiBlockcypher;
+import com.tangem.data.network.ServerApiSoChain;
+import com.tangem.data.network.model.BlockcypherFee;
+import com.tangem.data.network.model.BlockcypherResponse;
+import com.tangem.data.network.model.BlockcypherTx;
+import com.tangem.data.network.model.BlockcypherTxref;
+import com.tangem.data.network.model.SoChain;
import com.tangem.wallet.BTCUtils;
import com.tangem.wallet.BalanceValidator;
import com.tangem.wallet.Base58;
@@ -21,6 +32,8 @@ import com.tangem.util.DecimalDigitsInputFilter;
import com.tangem.util.DerEncodingUtil;
import com.tangem.wallet.R;
+import org.json.JSONException;
+
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -478,6 +491,281 @@ public class LtcEngine extends BtcEngine {
};
}
+ @Override
+ public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) throws Exception {
+ ctx.setError(null);
+
+ if (!coinData.isUseBlockcypher()) {
+ final ServerApiSoChain serverApiSoChain = new ServerApiSoChain();
+
+ ServerApiSoChain.AddressInfoListener addressInfoListener = new ServerApiSoChain.AddressInfoListener() {
+ @Override
+ public void onSuccess(SoChain.Response.AddressBalance response) {
+ try {
+ String walletAddress = response.getData().getAddress();
+ if (!walletAddress.equals(coinData.getWallet())) {
+ // todo - check
+ throw new Exception("Invalid wallet address in answer!");
+ }
+ Long confBalance = convertToInternalAmount(convertToAmount(response.getData().getConfirmed_balance(), getBalanceCurrency())).longValueExact();
+ Long unconfirmedBalance = convertToInternalAmount(convertToAmount(response.getData().getUnconfirmed_balance(), getBalanceCurrency())).longValueExact();
+ coinData.setBalanceReceived(true);
+ coinData.setBalanceConfirmed(confBalance);
+ coinData.setBalanceUnconfirmed(unconfirmedBalance);
+ coinData.setValidationNodeDescription(Server.ApiSoChain.URL);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ Log.e(TAG, "FAIL METHOD_GetBalance JSONException");
+ ctx.setError("FAIL METHOD_GetBalance JSONException");
+ } catch (Exception e) {
+ e.printStackTrace();
+ Log.e(TAG, "FAIL METHOD_GetBalance Exception");
+ ctx.setError("FAIL METHOD_GetBalance Exception");
+ }
+ if (serverApiSoChain.isRequestsSequenceCompleted()) {
+ if (!coinData.isUseBlockcypher()) {
+ checkPending(blockchainRequestsCallbacks);
+ } else {
+ try {
+ requestBalanceAndUnspentTransactions(blockchainRequestsCallbacks);
+ } catch (Exception e) {
+ ctx.setError(e.getMessage());
+ blockchainRequestsCallbacks.onComplete(false);
+ }
+ }
+ } else {
+ blockchainRequestsCallbacks.onProgress();
+ }
+
+ }
+
+ @Override
+ public void onSuccess(SoChain.Response.TxUnspent response) {
+ String walletAddress = response.getData().getAddress();
+ try {
+ if (!walletAddress.equals(coinData.getWallet())) {
+ // todo - check
+ throw new Exception("Invalid wallet address in answer!");
+ }
+ coinData.getUnspentTransactions().clear();
+ if (response.getData().getTxs() != null)
+ for (SoChain.Response.TxUnspent.Data.Tx tx : response.getData().getTxs()) {
+ BtcData.UnspentTransaction trUnspent = new BtcData.UnspentTransaction();
+ trUnspent.txID = tx.getTxid();
+ trUnspent.amount = convertToInternalAmount(convertToAmount(tx.getValue(), getBalanceCurrency())).longValueExact();
+ trUnspent.outputN = tx.getOutput_no();
+ trUnspent.script = tx.getScript_hex();
+ coinData.getUnspentTransactions().add(trUnspent);
+
+// if (blockchainRequestsCallbacks.allowAdvance()) {
+// //serverApiSoChain.requestData(ctx, ElectrumRequest.getTransaction(walletAddress, hash));
+// } else {
+// ctx.setError("Terminated by user");
+// }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Log.e(TAG, "FAIL METHOD_ListUnspent JSONException");
+ }
+
+ if (serverApiSoChain.isRequestsSequenceCompleted()) {
+ if (!coinData.isUseBlockcypher()) {
+ checkPending(blockchainRequestsCallbacks);
+ } else {
+ try {
+ requestBalanceAndUnspentTransactions(blockchainRequestsCallbacks);
+ } catch (Exception e) {
+ ctx.setError(e.getMessage());
+ blockchainRequestsCallbacks.onComplete(false);
+ }
+ }
+ } else {
+ blockchainRequestsCallbacks.onProgress();
+ }
+
+ }
+
+ @Override
+ public void onFail(String message) {
+ Log.i(TAG, "onFail: " + message);
+ coinData.setUseBlockcypher(true);
+// ctx.setError(R.string.cannot_obtain_data_from_blockchain);
+ if (serverApiSoChain.isRequestsSequenceCompleted()) {
+// blockchainRequestsCallbacks.onComplete(false);//serverApiElectrum.isErrorOccurred(), serverApiElectrum.getError());
+ try {
+ requestBalanceAndUnspentTransactions(blockchainRequestsCallbacks);
+ } catch (Exception e) {
+ ctx.setError(e.getMessage());
+ blockchainRequestsCallbacks.onComplete(false);
+ }
+ } else {
+ blockchainRequestsCallbacks.onProgress();
+ }
+ }
+ };
+
+
+ serverApiSoChain.setAddressInfoListener(addressInfoListener);
+
+ serverApiSoChain.requestAddressBalance(ctx.getBlockchain(), coinData.getWallet());
+ serverApiSoChain.requestUnspentTx(ctx.getBlockchain(), coinData.getWallet());
+ } else {
+ final ServerApiBlockcypher serverApiBlockcypher = new ServerApiBlockcypher();
+
+ ServerApiBlockcypher.ResponseListener blockcypherListener = new ServerApiBlockcypher.ResponseListener() {
+ @Override
+ public void onSuccess(String method, BlockcypherResponse blockcypherResponse) {
+ Log.i(TAG, "onSuccess: " + method);
+ try {
+ String walletAddress = blockcypherResponse.getAddress();
+ if (!walletAddress.equals(coinData.getWallet())) {
+ // todo - check
+ throw new Exception("Invalid wallet address in answer!");
+ }
+ Long confBalance = blockcypherResponse.getBalance();
+ Long unconfirmedBalance = blockcypherResponse.getUnconfirmed_balance();
+ coinData.setBalanceReceived(true);
+ coinData.setBalanceConfirmed(confBalance);
+ coinData.setBalanceUnconfirmed(unconfirmedBalance);
+ coinData.setValidationNodeDescription(Server.ApiBlockcypher.URL_BLOCKCYPHER);
+
+ coinData.getUnspentTransactions().clear();
+ if (blockcypherResponse.getTxrefs() != null) {
+ for (BlockcypherTxref txref : blockcypherResponse.getTxrefs()) {
+ BtcData.UnspentTransaction trUnspent = new BtcData.UnspentTransaction();
+ trUnspent.txID = txref.getTx_hash();
+ trUnspent.amount = txref.getValue();
+ trUnspent.outputN = txref.getTx_output_n();
+ trUnspent.script = txref.getScript();
+ coinData.getUnspentTransactions().add(trUnspent);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Log.e(TAG, "FAIL BLOCKCYPHER_ADDRESS Exception");
+ }
+
+ if (serverApiBlockcypher.isRequestsSequenceCompleted()) {
+ checkPending(blockchainRequestsCallbacks);
+ } else {
+ blockchainRequestsCallbacks.onProgress();
+ }
+ }
+
+ public void onSuccess(String method, BlockcypherFee blockcypherFee) {
+ Log.e(TAG, "Wrong response type for requestBalanceAndUnspentTransactions");
+ ctx.setError("Wrong response type for requestBalanceAndUnspentTransactions");
+ blockchainRequestsCallbacks.onComplete(false);
+ }
+
+ @Override
+ public void onFail(String method, String message) {
+ Log.i(TAG, "onFail: " + method + " " + message);
+ ctx.setError(message);
+ blockchainRequestsCallbacks.onComplete(false);
+ }
+ };
+
+ serverApiBlockcypher.setResponseListener(blockcypherListener);
+
+ serverApiBlockcypher.requestData(ctx.getBlockchain().getID(), ServerApiBlockcypher.BLOCKCYPHER_ADDRESS, ctx.getCoinData().getWallet(), "");
+ }
+ }
+
+ private void checkPending(BlockchainRequestsCallbacks blockchainRequestsCallbacks) {
+ if (App.pendingTransactionsStorage.hasTransactions(ctx.getCard())) {
+
+ if (!coinData.isUseBlockcypher()) {
+ ServerApiSoChain serverApiSoChain = new ServerApiSoChain();
+
+ ServerApiSoChain.TransactionInfoListener listener = new ServerApiSoChain.TransactionInfoListener() {
+ @Override
+ public void onSuccess(SoChain.Response.GetTx response) {
+ Log.i(TAG, "onSuccess: GetTx");
+ try {
+ if (response.getData() != null && response.getData().getTx_hex() != null && response.getData().getTxid() != null) {
+ App.pendingTransactionsStorage.removeTransaction(ctx.getCard(), response.getData().getTx_hex());
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "onFail: GetTx" + response);
+ }
+ if (serverApiSoChain.isRequestsSequenceCompleted()) {
+ blockchainRequestsCallbacks.onComplete(!ctx.hasError());
+ } else {
+ blockchainRequestsCallbacks.onProgress();
+ }
+ }
+
+ @Override
+ public void onFail(String message) {
+ Log.i(TAG, "onFail: GetTx " + message);
+ if (serverApiSoChain.isRequestsSequenceCompleted()) {
+ blockchainRequestsCallbacks.onComplete(!ctx.hasError());//serverApiElectrum.isErrorOccurred(), serverApiElectrum.getError());
+ } else {
+ blockchainRequestsCallbacks.onProgress();
+ }
+ }
+ };
+
+ serverApiSoChain.setTransactionInfoListener(listener);
+ for (PendingTransactionsStorage.TransactionInfo pendingTx : App.pendingTransactionsStorage.getTransactions(ctx.getCard()).getTransactions()) {
+ String txId = BTCUtils.toHex(BTCUtils.reverse(CryptoUtil.doubleSha256(BTCUtils.fromHex(pendingTx.getTx()))));
+ try {
+ serverApiSoChain.requestTransactionInfo(ctx.getBlockchain(), txId);
+ } catch (Exception e) {
+ e.printStackTrace();
+ blockchainRequestsCallbacks.onComplete(!ctx.hasError());
+ }
+ }
+ } else {
+ ServerApiBlockcypher serverApiBlockcypher = new ServerApiBlockcypher();
+
+ ServerApiBlockcypher.TxResponseListener listener = new ServerApiBlockcypher.TxResponseListener() {
+
+ @Override
+ public void onSuccess(BlockcypherTx response) {
+ Log.i(TAG, "onSuccess: BlockcypherTx");
+ try {
+ if (response.getHex() != null) {
+ App.pendingTransactionsStorage.removeTransaction(ctx.getCard(), response.getHex());
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "onFail: BlockcypherTx" + response);
+ }
+ if (serverApiBlockcypher.isRequestsSequenceCompleted()) {
+ blockchainRequestsCallbacks.onComplete(!ctx.hasError());
+ } else {
+ blockchainRequestsCallbacks.onProgress();
+ }
+ }
+
+ @Override
+ public void onFail(String message) {
+ Log.i(TAG, "onFail: BlockcypherTx " + message);
+ if (serverApiBlockcypher.isRequestsSequenceCompleted()) {
+ blockchainRequestsCallbacks.onComplete(!ctx.hasError());//serverApiElectrum.isErrorOccurred(), serverApiElectrum.getError());
+ } else {
+ blockchainRequestsCallbacks.onProgress();
+ }
+ }
+ };
+ serverApiBlockcypher.setTxResponseListener(listener);
+
+ for (PendingTransactionsStorage.TransactionInfo pendingTx : App.pendingTransactionsStorage.getTransactions(ctx.getCard()).getTransactions()) {
+ String txId = BTCUtils.toHex(BTCUtils.reverse(CryptoUtil.doubleSha256(BTCUtils.fromHex(pendingTx.getTx()))));
+ try {
+ serverApiBlockcypher.requestData(ctx.getBlockchain().getID(), ServerApiBlockcypher.BLOCKCYPHER_TXS, "", txId);
+ } catch (Exception e) {
+ e.printStackTrace();
+ blockchainRequestsCallbacks.onComplete(!ctx.hasError());
+ }
+ }
+ }
+ } else {
+ blockchainRequestsCallbacks.onComplete(!ctx.hasError());
+ }
+ }
+
private final static BigDecimal relayFee = new BigDecimal(0.00001).setScale(8, RoundingMode.DOWN);
@Override
@@ -486,6 +774,92 @@ public class LtcEngine extends BtcEngine {
blockchainRequestsCallbacks.onComplete(true);
}
+ @Override
+ public void requestSendTransaction(BlockchainRequestsCallbacks blockchainRequestsCallbacks, byte[] txForSend) throws Exception {
+ final String txStr = BTCUtils.toHex(txForSend);
+ if (!coinData.isUseBlockcypher()) {
+ final ServerApiSoChain serverApiSoChain = new ServerApiSoChain();
+
+ ServerApiSoChain.SendTxListener listener = new ServerApiSoChain.SendTxListener() {
+ @Override
+ public void onSuccess(SoChain.Response.SendTx response) {
+ try {
+ if (response.getStatus() == null || response.getData() == null) {
+ ctx.setError("Rejected by node: invalid answer received");
+ blockchainRequestsCallbacks.onComplete(false);
+ } else if (response.getStatus().equals("fail") || response.getData().getTxid() == null) {
+ ctx.setError("Rejected by node: " + response.getData());
+ blockchainRequestsCallbacks.onComplete(false);
+ } else {
+ ctx.setError(null);
+ blockchainRequestsCallbacks.onComplete(true);
+ }
+ } catch (Exception e) {
+ if (e.getMessage() != null) {
+ ctx.setError(e.getMessage());
+ blockchainRequestsCallbacks.onComplete(false);
+ } else {
+ ctx.setError(e.getClass().getName());
+ blockchainRequestsCallbacks.onComplete(false);
+ }
+ }
+ }
+
+ @Override
+ public void onFail(String message) {
+ ctx.setError(message);
+ blockchainRequestsCallbacks.onComplete(false);
+ }
+ };
+ serverApiSoChain.setSendTxListener(listener);
+ serverApiSoChain.requestSendTransaction(ctx.getBlockchain(), txStr);
+
+ } else {
+ final ServerApiBlockcypher serverApiBlockcypher = new ServerApiBlockcypher();
+
+ ServerApiBlockcypher.ResponseListener blockcypherListener = new ServerApiBlockcypher.ResponseListener() {
+ @Override
+ public void onSuccess(String method, BlockcypherResponse blockcypherResponse) {
+ String resultString = blockcypherResponse.toString();
+ try {
+ if (resultString.isEmpty()) {
+ ctx.setError("No response from node");
+ blockchainRequestsCallbacks.onComplete(false);
+ } else { // TODO: Make check for a valid send response
+ ctx.setError(null);
+ blockchainRequestsCallbacks.onComplete(true);
+ }
+ } catch (Exception e) {
+ if (e.getMessage() != null) {
+ ctx.setError(e.getMessage());
+ blockchainRequestsCallbacks.onComplete(false);
+ } else {
+ ctx.setError(e.getClass().getName());
+ blockchainRequestsCallbacks.onComplete(false);
+ Log.e(TAG, resultString);
+ }
+ }
+ }
+
+ public void onSuccess(String method, BlockcypherFee blockcypherFee) {
+ Log.e(TAG, "Wrong response type for requestSendTransaction");
+ ctx.setError("Wrong response type for requestSendTransaction");
+ blockchainRequestsCallbacks.onComplete(false);
+ }
+
+ @Override
+ public void onFail(String method, String message) {
+ Log.i(TAG, "onFail: " + method + " " + message);
+ ctx.setError(message);
+ blockchainRequestsCallbacks.onComplete(false);
+ }
+ };
+ serverApiBlockcypher.setResponseListener(blockcypherListener);
+
+ serverApiBlockcypher.requestData(ctx.getBlockchain().getID(), ServerApiBlockcypher.BLOCKCYPHER_SEND, "", txStr);
+ }
+ }
+
@Override
public boolean allowSelectFeeLevel() {
return false;
diff --git a/build.gradle b/build.gradle
index 868717e1b8..0a6c7bd4a5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ buildscript {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.4.2'
+ classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'io.fabric.tools:gradle:1.27.1'
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 662c6f9706..212388dbad 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Thu Apr 18 12:21:12 MSK 2019
+#Wed Aug 21 11:57:23 MSK 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip