Updated on 2026-08-14

This commit is contained in:
Tangem 2019-06-11 12:27:03 +03:00
parent ba0b69b263
commit 2d170ae61c
8 changed files with 39 additions and 79 deletions

View file

@ -14,12 +14,12 @@ import retrofit2.http.Query;
public interface BlockcypherApi {
@GET(Server.ApiBlockcypher.Method.MAIN)
Call<BlockcypherFee> blockcypherMain();
Call<BlockcypherFee> blockcypherMain(@Path("blockchain") String blockchain);
@GET(Server.ApiBlockcypher.Method.ADDRESS)
Call<BlockcypherResponse> blockcypherAddress(@Path("address") String address);
Call<BlockcypherResponse> blockcypherAddress(@Path("blockchain") String blockchain, @Path("address") String address);
@Headers("Content-Type: application/json")
@POST(Server.ApiBlockcypher.Method.PUSH)
Call<BlockcypherResponse> blockcypherPush(@Body BlockcypherBody blockcypherBody, @Query("token") String token);
Call<BlockcypherResponse> blockcypherPush(@Path("blockchain") String blockchain, @Body BlockcypherBody blockcypherBody, @Query("token") String token);
}

View file

@ -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<RateInfoResponse> getRateInfo(@Query("amount") int amount, @Query("symbol") String cryptoId);
}

View file

@ -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";
}

View file

@ -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<BlockcypherResponse> addressCall = blockcypherApi.blockcypherAddress(wallet);
Call<BlockcypherResponse> addressCall = blockcypherApi.blockcypherAddress(blockchain, wallet);
addressCall.enqueue(new Callback<BlockcypherResponse>() {
@Override
public void onResponse(@NonNull Call<BlockcypherResponse> call, @NonNull Response<BlockcypherResponse> response) {
@ -71,7 +72,7 @@ public class ServerApiBlockcypher {
break;
case BLOCKCYPHER_FEE:
Call<BlockcypherFee> feeCall = blockcypherApi.blockcypherMain();
Call<BlockcypherFee> feeCall = blockcypherApi.blockcypherMain(blockchain);
feeCall.enqueue(new Callback<BlockcypherFee>() {
@Override
public void onResponse(@NonNull Call<BlockcypherFee> call, @NonNull Response<BlockcypherFee> response) {
@ -96,7 +97,7 @@ public class ServerApiBlockcypher {
case BLOCKCYPHER_SEND:
BlockcypherToken blockcypherToken = BlockcypherToken.values()[new Random().nextInt(BlockcypherToken.values().length)];
Call<BlockcypherResponse> sendCall = blockcypherApi.blockcypherPush(new BlockcypherBody(tx), blockcypherToken.getToken());
Call<BlockcypherResponse> sendCall = blockcypherApi.blockcypherPush(blockchain, new BlockcypherBody(tx), blockcypherToken.getToken());
sendCall.enqueue(new Callback<BlockcypherResponse>() {
@Override
public void onResponse(@NonNull Call<BlockcypherResponse> call, @NonNull Response<BlockcypherResponse> response) {

View file

@ -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/";

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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<UnspentOutputInfo> unspentOutputs;
ArrayList<UnspentOutputInfo> unspentOutputs = new ArrayList<>();
checkBlockchainDataExists();
String myAddress = ctx.getCoinData().getWallet();
byte[] pbKey = ctx.getCard().getWalletPublicKey();
// Build script for our address
List<BtcData.UnspentTransaction> 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;
}
}