Updated on 2026-08-14

This commit is contained in:
Tangem 2019-04-18 11:28:54 +03:00
parent 5f3d316ab7
commit c0826690b6
5 changed files with 96 additions and 2 deletions

View file

@ -39,6 +39,7 @@ public class Server {
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}";
}
}

View file

@ -24,6 +24,7 @@ public class ServerApiSoChain {
return requestsCount <= 0;
}
public interface AddressInfoListener {
void onSuccess(SoChain.Response.AddressBalance response);
@ -50,6 +51,20 @@ public class ServerApiSoChain {
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:
@ -140,4 +155,29 @@ public class ServerApiSoChain {
});
}
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()));
}
});
}
}

View file

@ -17,6 +17,9 @@ public interface SoChainApi {
@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);

View file

@ -52,5 +52,19 @@ class SoChain {
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
}
}
}