Updated on 2026-08-14
This commit is contained in:
commit
f3ec82bf73
9 changed files with 194 additions and 155 deletions
25
app/src/main/java/com/tangem/data/network/DucatusApi.java
Normal file
25
app/src/main/java/com/tangem/data/network/DucatusApi.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import com.tangem.data.network.model.BitcoreBalance;
|
||||
import com.tangem.data.network.model.BitcoreSendBody;
|
||||
import com.tangem.data.network.model.BitcoreSendResponse;
|
||||
import com.tangem.data.network.model.BitcoreUtxo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Path;
|
||||
|
||||
public interface DucatusApi {
|
||||
@GET(Server.ApiDucatus.Method.BALANCE)
|
||||
Single<BitcoreBalance> ducatusBalance(@Path("address") String address);
|
||||
|
||||
@GET(Server.ApiDucatus.Method.UTXO)
|
||||
Single<List<BitcoreUtxo>> ducatusUnspents(@Path("address") String address);
|
||||
|
||||
@POST(Server.ApiDucatus.Method.SEND)
|
||||
Single<BitcoreSendResponse> ducatusSend(@Body BitcoreSendBody body);
|
||||
}
|
||||
|
|
@ -129,4 +129,14 @@ public class Server {
|
|||
static final String PUSH = URL_BLOCKCHAININFO + "pushtx";
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApiDucatus {
|
||||
public static final String URL_DUCATUS = ServerURL.API_DUCATUS + "api/DUC/mainnet/";
|
||||
|
||||
public static class Method {
|
||||
static final String BALANCE = URL_DUCATUS + "address/{address}/balance";
|
||||
static final String UTXO = URL_DUCATUS + "address/{address}/?unspent=true";
|
||||
static final String SEND = URL_DUCATUS + "tx/send";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import com.tangem.App;
|
||||
import com.tangem.data.network.model.BitcoreBalance;
|
||||
import com.tangem.data.network.model.BitcoreBalanceAndUnspents;
|
||||
import com.tangem.data.network.model.BitcoreSendBody;
|
||||
import com.tangem.data.network.model.BitcoreSendResponse;
|
||||
import com.tangem.data.network.model.BitcoreUtxo;
|
||||
import com.tangem.tangem_card.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleObserver;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class ServerApiBitcore {
|
||||
private static String TAG = ServerApiBitcore.class.getSimpleName();
|
||||
|
||||
public void getBalanceAndUnspents(String wallet, SingleObserver<BitcoreBalanceAndUnspents> balanceAndUnspentsObserver) {
|
||||
Log.i(TAG, "new getAddressAndUnspents request");
|
||||
DucatusApi api = App.Companion.getNetworkComponent().getRetrofitDucatus().create(DucatusApi.class);
|
||||
|
||||
Single<BitcoreBalance> balanceObservable = api.ducatusBalance(wallet);
|
||||
|
||||
Single<List<BitcoreUtxo>> unspentsObservable = api.ducatusUnspents(wallet)
|
||||
.onErrorReturnItem(new ArrayList<>());
|
||||
|
||||
Single.zip(balanceObservable, unspentsObservable, BitcoreBalanceAndUnspents::new)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(balanceAndUnspentsObserver);
|
||||
}
|
||||
|
||||
public void sendTransaction(String tx, SingleObserver<BitcoreSendResponse> sendObserver) {
|
||||
Log.i(TAG, "new getAddress request");
|
||||
DucatusApi api = App.Companion.getNetworkComponent().getRetrofitDucatus().create(DucatusApi.class);
|
||||
|
||||
Single<BitcoreSendResponse> sendObservable = api.ducatusSend(new BitcoreSendBody(tx))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
|
||||
sendObservable.subscribe(sendObserver);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,4 +16,5 @@ class ServerURL {
|
|||
static final String API_STELLAR_RESERVE = "https://horizon.sui.li/";
|
||||
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/";
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.tangem.data.network.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class BitcoreBalance(
|
||||
@SerializedName("confirmed")
|
||||
var confirmed: Long? = null,
|
||||
|
||||
@SerializedName("unconfirmed")
|
||||
var unconfirmed: Long? = null
|
||||
)
|
||||
|
||||
data class BitcoreUtxo(
|
||||
@SerializedName("mintTxid")
|
||||
var mintTxid: String? = null,
|
||||
|
||||
@SerializedName("mintIndex")
|
||||
var mintIndex: Int? = null,
|
||||
|
||||
@SerializedName("value")
|
||||
var value: Long? = null,
|
||||
|
||||
@SerializedName("script")
|
||||
var script: String? = null
|
||||
)
|
||||
|
||||
data class BitcoreBalanceAndUnspents(
|
||||
var balance: BitcoreBalance,
|
||||
var unspents: List<BitcoreUtxo>
|
||||
)
|
||||
|
||||
data class BitcoreSendResponse(
|
||||
var txid: String? = null
|
||||
)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.tangem.data.network.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BitcoreSendBody {
|
||||
private List<String> rawTx;
|
||||
|
||||
public BitcoreSendBody(String tx) {
|
||||
List<String> txList = new ArrayList<>();
|
||||
txList.add(tx);
|
||||
rawTx = txList;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue