Updated on 2026-08-14
This commit is contained in:
commit
b48c9aaf78
11 changed files with 917 additions and 333 deletions
|
|
@ -32,6 +32,18 @@ public class Server {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ApiSoChain {
|
||||
public static final String URL = ServerURL.API_SOCHAIN_V2;
|
||||
|
||||
public static class Method {
|
||||
public static final String ADDRESS_BALANCE = "api/v2/get_address_balance/{network}/{address}";
|
||||
public static final String UNSPENT_TX = "api/v2/get_tx_unspent/{network}/{address}";
|
||||
public static final String GET_TX = "api/v2/get_tx/{network}/{txid}";
|
||||
public static final String SEND_TRANSACTION = "api/v2/send_tx/{network}";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://public-node.rsk.co/
|
||||
*/
|
||||
|
|
|
|||
183
app/src/main/java/com/tangem/data/network/ServerApiSoChain.java
Normal file
183
app/src/main/java/com/tangem/data/network/ServerApiSoChain.java
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.App;
|
||||
import com.tangem.data.Blockchain;
|
||||
import com.tangem.data.network.model.SoChain;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class ServerApiSoChain {
|
||||
|
||||
public static String NETWORK_BTC = "BTC";
|
||||
|
||||
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<SoChain.Response.AddressBalance> call = api.getAddressBalance(getNetwork(blockchain), wallet);
|
||||
call.enqueue(new Callback<SoChain.Response.AddressBalance>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SoChain.Response.AddressBalance> call, @NonNull Response<SoChain.Response.AddressBalance> response) {
|
||||
Log.i(TAG, "requestAddressBalance onResponse " + response.code());
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
addressInfoListener.onSuccess(response.body());
|
||||
} else {
|
||||
addressInfoListener.onFail(String.valueOf(response.code()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SoChain.Response.AddressBalance> call, @NonNull Throwable t) {
|
||||
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<SoChain.Response.TxUnspent> call = api.getUnspentTx(getNetwork(blockchain), wallet);
|
||||
call.enqueue(new Callback<SoChain.Response.TxUnspent>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SoChain.Response.TxUnspent> call, @NonNull Response<SoChain.Response.TxUnspent> response) {
|
||||
Log.i(TAG, "requestAddressBalance onResponse " + response.code());
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
addressInfoListener.onSuccess(response.body());
|
||||
} else {
|
||||
addressInfoListener.onFail(String.valueOf(response.code()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SoChain.Response.TxUnspent> call, @NonNull Throwable t) {
|
||||
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<SoChain.Response.SendTx> call = api.sendTransaction(getNetwork(blockchain), tx);
|
||||
call.enqueue(new Callback<SoChain.Response.SendTx>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SoChain.Response.SendTx> call, @NonNull Response<SoChain.Response.SendTx> response) {
|
||||
Log.i(TAG, "requestAddressBalance onResponse " + response.code());
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
sendTxListener.onSuccess(response.body());
|
||||
} else {
|
||||
sendTxListener.onFail(String.valueOf(response.code()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SoChain.Response.SendTx> call, @NonNull Throwable t) {
|
||||
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<SoChain.Response.GetTx> call = api.getTx(getNetwork(blockchain), txId);
|
||||
call.enqueue(new Callback<SoChain.Response.GetTx>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SoChain.Response.GetTx> call, @NonNull Response<SoChain.Response.GetTx> response) {
|
||||
Log.i(TAG, "requestAddressBalance onResponse " + response.code());
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
txInfoListener.onSuccess(response.body());
|
||||
} else {
|
||||
txInfoListener.onFail(String.valueOf(response.code()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<SoChain.Response.GetTx> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, "requestAddressBalance onFailure " + t.getMessage());
|
||||
txInfoListener.onFail(String.valueOf(t.getMessage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ class ServerURL {
|
|||
static final String API_TANGEM = "https://verify.tangem.com/";
|
||||
static final String API_COINMARKETCAP = "https://pro-api.coinmarketcap.com/";
|
||||
static final String API_INFURA = "https://mainnet.infura.io/";
|
||||
static final String API_SOCHAIN_V2 = "https://chain.so/";
|
||||
static final String API_ESTIMATEFEE = "https://estimatefee.com/";
|
||||
static final String API_UPDATE_VERSION = "https://raw.githubusercontent.com/";
|
||||
static final String API_ROOTSTOCK = "https://public-node.rsk.co/";
|
||||
|
|
|
|||
26
app/src/main/java/com/tangem/data/network/SoChainApi.java
Normal file
26
app/src/main/java/com/tangem/data/network/SoChainApi.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
|
||||
import com.tangem.data.network.model.SoChain;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Path;
|
||||
|
||||
public interface SoChainApi {
|
||||
@GET(Server.ApiSoChain.Method.ADDRESS_BALANCE)
|
||||
Call<SoChain.Response.AddressBalance> getAddressBalance(@Path("network") String network, @Path("address") String address);
|
||||
|
||||
@GET(Server.ApiSoChain.Method.UNSPENT_TX)
|
||||
Call<SoChain.Response.TxUnspent> getUnspentTx(@Path("network") String network, @Path("address") String address);
|
||||
|
||||
@GET(Server.ApiSoChain.Method.GET_TX)
|
||||
Call<SoChain.Response.GetTx> getTx(@Path("network") String network, @Path("txid") String txId);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST(Server.ApiSoChain.Method.SEND_TRANSACTION)
|
||||
Call<SoChain.Response.SendTx> sendTransaction(@Path("network") String network, @Body SoChain.Request.SendTx body);
|
||||
}
|
||||
70
app/src/main/java/com/tangem/data/network/model/SoChain.kt
Normal file
70
app/src/main/java/com/tangem/data/network/model/SoChain.kt
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package com.tangem.data.network.model
|
||||
|
||||
class SoChain {
|
||||
class Request {
|
||||
class SendTx{
|
||||
var tx_hex: String? = null
|
||||
}
|
||||
}
|
||||
|
||||
class Response {
|
||||
class AddressBalance {
|
||||
class Data {
|
||||
var network: String? = null
|
||||
var address: String? = null
|
||||
var confirmed_balance: String? = null
|
||||
var unconfirmed_balance: String? = null
|
||||
var confirmations: String? = null
|
||||
}
|
||||
|
||||
var status: String? = null
|
||||
var data: Data? = null
|
||||
}
|
||||
|
||||
class TxUnspent {
|
||||
class Data {
|
||||
class Tx {
|
||||
var txid: String? = null //"9b5c8fbeb1e42bb2a6da40e2eab49c368d1a205707a1ec88aa13f0f2ecdfe944",
|
||||
var output_no: Int? = null // 0,
|
||||
var script_asm: String? = null // "OP_DUP OP_HASH160 8541eb0593bb19c3755198e7d2a71e134da21a97 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
var script_hex: String? = null // "76a9148541eb0593bb19c3755198e7d2a71e134da21a9788ac",
|
||||
var value: String? = null // "11.38404832",
|
||||
var confirmations: Long? = null
|
||||
var time: Long? = null// : 1555509495
|
||||
}
|
||||
|
||||
var network: String? = null
|
||||
var address: String? = null
|
||||
var txs: Array<Tx>? = null
|
||||
}
|
||||
|
||||
var status: String? = null
|
||||
var data: Data? = null
|
||||
|
||||
}
|
||||
|
||||
class SendTx {
|
||||
class Data {
|
||||
var network: String? = null
|
||||
var txid: String? = null
|
||||
var tx_hex: String? = null
|
||||
}
|
||||
var status: String? = null
|
||||
var data: Data? = null
|
||||
}
|
||||
|
||||
class GetTx {
|
||||
class Data {
|
||||
// restricted data
|
||||
var network: String? = null
|
||||
var address: String? = null
|
||||
var txid: String? = null
|
||||
var tx_hex: String? = null
|
||||
}
|
||||
|
||||
var status: String? = null
|
||||
var data: Data? = null
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -35,6 +35,9 @@ interface NetworkComponent {
|
|||
@get:Named(Server.ApiBlockcypher.URL_BLOCKCYPHER)
|
||||
val retrofitBlockcypher: Retrofit
|
||||
|
||||
@get:Named(Server.ApiSoChain.URL)
|
||||
val retrofitSoChain: Retrofit
|
||||
|
||||
@get:Named("socket")
|
||||
val socket: Socket
|
||||
|
||||
|
|
|
|||
|
|
@ -109,6 +109,18 @@ internal class NetworkModule {
|
|||
return builder.build()
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named(Server.ApiSoChain.URL)
|
||||
fun provideRetrofitSoChain(): Retrofit {
|
||||
val builder = Retrofit.Builder()
|
||||
.baseUrl(Server.ApiSoChain.URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
if (BuildConfig.DEBUG)
|
||||
builder.client(createOkHttpClient())
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
private fun createOkHttpClient(): OkHttpClient {
|
||||
return OkHttpClient.Builder().addInterceptor(createHttpLoggingInterceptor()).build()
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue