diff --git a/app/src/main/java/com/tangem/data/network/BlockcypherApi.java b/app/src/main/java/com/tangem/data/network/BlockcypherApi.java index 9e05655889..d952daf43c 100644 --- a/app/src/main/java/com/tangem/data/network/BlockcypherApi.java +++ b/app/src/main/java/com/tangem/data/network/BlockcypherApi.java @@ -14,12 +14,12 @@ import retrofit2.http.Query; public interface BlockcypherApi { @GET(Server.ApiBlockcypher.Method.MAIN) - Call blockcypherMain(); + Call blockcypherMain(@Path("blockchain") String blockchain); @GET(Server.ApiBlockcypher.Method.ADDRESS) - Call blockcypherAddress(@Path("address") String address); + Call blockcypherAddress(@Path("blockchain") String blockchain, @Path("address") String address); @Headers("Content-Type: application/json") @POST(Server.ApiBlockcypher.Method.PUSH) - Call blockcypherPush(@Body BlockcypherBody blockcypherBody, @Query("token") String token); + Call blockcypherPush(@Path("blockchain") String blockchain, @Body BlockcypherBody blockcypherBody, @Query("token") String token); } 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 d14422cc88..47c370b415 100644 --- a/app/src/main/java/com/tangem/data/network/CoinmarketApi.java +++ b/app/src/main/java/com/tangem/data/network/CoinmarketApi.java @@ -8,7 +8,7 @@ import retrofit2.http.Headers; import retrofit2.http.Query; public interface CoinmarketApi { - @Headers("X-CMC_PRO_API_KEY: 7850b957-6943-42eb-af73-8d536dd8f73e") + @Headers("X-CMC_PRO_API_KEY: f6622117-c043-47a0-8975-9d673ce484de") @GET(Server.ApiCoinmarket.Method.PRICE_CONVERSION) Call getRateInfo(@Query("amount") int amount, @Query("symbol") String cryptoId); } \ No newline at end of file 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 7e72bf7b03..3365ca5590 100644 --- a/app/src/main/java/com/tangem/data/network/Server.java +++ b/app/src/main/java/com/tangem/data/network/Server.java @@ -67,6 +67,10 @@ public class Server { } } + /** + * https://dex.binance.org/ + */ + public static class ApiBinance { public static final String URL_BINANCE = ServerURL.API_BINANCE; @@ -75,6 +79,10 @@ public class Server { } } + /** + * https://testnet-dex.binance.org/ + */ + public static class ApiBinanceTestnet { public static final String URL_BINANCE_TESTNET = ServerURL.API_BINANCE_TESTNET; @@ -83,12 +91,16 @@ public class Server { } } + /** + * https://api.blockcypher.com/ + */ + public static class ApiBlockcypher { public static final String URL_BLOCKCYPHER = ServerURL.API_BLOCKCYPHER; - static final String V1_BTC_MAIN = "v1/btc/main"; + static final String V1_MAIN = "v1/{blockchain}/main"; public static class Method { - static final String MAIN = URL_BLOCKCYPHER + V1_BTC_MAIN; + static final String MAIN = URL_BLOCKCYPHER + V1_MAIN; static final String ADDRESS = MAIN + "/addrs/{address}?unspentOnly=true&includeScript=true"; static final String PUSH = MAIN + "/txs/push"; } 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 997bd47299..5b07c97b71 100644 --- a/app/src/main/java/com/tangem/data/network/ServerApiBlockcypher.java +++ b/app/src/main/java/com/tangem/data/network/ServerApiBlockcypher.java @@ -42,13 +42,14 @@ public class ServerApiBlockcypher { responseListener = listener; } - public void requestData(String method, String wallet, String tx) { + public void requestData(String blockchainID, String method, String wallet, String tx) { requestsCount++; + String blockchain = blockchainID.toLowerCase(); BlockcypherApi blockcypherApi = App.Companion.getNetworkComponent().getRetrofitBlockcypher().create(BlockcypherApi.class); switch (method) { case BLOCKCYPHER_ADDRESS: - Call addressCall = blockcypherApi.blockcypherAddress(wallet); + Call addressCall = blockcypherApi.blockcypherAddress(blockchain, wallet); addressCall.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { @@ -71,7 +72,7 @@ public class ServerApiBlockcypher { break; case BLOCKCYPHER_FEE: - Call feeCall = blockcypherApi.blockcypherMain(); + Call feeCall = blockcypherApi.blockcypherMain(blockchain); feeCall.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { @@ -96,7 +97,7 @@ public class ServerApiBlockcypher { case BLOCKCYPHER_SEND: BlockcypherToken blockcypherToken = BlockcypherToken.values()[new Random().nextInt(BlockcypherToken.values().length)]; - Call sendCall = blockcypherApi.blockcypherPush(new BlockcypherBody(tx), blockcypherToken.getToken()); + Call sendCall = blockcypherApi.blockcypherPush(blockchain, new BlockcypherBody(tx), blockcypherToken.getToken()); sendCall.enqueue(new Callback() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { 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 7239983433..282062c485 100644 --- a/app/src/main/java/com/tangem/data/network/ServerURL.java +++ b/app/src/main/java/com/tangem/data/network/ServerURL.java @@ -2,7 +2,7 @@ package com.tangem.data.network; class ServerURL { static final String API_TANGEM = "https://verify.tangem.com/"; - static final String API_COINMARKETCAP = "https://sandbox-api.coinmarketcap.com/"; //TODO: change to "https://pro-api.coinmarketcap.com/" for production environment + static final String API_COINMARKETCAP = "https://pro-api.coinmarketcap.com/"; //TODO: change to "https://pro-api.coinmarketcap.com/" for production environment static final String API_INFURA = "https://mainnet.infura.io/"; static final String API_ESTIMATEFEE = "https://estimatefee.com/"; static final String API_UPDATE_VERSION = "https://raw.githubusercontent.com/"; diff --git a/app/src/main/java/com/tangem/wallet/Transaction.java b/app/src/main/java/com/tangem/wallet/Transaction.java index 359572a2f3..0d4e54fd51 100644 --- a/app/src/main/java/com/tangem/wallet/Transaction.java +++ b/app/src/main/java/com/tangem/wallet/Transaction.java @@ -32,7 +32,7 @@ public final class Transaction { try { bais = new BitcoinInputStream(rawBytes); version = bais.readInt32(); - if (version != 1 && version != 2 && version != 3) { + if (version != 1 && version != 2 && version != 3 && version != -1273714314) { throw new BitcoinException(BitcoinException.ERR_UNSUPPORTED, "Unsupported TX version", version); } 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 6452c9caeb..3427fa0bbe 100644 --- a/app/src/main/java/com/tangem/wallet/btc/BtcEngine.java +++ b/app/src/main/java/com/tangem/wallet/btc/BtcEngine.java @@ -581,7 +581,7 @@ public class BtcEngine extends CoinEngine { serverApiBlockcypher.setResponseListener(blockcypherListener); - serverApiBlockcypher.requestData(ServerApiBlockcypher.BLOCKCYPHER_ADDRESS, ctx.getCoinData().getWallet(), ""); + serverApiBlockcypher.requestData(ctx.getBlockchain().getID(), ServerApiBlockcypher.BLOCKCYPHER_ADDRESS, ctx.getCoinData().getWallet(), ""); } // @Override @@ -870,7 +870,7 @@ public class BtcEngine extends CoinEngine { serverApiBlockcypher.setResponseListener(blockcypherListener); - serverApiBlockcypher.requestData(ServerApiBlockcypher.BLOCKCYPHER_FEE, "", ""); + serverApiBlockcypher.requestData(ctx.getBlockchain().getID(), ServerApiBlockcypher.BLOCKCYPHER_FEE, "", ""); } // @Override @@ -1020,6 +1020,6 @@ public class BtcEngine extends CoinEngine { }; serverApiBlockcypher.setResponseListener(blockcypherListener); - serverApiBlockcypher.requestData(ServerApiBlockcypher.BLOCKCYPHER_SEND, "", txStr); + serverApiBlockcypher.requestData(ctx.getBlockchain().getID(), ServerApiBlockcypher.BLOCKCYPHER_SEND, "", txStr); } } \ No newline at end of file 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 55b34f61a6..3bf36b1450 100644 --- a/app/src/main/java/com/tangem/wallet/ltc/LtcEngine.java +++ b/app/src/main/java/com/tangem/wallet/ltc/LtcEngine.java @@ -395,18 +395,15 @@ public class LtcEngine extends BtcEngine { @Override public SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception { - final ArrayList unspentOutputs; + ArrayList unspentOutputs = new ArrayList<>(); checkBlockchainDataExists(); String myAddress = ctx.getCoinData().getWallet(); byte[] pbKey = ctx.getCard().getWalletPublicKey(); - // Build script for our address - List rawTxList = coinData.getUnspentTransactions(); - byte[] outputScriptWeAreAbleToSpend = Transaction.Script.buildOutput(myAddress).bytes; - - // Collect unspent - unspentOutputs = BTCUtils.getOutputs(rawTxList, outputScriptWeAreAbleToSpend); + for (BtcData.UnspentTransaction utxo : coinData.getUnspentTransactions()) { + unspentOutputs.add(new UnspentOutputInfo(BTCUtils.fromHex(utxo.txID), new Transaction.Script(BTCUtils.fromHex(utxo.Raw)), utxo.Amount, utxo.Height, -1, utxo.txID, null)); + } long fullAmount = 0; for (int i = 0; i < unspentOutputs.size(); ++i) { @@ -495,66 +492,16 @@ public class LtcEngine extends BtcEngine { }; } - private final static BigDecimal relayFee = new BigDecimal(0.00001); + private final static BigDecimal relayFee = new BigDecimal(0.00001).setScale(8, RoundingMode.DOWN); @Override public void requestFee(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) throws Exception { - final int calcSize = calculateEstimatedTransactionSize(targetAddress, amount.toValueString()); - Log.e(TAG, String.format("Estimated tx size %d", calcSize)); - coinData.minFee=null; - coinData.maxFee=null; - coinData.normalFee=null; + coinData.minFee = coinData.normalFee = coinData.maxFee = new Amount(relayFee, "LTC"); + blockchainRequestsCallbacks.onComplete(true); + } - final ServerApiElectrum serverApiElectrum = new ServerApiElectrum(); - - final ServerApiElectrum.ResponseListener electrumListener = new ServerApiElectrum.ResponseListener() { - @Override - public void onSuccess(ElectrumRequest electrumRequest) { - BigDecimal fee; - if (electrumRequest.isMethod(ElectrumRequest.METHOD_GetFee)) { - try { - fee = new BigDecimal(electrumRequest.getResultString()); //fee per KB - - if (fee.equals(BigDecimal.ZERO)) { - serverApiElectrum.requestData(ctx, ElectrumRequest.getFee()); - } - -// if (calcSize != 0) { - fee = fee.multiply(new BigDecimal(calcSize)).divide(new BigDecimal(1024)); // (per KB -> per byte)*size -// } else { -// serverApiElectrum.requestData(ctx, ElectrumRequest.getFee()); -// } - - //compare fee to usual relay fee - if (fee.compareTo(relayFee) < 0) { - fee = relayFee; - } - fee = fee.setScale(8, RoundingMode.DOWN); - - CoinEngine.Amount feeAmount = new CoinEngine.Amount(fee, ctx.getBlockchain().getCurrency()); - coinData.minFee = feeAmount; - coinData.normalFee = feeAmount; - coinData.maxFee = feeAmount; -// if (coinData.minFee != null && coinData.normalFee != null && coinData.maxFee != null) { - blockchainRequestsCallbacks.onComplete(true); -// } else { -// blockchainRequestsCallbacks.onProgress(); -// } - - } catch (JSONException e) { - e.printStackTrace(); - } - } - } - - @Override - public void onFail(ElectrumRequest electrumRequest) { - ctx.setError(electrumRequest.getError()); - blockchainRequestsCallbacks.onComplete(false); - } - }; - serverApiElectrum.setResponseListener(electrumListener); - - serverApiElectrum.requestData(ctx, ElectrumRequest.getFee()); + @Override + public boolean allowSelectFeeLevel() { + return false; } } \ No newline at end of file