Updated on 2026-08-14

This commit is contained in:
Tangem 2020-03-02 12:21:18 +03:00
parent e029da2b32
commit a31c66d60f
10 changed files with 328 additions and 266 deletions

View file

@ -0,0 +1,27 @@
package com.tangem.data.network;
import com.tangem.data.network.model.BlockchairAddressResponse;
import com.tangem.data.network.model.BlockchairSendBody;
import com.tangem.data.network.model.BlockchairStatsResponse;
import com.tangem.data.network.model.BlockchairTransactionResponse;
import io.reactivex.Completable;
import io.reactivex.Single;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
public interface BlockchairApi {
@GET(Server.ApiBlockchair.Method.ADDRESS)
Single<BlockchairAddressResponse> getAddress(@Path("blockchain") String blockchain, @Path("address") String address);
@GET(Server.ApiBlockchair.Method.TRANSACTION)
Single<BlockchairTransactionResponse> getTransaction(@Path("blockchain") String blockchain, @Path("transaction") String transaction);
@GET(Server.ApiBlockchair.Method.STATS)
Single<BlockchairStatsResponse> getStats(@Path("blockchain") String blockchain);
@POST(Server.ApiBlockchair.Method.PUSH)
Completable sendTransaction(@Path("blockchain") String blockchain, @Body BlockchairSendBody body);
}

View file

@ -139,4 +139,15 @@ public class Server {
static final String SEND = URL_DUCATUS + "tx/send";
}
}
public static class ApiBlockchair {
public static final String URL_BLOCKCHAIR = ServerURL.API_BLOCKCHAIR + "{blockchain}/";
public static class Method {
static final String ADDRESS = URL_BLOCKCHAIR + "dashboards/address/{address}";
static final String TRANSACTION = URL_BLOCKCHAIR + "dashboards/transaction/{transaction}";
static final String STATS = URL_BLOCKCHAIR + "stats";
static final String PUSH = URL_BLOCKCHAIR + "push/transaction";
}
}
}

View file

@ -0,0 +1,73 @@
package com.tangem.data.network;
import com.tangem.App;
import com.tangem.data.Blockchain;
import com.tangem.data.network.model.BlockchairAddressResponse;
import com.tangem.data.network.model.BlockchairSendBody;
import com.tangem.data.network.model.BlockchairStatsResponse;
import com.tangem.data.network.model.BlockchairTransactionResponse;
import com.tangem.tangem_card.util.Log;
import io.reactivex.Completable;
import io.reactivex.CompletableObserver;
import io.reactivex.Single;
import io.reactivex.SingleObserver;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
public class ServerApiBlockchair {
private static String TAG = ServerApiBlockchair.class.getSimpleName();
private String blockchain;
public ServerApiBlockchair(Blockchain blockchain) {
if (blockchain == Blockchain.BitcoinCash) this.blockchain = "bitcoin-cash";
}
public void getAddress(String wallet, SingleObserver<BlockchairAddressResponse> addressObserver) {
Log.i(TAG, "new getAddress request");
BlockchairApi api = App.Companion.getNetworkComponent().getRetrofitBlockchair().create(BlockchairApi.class);
Single<BlockchairAddressResponse> addressSingle = api.getAddress(blockchain, wallet)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
addressSingle.subscribe(addressObserver);
}
public void getTransaction(String transaction, SingleObserver<BlockchairTransactionResponse> transactionObserver) {
Log.i(TAG, "new getAddress request");
BlockchairApi api = App.Companion.getNetworkComponent().getRetrofitBlockchair().create(BlockchairApi.class);
Single<BlockchairTransactionResponse> transactionSingle = api.getTransaction(blockchain, transaction)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
transactionSingle.subscribe(transactionObserver);
}
public void getStats(SingleObserver<BlockchairStatsResponse> statsObserver) {
Log.i(TAG, "new getStats request");
BlockchairApi api = App.Companion.getNetworkComponent().getRetrofitBlockchair().create(BlockchairApi.class);
Single<BlockchairStatsResponse> statsSingle = api.getStats(blockchain)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
statsSingle.subscribe(statsObserver);
}
public void sendTransaction(String tx, CompletableObserver sendObserver) {
Log.i(TAG, "new getAddress request");
BlockchairApi api = App.Companion.getNetworkComponent().getRetrofitDucatus().create(BlockchairApi.class);
Completable sendCompletable = api.sendTransaction(blockchain, new BlockchairSendBody(tx))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
sendCompletable.subscribe(sendObserver);
}
public String getUrl() {
return ServerURL.API_BLOCKCHAIR;
}
}

View file

@ -17,4 +17,5 @@ class ServerURL {
static final String API_STELLAR_TESTNET = "https://horizon-testnet.stellar.org/";
static final String API_BLOCKCHAIN_INFO = "https://blockchain.info/";
static final String API_DUCATUS = "https://ducapi.rocknblock.io/";
static final String API_BLOCKCHAIR = "https://api.blockchair.com/";
}

View file

@ -0,0 +1,69 @@
package com.tangem.data.network.model
import com.google.gson.annotations.SerializedName
data class BlockchairAddressResponse(
@SerializedName("data")
val data: Map<String, BlockchairAddressData>? = null
)
data class BlockchairAddressData(
@SerializedName("address")
val address: BlockchairAddressInfo? = null,
@SerializedName("utxo")
val unspentOutputs: List<BlockchairUnspentOutput>? = null,
@SerializedName("transactions")
val transactions: List<String>
)
data class BlockchairAddressInfo(
@SerializedName("balance")
val balance: Long? = null,
@SerializedName("output_count")
val outputCount: Int? = null,
@SerializedName("unspent_output_count")
val unspentOutputCount: Int? = null
)
data class BlockchairUnspentOutput(
@SerializedName("block_id")
val block: Int? = null,
@SerializedName("transaction_hash")
val transactionHash: String? = null,
@SerializedName("index")
val index: Int? = null,
@SerializedName("value")
val amount: Long? = null
)
data class BlockchairTransactionResponse(
@SerializedName("data")
val data: Map<String, BlockchairTransactionData>? = null
)
data class BlockchairTransactionData(
@SerializedName("transaction")
val transaction: BlockchairTransactionInfo? = null
)
data class BlockchairTransactionInfo(
@SerializedName("block_id")
val block: Int? = null
)
data class BlockchairStatsResponse(
@SerializedName("data")
val data: BlockchairStatsData? = null
)
data class BlockchairStatsData(
@SerializedName("suggested_transaction_fee_per_byte_sat")
val feePerByte: Int? = null
)

View file

@ -0,0 +1,9 @@
package com.tangem.data.network.model;
public class BlockchairSendBody {
private String data;
public BlockchairSendBody(String data) {
this.data = data;
}
}