sendObservable = Observable.just(new PushedTransaction())
- .map(pushedTransaction -> EosApiServiceGenerator.executeSync(eosApiPush.pushTransaction(req)))
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread());
-
- sendObservable.subscribe(sendObserver);
- }
-
-}
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiInfura.java b/app/src/main/java/com/tangem/data/network/ServerApiInfura.java
deleted file mode 100644
index 29ded17af1..0000000000
--- a/app/src/main/java/com/tangem/data/network/ServerApiInfura.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package com.tangem.data.network;
-
-import android.util.Log;
-
-import androidx.annotation.NonNull;
-
-import com.tangem.App;
-import com.tangem.data.Blockchain;
-import com.tangem.data.network.model.InfuraBody;
-import com.tangem.data.network.model.InfuraResponse;
-
-import retrofit2.Call;
-import retrofit2.Callback;
-import retrofit2.Response;
-
-public class ServerApiInfura {
- private static String TAG = ServerApiInfura.class.getSimpleName();
-
- /**
- * HTTP
- * Infura
- *
- * eth_getBalance
- * eth_getTransactionCount
- * eth_call
- * eth_sendRawTransaction
- * eth_gasPrice
- */
- public static final String INFURA_ETH_GET_BALANCE = "eth_getBalance";
- public static final String INFURA_ETH_GET_TRANSACTION_COUNT = "eth_getTransactionCount";
- public static final String INFURA_ETH_GET_PENDING_COUNT = "eth_getPendingCount";
- public static final String INFURA_ETH_CALL = "eth_call";
- public static final String INFURA_ETH_SEND_RAW_TRANSACTION = "eth_sendRawTransaction";
- public static final String INFURA_ETH_GAS_PRICE = "eth_gasPrice";
-
- private int requestsCount=0;
-
- private InfuraApi infuraApi = App.Companion.getNetworkComponent().getRetrofitInfura().create(InfuraApi.class);
-
- public ServerApiInfura() {}
-
- public ServerApiInfura(Blockchain blockchain) {
- if (blockchain == Blockchain.EthereumTestNet) {
- infuraApi = App.Companion.getNetworkComponent().getRetrofitInfuraTestnet().create(InfuraApi.class);
- } else if (blockchain == Blockchain.TokenEmv) {
- infuraApi = App.Companion.getNetworkComponent().getRetrofitInfuraRopsten().create(InfuraApi.class);
- }
- }
-
- public boolean isRequestsSequenceCompleted() {
- Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
- return requestsCount <= 0;
- }
-
- private ResponseListener responseListener;
-
- public interface ResponseListener {
- void onSuccess(String method, InfuraResponse infuraResponse);
-
- void onFail(String method, String message);
- }
-
- public void setResponseListener(ResponseListener listener) {
- responseListener = listener;
- }
-
- public void requestData(String method, int id, String wallet, String contract, String tx) {
- requestsCount++;
-
-
- InfuraBody infuraBody;
- switch (method) {
- case INFURA_ETH_GET_BALANCE:
- case INFURA_ETH_GET_TRANSACTION_COUNT:
- infuraBody = new InfuraBody(method, new String[]{wallet, "latest"}, id);
- break;
- case INFURA_ETH_GET_PENDING_COUNT:
- infuraBody = new InfuraBody(INFURA_ETH_GET_TRANSACTION_COUNT, new String[]{wallet, "pending"}, id);
- break;
- case INFURA_ETH_CALL:
- String address = wallet.substring(2);
- infuraBody = new InfuraBody(method, new Object[]{new InfuraBody.EthCallParams("0x70a08231000000000000000000000000" + address, contract), "latest"}, id);
- break;
-
- case INFURA_ETH_SEND_RAW_TRANSACTION:
- infuraBody = new InfuraBody(method, new String[]{tx}, id);
- break;
-
- case INFURA_ETH_GAS_PRICE:
- infuraBody = new InfuraBody(method, id);
- break;
-
- default:
- infuraBody = new InfuraBody();
- }
-
- Call call = infuraApi.infura(infuraBody);
- call.enqueue(new Callback() {
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) {
- requestsCount--;
-
- if (response.code() == 200) {
- responseListener.onSuccess(method, response.body());
- Log.i(TAG, "requestData " + method + " onResponse " + response.code());
- } else {
- responseListener.onFail(method, String.valueOf(response.code()));
- Log.e(TAG, "requestData " + method + " onResponse " + response.code());
- }
- }
-
- @Override
- public void onFailure(@NonNull Call call, @NonNull Throwable t) {
- requestsCount--;
- responseListener.onFail(method, String.valueOf(t.getMessage()));
- Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
- }
- });
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiInsight.java b/app/src/main/java/com/tangem/data/network/ServerApiInsight.java
deleted file mode 100644
index 5a768471e6..0000000000
--- a/app/src/main/java/com/tangem/data/network/ServerApiInsight.java
+++ /dev/null
@@ -1,131 +0,0 @@
-package com.tangem.data.network;
-
-import android.util.Log;
-
-import androidx.annotation.NonNull;
-
-import com.tangem.data.network.model.InsightBody;
-import com.tangem.data.network.model.InsightResponse;
-import com.tangem.data.network.model.InsightUtxo;
-
-import java.util.List;
-
-import retrofit2.Call;
-import retrofit2.Callback;
-import retrofit2.Response;
-import retrofit2.Retrofit;
-import retrofit2.converter.gson.GsonConverterFactory;
-
-public class ServerApiInsight {
- private static String TAG = ServerApiInsight.class.getSimpleName();
-
- public static final String INSIGHT_ADDRESS = "addr/{address}";
- public static final String INSIGHT_UNSPENT_OUTPUTS = "addr/{address}/utxo";
- public static final String INSIGHT_TRANSACTION = "rawtx/{txId}";
- public static final String INSIGHT_FEE = "utils/estimatefee?nbBlocks=2,3,6";
- public static final String INSIGHT_SEND = "tx/send";
-
- private int requestsCount = 0;
-
- public static String lastNode;
-
- public boolean isRequestsSequenceCompleted() {
- Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
- return requestsCount <= 0;
- }
-
- private ResponseListener responseListener;
-
- public interface ResponseListener {
- void onSuccess(String method, InsightResponse insightResponse);
-
- void onSuccess(String method, List utxoList);
-
- void onFail(String method, String message);
- }
-
- public void setResponseListener(ResponseListener listener) {
- responseListener = listener;
- }
-
- public void requestData(String method, String wallet, String tx) {
- requestsCount++;
- String insightURL = "https://insight.ducatus.io/insight-lite-api/"; //TODO: make random selection
- this.lastNode = insightURL; //TODO: show node instead of URL
-
- Retrofit retrofitInsight = new Retrofit.Builder()
- .baseUrl(insightURL)
- .addConverterFactory(GsonConverterFactory.create())
- .build();
-
-// InsightApi insightApi = App.getNetworkComponent().getRetrofitInsight(insightURL).create(InsightApi.class);
- InsightApi insightApi = retrofitInsight.create(InsightApi.class);
-
- if (method.equals(INSIGHT_UNSPENT_OUTPUTS)) {
- Call> call = insightApi.insightUnspent(wallet);
- call.enqueue(new Callback>() {
- @Override
- public void onResponse(@NonNull Call> call, @NonNull Response> response) {
- requestsCount--;
-
- if (response.code() == 200) {
- responseListener.onSuccess(method, response.body());
- Log.i(TAG, "requestData " + method + " onResponse " + response.code());
- } else {
- responseListener.onFail(method, String.valueOf(response.code()));
- Log.e(TAG, "requestData " + method + " onResponse " + response.code());
- }
- }
-
- @Override
- public void onFailure(@NonNull Call> call, @NonNull Throwable t) {
- requestsCount--;
- responseListener.onFail(method, String.valueOf(t.getMessage()));
- Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
- }
- });
-
- } else {
- Call call;
-
- switch (method) {
- case INSIGHT_ADDRESS:
- call = insightApi.insightAddress(wallet);
- break;
-
-// case INSIGHT_FEE:
-// call = insightApi.insightFee();
-// break;
-
- case INSIGHT_SEND:
- call = insightApi.insightSend(new InsightBody(tx));
- break;
-
- default:
- call = insightApi.insightAddress(wallet);
- break;
- }
- call.enqueue(new Callback() {
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) {
- requestsCount--;
-
- if (response.code() == 200) {
- responseListener.onSuccess(method, response.body());
- Log.i(TAG, "requestData " + method + " onResponse " + response.code());
- } else {
- responseListener.onFail(method, String.valueOf(response.code()));
- Log.e(TAG, "requestData " + method + " onResponse " + response.code());
- }
- }
-
- @Override
- public void onFailure(@NonNull Call call, @NonNull Throwable t) {
- requestsCount--;
- responseListener.onFail(method, String.valueOf(t.getMessage()));
- Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
- }
- });
- }
- }
-}
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiMatic.java b/app/src/main/java/com/tangem/data/network/ServerApiMatic.java
deleted file mode 100644
index 448fa02fc6..0000000000
--- a/app/src/main/java/com/tangem/data/network/ServerApiMatic.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package com.tangem.data.network;
-
-import android.util.Log;
-
-import androidx.annotation.NonNull;
-
-import com.tangem.App;
-import com.tangem.data.network.model.InfuraBody;
-import com.tangem.data.network.model.InfuraResponse;
-
-import retrofit2.Call;
-import retrofit2.Callback;
-import retrofit2.Response;
-
-public class ServerApiMatic {
- private static String TAG = ServerApiMatic.class.getSimpleName();
-
- /**
- * HTTP
- * Infura
- *
- * eth_getBalance
- * eth_getTransactionCount
- * eth_call
- * eth_sendRawTransaction
- * eth_gasPrice
- */
- public static final String MATIC_ETH_GET_BALANCE = "eth_getBalance";
- public static final String MATIC_ETH_GET_TRANSACTION_COUNT = "eth_getTransactionCount";
- public static final String MATIC_ETH_GET_PENDING_COUNT = "eth_getPendingCount";
- public static final String MATIC_ETH_CALL = "eth_call";
- public static final String MATIC_ETH_SEND_RAW_TRANSACTION = "eth_sendRawTransaction";
- public static final String MATIC_ETH_GAS_PRICE = "eth_gasPrice";
-
- private int requestsCount=0;
-
- public boolean isRequestsSequenceCompleted() {
- Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
- return requestsCount <= 0;
- }
-
- private ResponseListener responseListener;
-
- public interface ResponseListener {
- void onSuccess(String method, InfuraResponse infuraResponse);
-
- void onFail(String method, String message);
- }
-
- public void setResponseListener(ResponseListener listener) {
- responseListener = listener;
- }
-
- public void requestData(String method, int id, String wallet, String contract, String tx) {
- requestsCount++;
- MaticApi maticApi = App.Companion.getNetworkComponent().getRetrofitMaticTesnet().create(MaticApi.class);
-
- InfuraBody infuraBody;
- switch (method) {
- case MATIC_ETH_GET_BALANCE:
- case MATIC_ETH_GET_TRANSACTION_COUNT:
- infuraBody = new InfuraBody(method, new String[]{wallet, "latest"}, id);
- break;
- case MATIC_ETH_GET_PENDING_COUNT:
- infuraBody = new InfuraBody(MATIC_ETH_GET_TRANSACTION_COUNT, new String[]{wallet, "pending"}, id);
- break;
- case MATIC_ETH_CALL:
- String address = wallet.substring(2);
- infuraBody = new InfuraBody(method, new Object[]{new InfuraBody.EthCallParams("0x70a08231000000000000000000000000" + address, contract), "latest"}, id);
- break;
-
- case MATIC_ETH_SEND_RAW_TRANSACTION:
- infuraBody = new InfuraBody(method, new String[]{tx}, id);
- break;
-
- case MATIC_ETH_GAS_PRICE:
- infuraBody = new InfuraBody(method, id);
- break;
-
- default:
- infuraBody = new InfuraBody();
- }
-
- Call call = maticApi.matic(infuraBody);
- call.enqueue(new Callback() {
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) {
- requestsCount--;
-
- if (response.code() == 200) {
- responseListener.onSuccess(method, response.body());
- Log.i(TAG, "requestData " + method + " onResponse " + response.code());
- } else {
- responseListener.onFail(method, String.valueOf(response.code()));
- Log.e(TAG, "requestData " + method + " onResponse " + response.code());
- }
- }
-
- @Override
- public void onFailure(@NonNull Call call, @NonNull Throwable t) {
- requestsCount--;
- responseListener.onFail(method, String.valueOf(t.getMessage()));
- Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
- }
- });
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiPayId.java b/app/src/main/java/com/tangem/data/network/ServerApiPayId.java
deleted file mode 100644
index 03a8a03a68..0000000000
--- a/app/src/main/java/com/tangem/data/network/ServerApiPayId.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package com.tangem.data.network;
-
-import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
-import com.tangem.data.Blockchain;
-import com.tangem.data.network.model.PayIdResponse;
-import com.tangem.tangem_card.util.Log;
-
-import java.security.InvalidParameterException;
-
-import io.reactivex.Single;
-import io.reactivex.SingleObserver;
-import io.reactivex.android.schedulers.AndroidSchedulers;
-import io.reactivex.schedulers.Schedulers;
-import retrofit2.Retrofit;
-import retrofit2.converter.gson.GsonConverterFactory;
-
-public class ServerApiPayId {
- private static String TAG = ServerApiPayId.class.getSimpleName();
-
- private int requestsCount = 0;
-
- public String getAcceptHeader(Blockchain blockchain) throws InvalidParameterException {
- switch (blockchain) {
- case Ripple: return "application/xrpl-mainnet+json";
- case Bitcoin: return "application/btc-mainnet+json";
- case Litecoin: return "application/ltc-mainnet+json";
- case Cardano: return "application/ada-mainnet+json";
- case Ducatus: return "application/duc-mainnet+json";
- case BitcoinCash: return "application/bch-mainnet+json";
- case Ethereum:
- case Token:
- return "application/eth-mainnet+json";
- case Stellar:
- case StellarAsset:
- return "application/xlm-mainnet+json";
- case Binance:
- case BinanceAsset:
- return "application/bnb-mainnet+json";
- case Rootstock:
- case RootstockToken:
- return "application/rsk-mainnet+json";
- default: throw new InvalidParameterException("PayID is not supported for " + blockchain.getOfficialName());
- }
- }
-
- public boolean isRequestsSequenceCompleted() {
- Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
- return requestsCount <= 0;
- }
-
- public void getAddress(String payID, Blockchain blockchain, SingleObserver addressObserver) throws InvalidParameterException {
- requestsCount++;
- Log.i(TAG, "new getAddress request");
-
- String[] addressParts = payID.split("\\$");
- String user = addressParts[0];
- String domain = addressParts[1];
-
- Retrofit retrofit = new Retrofit.Builder()
- .baseUrl("https://" + domain + "/")
- .addConverterFactory(GsonConverterFactory.create())
- .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
- .build();
-
- PayIdApi api = retrofit.create(PayIdApi.class);
-
- Single addressSingle = api.getAddress(user, getAcceptHeader(blockchain))
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .doOnEvent((object, throwable) -> requestsCount--);
-
- addressSingle.subscribe(addressObserver);
- }
-}
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiRipple.java b/app/src/main/java/com/tangem/data/network/ServerApiRipple.java
deleted file mode 100644
index 85563c0df4..0000000000
--- a/app/src/main/java/com/tangem/data/network/ServerApiRipple.java
+++ /dev/null
@@ -1,157 +0,0 @@
-package com.tangem.data.network;
-
-import android.util.Log;
-
-import androidx.annotation.NonNull;
-
-import com.tangem.data.network.model.RippleBody;
-import com.tangem.data.network.model.RippleResponse;
-
-import java.util.HashMap;
-
-import retrofit2.Call;
-import retrofit2.Callback;
-import retrofit2.Response;
-import retrofit2.Retrofit;
-import retrofit2.converter.gson.GsonConverterFactory;
-
-public class ServerApiRipple {
- private static String TAG = ServerApiRipple.class.getSimpleName();
-
- public static final String RIPPLE_ACCOUNT_INFO = "account_info";
- public static final String RIPPLE_ACCOUNT_UNCONFIRMED = "account_unconfirmed";
- public static final String RIPPLE_SUBMIT = "submit";
- public static final String RIPPLE_FEE = "fee";
- public static final String RIPPLE_SERVER_STATE = "server_state";
-
- private int requestsCount = 0;
-
- private final String rippleURL1 = "https://s1.ripple.com:51234"; //TODO: make random selection, add more?, move
- private final String rippleURL2 = "https://s2.ripple.com:51234";
-
- private String currentURL = rippleURL1;
-
- public String getCurrentURL() {
- return currentURL;
- }
-
- public boolean isRequestsSequenceCompleted() {
- Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
- return requestsCount <= 0;
- }
-
- private ResponseListener responseListener;
-
- public interface ResponseListener {
- void onSuccess(String method, RippleResponse rippleResponse);
-
- void onFail(String method, String message);
- }
-
- public void setResponseListener(ResponseListener listener) {
- responseListener = listener;
- }
-
- public void requestData(String method, String wallet, String tx) {
- requestsCount++;
-
- Retrofit retrofitRipple = new Retrofit.Builder()
- .baseUrl(currentURL)
- .addConverterFactory(GsonConverterFactory.create())
- .build();
-
- RippleApi rippleApi = retrofitRipple.create(RippleApi.class);
-
- RippleBody rippleBody;
- HashMap paramsMap;
-
- switch (method) {
- case RIPPLE_ACCOUNT_INFO:
- paramsMap = new HashMap<>();
- paramsMap.put("account", wallet);
- paramsMap.put("ledger_index", "validated");
- rippleBody = new RippleBody(method, paramsMap);
- break;
-
- case RIPPLE_ACCOUNT_UNCONFIRMED:
- paramsMap = new HashMap<>();
- paramsMap.put("account", wallet);
- paramsMap.put("ledger_index", "current");
-// paramsMap.put("queue", "true"); TODO: make queue check if needed
- rippleBody = new RippleBody(RIPPLE_ACCOUNT_INFO, paramsMap);
- break;
-
- case RIPPLE_SERVER_STATE:
- rippleBody = new RippleBody(method, new HashMap<>());
- break;
-
- case RIPPLE_FEE:
- rippleBody = new RippleBody(method, new HashMap<>());
- break;
-
- case RIPPLE_SUBMIT:
- paramsMap = new HashMap<>();
- paramsMap.put("tx_blob", tx);
- rippleBody = new RippleBody(method, paramsMap);
- break;
-
- default:
- rippleBody = new RippleBody();
- }
-
- Call call = rippleApi.ripple(rippleBody);
- call.enqueue(new Callback() {
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) {
- if (response.code() == 200) {
- requestsCount--;
- responseListener.onSuccess(method, response.body());
- Log.i(TAG, "requestData " + method + " onResponse " + response.code());
- } else {
- retryRequest(method, rippleBody);
- Log.e(TAG, "requestData " + method + " onResponse " + response.code());
- }
- }
-
- @Override
- public void onFailure(@NonNull Call call, @NonNull Throwable t) {
- retryRequest(method, rippleBody);
- Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
- }
- });
- }
-
- private void retryRequest(String method, RippleBody rippleBody) {
- currentURL = rippleURL2;
-
- Retrofit retrofitRipple = new Retrofit.Builder()
- .baseUrl(currentURL)
- .addConverterFactory(GsonConverterFactory.create())
- .build();
-
- RippleApi rippleApi = retrofitRipple.create(RippleApi.class);
-
- Call call = rippleApi.ripple(rippleBody);
- call.enqueue(new Callback() {
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) {
- requestsCount--;
-
- if (response.code() == 200) {
- responseListener.onSuccess(method, response.body());
- Log.i(TAG, "requestData " + method + " onResponse " + response.code());
- } else {
- responseListener.onFail(method, String.valueOf(response.code()));
- Log.e(TAG, "requestData " + method + " onResponse " + response.code());
- }
- }
-
- @Override
- public void onFailure(@NonNull Call call, @NonNull Throwable t) {
- requestsCount--;
- responseListener.onFail(method, String.valueOf(t.getMessage()));
- Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
- }
- });
- }
-}
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiRootstock.java b/app/src/main/java/com/tangem/data/network/ServerApiRootstock.java
deleted file mode 100644
index ce1c152a39..0000000000
--- a/app/src/main/java/com/tangem/data/network/ServerApiRootstock.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package com.tangem.data.network;
-
-import android.util.Log;
-
-import androidx.annotation.NonNull;
-
-import com.tangem.App;
-import com.tangem.data.network.model.InfuraBody;
-import com.tangem.data.network.model.InfuraResponse;
-
-import retrofit2.Call;
-import retrofit2.Callback;
-import retrofit2.Response;
-
-public class ServerApiRootstock {
- private static String TAG = ServerApiRootstock.class.getSimpleName();
-
- /**
- * HTTP
- * Rootstock
- *
- * eth_getBalance
- * eth_getTransactionCount
- * eth_call
- * eth_sendRawTransaction
- * eth_gasPrice
- */
- public static final String ROOTSTOCK_ETH_GET_BALANCE = "eth_getBalance";
- public static final String ROOTSTOCK_ETH_GET_TRANSACTION_COUNT = "eth_getTransactionCount";
- public static final String ROOTSTOCK_ETH_GET_PENDING_COUNT = "eth_getPendingCount";
- public static final String ROOTSTOCK_ETH_CALL = "eth_call";
- public static final String ROOTSTOCK_ETH_SEND_RAW_TRANSACTION = "eth_sendRawTransaction";
- public static final String ROOTSTOCK_ETH_GAS_PRICE = "eth_gasPrice";
-
- private int requestsCount=0;
-
- public boolean isRequestsSequenceCompleted() {
- Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
- return requestsCount <= 0;
- }
-
- private ResponseListener responseListener;
-
- public interface ResponseListener {
- void onSuccess(String method, InfuraResponse infuraResponse);
-
- void onFail(String method, String message);
- }
-
- public void setResponseListener(ResponseListener listener) {
- responseListener = listener;
- }
-
- public void requestData(String method, int id, String wallet, String contract, String tx) {
- requestsCount++;
- RootstockApi rootstockApi = App.Companion.getNetworkComponent().getRetrofitRootstock().create(RootstockApi.class);
-
- InfuraBody infuraBody;
- switch (method) {
- case ROOTSTOCK_ETH_GET_BALANCE:
- case ROOTSTOCK_ETH_GET_TRANSACTION_COUNT:
- infuraBody = new InfuraBody(method, new String[]{wallet, "latest"}, id);
- break;
- case ROOTSTOCK_ETH_GET_PENDING_COUNT:
- infuraBody = new InfuraBody(ROOTSTOCK_ETH_GET_TRANSACTION_COUNT, new String[]{wallet, "pending"}, id);
- break;
- case ROOTSTOCK_ETH_CALL:
- String address = wallet.substring(2);
- infuraBody = new InfuraBody(method, new Object[]{new InfuraBody.EthCallParams("0x70a08231000000000000000000000000" + address, contract), "latest"}, id);
- break;
-
- case ROOTSTOCK_ETH_SEND_RAW_TRANSACTION:
- infuraBody = new InfuraBody(method, new String[]{tx}, id);
- break;
-
- case ROOTSTOCK_ETH_GAS_PRICE:
- infuraBody = new InfuraBody(method, id);
- break;
-
- default:
- infuraBody = new InfuraBody();
- }
-
- Call call = rootstockApi.rootstock(infuraBody);
- call.enqueue(new Callback() {
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) {
- requestsCount--;
-
- if (response.code() == 200) {
- responseListener.onSuccess(method, response.body());
- Log.i(TAG, "requestData " + method + " onResponse " + response.code());
- } else {
- responseListener.onFail(method, String.valueOf(response.code()));
- Log.e(TAG, "requestData " + method + " onResponse " + response.code());
- }
- }
-
- @Override
- public void onFailure(@NonNull Call call, @NonNull Throwable t) {
- requestsCount--;
- responseListener.onFail(method, String.valueOf(t.getMessage()));
- Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
- }
- });
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiSoChain.java b/app/src/main/java/com/tangem/data/network/ServerApiSoChain.java
deleted file mode 100644
index ceb90697d5..0000000000
--- a/app/src/main/java/com/tangem/data/network/ServerApiSoChain.java
+++ /dev/null
@@ -1,186 +0,0 @@
-package com.tangem.data.network;
-
-import android.util.Log;
-
-import androidx.annotation.NonNull;
-
-import com.tangem.App;
-import com.tangem.data.Blockchain;
-import com.tangem.data.network.model.SoChain;
-
-import retrofit2.Call;
-import retrofit2.Callback;
-import retrofit2.Response;
-
-public class ServerApiSoChain {
-
- private static String TAG = ServerApiSoChain.class.getSimpleName();
-
- private int requestsCount = 0;
-
- public boolean isRequestsSequenceCompleted() {
- Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
- return requestsCount <= 0;
- }
-
-
- public interface AddressInfoListener {
- void onSuccess(SoChain.Response.AddressBalance response);
-
- void onSuccess(SoChain.Response.TxUnspent response);
-
- void onFail(String message);
- }
-
- private AddressInfoListener addressInfoListener;
-
- public void setAddressInfoListener(AddressInfoListener listener) {
- addressInfoListener = listener;
- }
-
- public interface SendTxListener {
- void onSuccess(SoChain.Response.SendTx response);
-
- void onFail(String message);
- }
-
- private SendTxListener sendTxListener;
-
- public void setSendTxListener(SendTxListener listener) {
- sendTxListener = listener;
- }
-
-
- public interface TransactionInfoListener {
- void onSuccess(SoChain.Response.GetTx response);
-
- void onFail(String message);
- }
-
- private TransactionInfoListener txInfoListener;
-
- public void setTransactionInfoListener(TransactionInfoListener listener) {
- txInfoListener=listener;
- }
-
-
- private String getNetwork(Blockchain blockchain) throws Exception {
- switch (blockchain) {
- case Bitcoin:
- return "BTC";
- case BitcoinTestNet:
- return "BTCTEST";
- case Litecoin:
- return "LTC";
- default:
- throw new Exception("SoChainAPI don't support blockchain " + blockchain.getID());
- }
- }
-
- public void requestAddressBalance(Blockchain blockchain, String wallet) throws Exception {
- requestsCount++;
- SoChainApi api = App.Companion.getNetworkComponent().getRetrofitSoChain().create(SoChainApi.class);
-
- Call call = api.getAddressBalance(getNetwork(blockchain), wallet);
- call.enqueue(new Callback() {
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) {
- requestsCount--;
- Log.i(TAG, "requestAddressBalance onResponse " + response.code());
- if (response.code() == 200) {
- addressInfoListener.onSuccess(response.body());
- } else {
- addressInfoListener.onFail(String.valueOf(response.code()));
- }
- }
-
- @Override
- public void onFailure(@NonNull Call call, @NonNull Throwable t) {
- requestsCount--;
- Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
- addressInfoListener.onFail(String.valueOf(t.getMessage()));
- }
- });
- }
-
- public void requestUnspentTx(Blockchain blockchain, String wallet) throws Exception {
- requestsCount++;
- SoChainApi api = App.Companion.getNetworkComponent().getRetrofitSoChain().create(SoChainApi.class);
-
- Call call = api.getUnspentTx(getNetwork(blockchain), wallet);
- call.enqueue(new Callback() {
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) {
- requestsCount--;
- Log.i(TAG, "requestAddressBalance onResponse " + response.code());
- if (response.code() == 200) {
- addressInfoListener.onSuccess(response.body());
- } else {
- addressInfoListener.onFail(String.valueOf(response.code()));
- }
- }
-
- @Override
- public void onFailure(@NonNull Call call, @NonNull Throwable t) {
- requestsCount--;
- Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
- addressInfoListener.onFail(String.valueOf(t.getMessage()));
- }
- });
- }
-
- public void requestSendTransaction(Blockchain blockchain, String txHEX) throws Exception {
- requestsCount++;
- SoChainApi api = App.Companion.getNetworkComponent().getRetrofitSoChain().create(SoChainApi.class);
-
- SoChain.Request.SendTx tx=new SoChain.Request.SendTx();
- tx.setTx_hex(txHEX);
- Call call = api.sendTransaction(getNetwork(blockchain), tx);
- call.enqueue(new Callback() {
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) {
- requestsCount--;
- Log.i(TAG, "requestAddressBalance onResponse " + response.code());
- if (response.code() == 200) {
- sendTxListener.onSuccess(response.body());
- } else {
- sendTxListener.onFail(String.valueOf(response.code()));
- }
- }
-
- @Override
- public void onFailure(@NonNull Call call, @NonNull Throwable t) {
- requestsCount--;
- Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
- sendTxListener.onFail(String.valueOf(t.getMessage()));
- }
- });
- }
-
- public void requestTransactionInfo(Blockchain blockchain, String txId) throws Exception {
- requestsCount++;
- SoChainApi api = App.Companion.getNetworkComponent().getRetrofitSoChain().create(SoChainApi.class);
-
- Call call = api.getTx(getNetwork(blockchain), txId);
- call.enqueue(new Callback() {
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) {
- requestsCount--;
- Log.i(TAG, "requestAddressBalance onResponse " + response.code());
- if (response.code() == 200) {
- txInfoListener.onSuccess(response.body());
- } else {
- txInfoListener.onFail(String.valueOf(response.code()));
- }
- }
-
- @Override
- public void onFailure(@NonNull Call call, @NonNull Throwable t) {
- requestsCount--;
- Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
- txInfoListener.onFail(String.valueOf(t.getMessage()));
- }
- });
- }
-
-}
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiStellar.java b/app/src/main/java/com/tangem/data/network/ServerApiStellar.java
deleted file mode 100644
index 77427e3fc4..0000000000
--- a/app/src/main/java/com/tangem/data/network/ServerApiStellar.java
+++ /dev/null
@@ -1,206 +0,0 @@
-package com.tangem.data.network;
-
-import com.tangem.App;
-import com.tangem.data.Blockchain;
-import com.tangem.util.LOG;
-import com.tangem.wallet.R;
-import com.tangem.wallet.TangemContext;
-
-import org.stellar.sdk.Network;
-import org.stellar.sdk.Server;
-import org.stellar.sdk.requests.ErrorResponse;
-
-import java.io.IOException;
-
-import io.reactivex.Observable;
-import io.reactivex.android.schedulers.AndroidSchedulers;
-import io.reactivex.observers.DefaultObserver;
-import io.reactivex.schedulers.Schedulers;
-
-/**
- * Created by dvol on 7.01.2019.
- *
- * Request processor for Stellar Horizon Rest Api
- * Every request live cycle:
- * 1. In application create request and call {@link ServerApiStellar}.requestData(..)
- * 2. Try send every request for max 4 times,
- * 3. If all 4 times fail call DefaultObserver.onError (defined in .requestData(..)) and than
- * {@link Listener}.onFail(...) callback
- * Error can be acquired with {@link StellarRequest}.getError() method
- * 4. If request network communication finished successfully then call DefaultObserver.onComplete (defined in .requestData) and than
- * {@link Listener}.onSuccess(...) callback
- */
-public class ServerApiStellar {
-
- public ServerApiStellar(Blockchain blockchain) {
- if (blockchain == Blockchain.Stellar || blockchain == Blockchain.StellarAsset || blockchain == Blockchain.StellarTag) {
- currentURL = ServerURL.API_STELLAR;
- } else {
- currentURL = ServerURL.API_STELLAR_TESTNET;
- }
- }
-
- private static String TAG = ServerApiStellar.class.getSimpleName();
-
- /**
- * TCP, SSL
- * Used in BTC, BCH
- */
- private Listener listener;
-
- private int requestsCount = 0;
-
- private String currentURL;
-
- public String getCurrentURL() {
- return currentURL;
- }
-
- public boolean isRequestsSequenceCompleted() {
- LOG.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
- return requestsCount <= 0;
- }
-
- /**
- * Interface for notification every request result
- */
- public interface Listener {
-
- /**
- * Notify that request processing was successful
- *
- * @param stellarRequest - processed request containing received answer {@see stellarRequest.getAnswer() method}
- */
- void onSuccess(StellarRequest.Base stellarRequest);
-
- /**
- * Notify that request processing was successful
- *
- * @param stellarRequest - processed request containing occurred error {@see stellarRequest.getError() method}
- */
- void onFail(StellarRequest.Base stellarRequest);
- }
-
- /**
- * Set notificaion listener
- *
- * @param listener
- */
- public void setListener(Listener listener) {
- this.listener = listener;
- }
-
-
- /**
- * Start process request
- *
- * @param ctx
- * @param stellarRequest
- */
-
- public void requestData(TangemContext ctx, StellarRequest.Base stellarRequest) {
- requestData(ctx, stellarRequest, false);
- }
-
- public void requestData(TangemContext ctx, StellarRequest.Base stellarRequest, boolean isRetry) {
- requestsCount++;
- LOG.i(TAG, String.format("New request[%d]: %s", requestsCount, stellarRequest.getClass().getSimpleName()));
-
- Observable stellarObserver = Observable.just(stellarRequest)
- .doOnEach(stellarRequest1 -> doStellarRequest(ctx, stellarRequest))
-
- .flatMap(stellarRequest1 -> {
- if (stellarRequest1.errorResponse != null) {
- LOG.e(TAG, "Error response on " + stellarRequest.getClass().getSimpleName());
- return Observable.error(stellarRequest.errorResponse);
- } else
- return Observable.just(stellarRequest1);
- }
- )
-// .retryWhen(errors -> errors
-// .filter(throwable -> (throwable instanceof IOException) || (throwable instanceof ErrorResponse))
-// .zipWith(Observable.range(1, 4), (n, i) -> i))
-
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread());
- stellarObserver.subscribe(new DefaultObserver() {
-
- @Override
- public void onNext(StellarRequest.Base stellarRequest) {
- LOG.e(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onNext ");
- }
-
- @Override
- public void onError(Throwable e) {
- requestsCount--;
- LOG.e(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onError " + e.getMessage());
- LOG.e(TAG, String.format("%d requests left in processing", requestsCount));
-
- if (isRetry || (stellarRequest.errorResponse != null && stellarRequest.errorResponse.getCode() == 404)) {
- stellarRequest.setError(e.getMessage());
- //setErrorOccurred(e.getMessage());//;
- listener.onFail(stellarRequest);
- } else {
- retryRequest(ctx, stellarRequest);
- }
- }
-
- /**
- * Called after completion request processing
- */
- @Override
- public void onComplete() {
- requestsCount--;
- LOG.e(TAG, String.format("%d requests left in processing", requestsCount));
- if (stellarRequest.getError() != null) {
- LOG.i(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onComplete, error!=null");
-
- if (isRetry || (stellarRequest.errorResponse != null && stellarRequest.errorResponse.getCode() == 404)) {
- listener.onFail(stellarRequest);
- } else {
- retryRequest(ctx, stellarRequest);
- }
- } else {
- LOG.e(TAG, "requestData " + stellarRequest.getClass().getSimpleName() + " onComplete, error==null");
- listener.onSuccess(stellarRequest);
- }
- }
-
- });
- }
-
- public void doStellarRequest(TangemContext ctx, StellarRequest.Base stellarRequest) throws IOException {
- stellarRequest.setError(null);
- try {
- Server server;
- Blockchain blockchain = ctx.getBlockchain();
- if (blockchain == Blockchain.Stellar || blockchain == Blockchain.StellarAsset || blockchain == Blockchain.StellarTag) {
- Network.usePublicNetwork();
- server = new Server(currentURL);
- } else if (blockchain == Blockchain.StellarTestNet) {
- Network.useTestNetwork();
- server = new Server(currentURL);
- } else {
- throw new IOException("Wrong blockchain for ServerApiStellar");
- }
- try {
- LOG.e(TAG, "--- request " + stellarRequest.getClass().getSimpleName());
- stellarRequest.process(server);
- } catch (ErrorResponse errorResponse) {
- LOG.e(TAG, "--- error response: " + errorResponse.getMessage());
- stellarRequest.errorResponse = errorResponse;
- stellarRequest.setError(errorResponse.getMessage());
- }
- } catch (Exception e) {
- e.printStackTrace();
- stellarRequest.setError(App.Companion.getInstance().getString(R.string.loaded_wallet_error_blockchain_communication_error));
- throw e;
- }
- }
-
- public void retryRequest (TangemContext ctx, StellarRequest.Base stellarRequest) {
- currentURL = ServerURL.API_STELLAR_RESERVE;
- requestData(ctx, stellarRequest, true);
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/data/network/ServerApiTezos.java b/app/src/main/java/com/tangem/data/network/ServerApiTezos.java
deleted file mode 100644
index b5300912ca..0000000000
--- a/app/src/main/java/com/tangem/data/network/ServerApiTezos.java
+++ /dev/null
@@ -1,139 +0,0 @@
-package com.tangem.data.network;
-
-import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
-import com.tangem.data.network.model.TezosAccountResponse;
-import com.tangem.data.network.model.TezosForgeBody;
-import com.tangem.data.network.model.TezosHeaderResponse;
-import com.tangem.data.network.model.TezosPreapplyBody;
-import com.tangem.tangem_card.util.Log;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import io.reactivex.Single;
-import io.reactivex.SingleObserver;
-import io.reactivex.android.schedulers.AndroidSchedulers;
-import io.reactivex.schedulers.Schedulers;
-import okhttp3.OkHttpClient;
-import okhttp3.logging.HttpLoggingInterceptor;
-import retrofit2.Response;
-import retrofit2.Retrofit;
-import retrofit2.converter.gson.GsonConverterFactory;
-import retrofit2.converter.scalars.ScalarsConverterFactory;
-
-public class ServerApiTezos {
- private static String TAG = ServerApiTezos.class.getSimpleName();
-
- private final String letzbakeURI = "https://teznode.letzbake.com";
- private final String tezrpcURI = "https://mainnet.tezrpc.me";
-
- static final String TEZOS_ADDRESS = "chains/main/blocks/head/context/contracts/{address}";
- static final String TEZOS_HEADER = "chains/main/blocks/head/header";
- static final String TEZOS_MANAGER_KEY = "chains/main/blocks/head/context/contracts/{address}/manager_key";
- static final String TEZOS_FORGE_OPERATIONS = "chains/main/blocks/head/helpers/forge/operations";
- static final String TEZOS_PREAPPLY_OPERATIONS = "chains/main/blocks/head/helpers/preapply/operations";
- static final String TEZOS_RUN_OPERATION = "chains/main/blocks/head/helpers/scripts/run_operation";
- static final String TEZOS_INJECT_OPERATIONS = "injection/operation";
-
- private Retrofit retrofitTezos = new Retrofit.Builder()
- .baseUrl(letzbakeURI)
- .addConverterFactory(GsonConverterFactory.create())
- .addConverterFactory(ScalarsConverterFactory.create())
- .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
- //logging for testing
- .client(new OkHttpClient.Builder().addInterceptor(
- new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
- ).build())
-
- .build();
-
- private TezosApi tezosApi = retrofitTezos.create(TezosApi.class);
-
- private int requestsCount = 0;
-
- public boolean isRequestsSequenceCompleted() {
- Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
- return requestsCount <= 0;
- }
-
- public void getAddress(String wallet, SingleObserver accountObserver) {
- requestsCount++;
- Log.i(TAG, "new getAddress request");
-
- Single accountSingle = tezosApi.getAccount(wallet)
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .doOnEvent((object, throwable) -> requestsCount--);
-
- accountSingle.subscribe(accountObserver);
- }
-
- public void getMangerKey(String wallet, SingleObserver accountObserver) {
- requestsCount++;
- Log.i(TAG, "new getManagerKey request");
-
- Single managerKeySingle = tezosApi.getManagerKey(wallet)
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .doOnEvent((object, throwable) -> requestsCount--);
-
- managerKeySingle.subscribe(accountObserver);
- }
-
- public TezosHeaderResponse getHeader() throws Exception { // TODO? not async
- requestsCount++;
- Log.i(TAG, "new getHeader request");
-
- Response headerResponse = tezosApi.getHeader().execute();
-
- requestsCount--;
- if (headerResponse.code() == 200) {
- return headerResponse.body();
- } else {
- throw new Exception("Wrong header response, code: " + headerResponse.code());
- }
- }
-
- public String forgeOperations(TezosForgeBody tezosForgeBody) throws Exception { // TODO? not async
- requestsCount++;
- Log.i(TAG, "new forgeOperations request");
-
- Response forgeResponse = tezosApi.forgeOperations(tezosForgeBody).execute();
-
- requestsCount--;
- if (forgeResponse.code() == 200) {
- return forgeResponse.body();
- } else {
- throw new Exception("Wrong forge response, code: " + forgeResponse.code());
- }
- }
-
- public void peapplyOperations(TezosPreapplyBody tezosPreapplyBody) throws Exception {
- Log.i(TAG, "new peapplyOperations request");
-
- List tezosPreapplyBodyList = new ArrayList<>();
- tezosPreapplyBodyList.add(tezosPreapplyBody);
- Response preapplyResponse = tezosApi.preapplyOperations(tezosPreapplyBodyList).execute();
-
- if (preapplyResponse.code() != 200) {
- String error = "Preapply error: unknown error";
- if (preapplyResponse.errorBody() != null) {
- error = "Preapply error: " + preapplyResponse.errorBody().string();
- }
- Log.e(TAG, error);
- throw new Exception(error);
- }
- }
-
- public void injectOperations(String txForSend, SingleObserver