Updated on 2026-08-14
This commit is contained in:
commit
52f7ae6f1b
26 changed files with 3295 additions and 61 deletions
35
.idea/misc.xml
generated
35
.idea/misc.xml
generated
|
|
@ -5,6 +5,41 @@
|
|||
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
|
||||
</configurations>
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="androidx.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="10">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
|
||||
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
|
||||
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
|
||||
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
|
||||
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="9">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
|
||||
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
|
||||
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
|
||||
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ dependencies {
|
|||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
|
||||
implementation 'androidx.biometric:biometric:1.0.0-alpha03'
|
||||
implementation 'co.nstant.in:cbor:0.8'
|
||||
implementation 'com.google.android.material:material:1.1.0-alpha02'
|
||||
implementation 'com.google.dagger:dagger:2.21'
|
||||
kapt 'com.google.dagger:dagger-compiler:2.21'
|
||||
|
|
@ -65,6 +66,7 @@ dependencies {
|
|||
implementation 'com.scottyab:rootbeer-lib:0.0.7'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
|
||||
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
|
||||
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
|
||||
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'
|
||||
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ public enum Blockchain {
|
|||
BitcoinCash("BCH", "BCH", 100000000.0, R.drawable.ic_logo_bitcoin_cash, "Bitcoin Cash"),
|
||||
Litecoin("LTC", "LTC", 100000000.0, R.drawable.ic_logo_bitcoin, "Litecoin"),
|
||||
Rootstock("RSK", "RBTC", 1.0, R.drawable.ic_logo_bitcoin, "Rootstock"),
|
||||
RootstockToken("Token", "RBTC", 1.0, R.drawable.ic_logo_bat_token, "Rootstock");
|
||||
RootstockToken("Token", "RBTC", 1.0, R.drawable.ic_logo_bat_token, "Rootstock"),
|
||||
Cardano("CARDANO", "ADA", 1000000.0,R.drawable.ic_logo_bitcoin, "Cardano");
|
||||
|
||||
Blockchain(String ID, String currency, double multiplier, int imageResource, String officialName) {
|
||||
mID = ID;
|
||||
|
|
|
|||
30
app/src/main/java/com/tangem/data/network/AdaliteApi.java
Normal file
30
app/src/main/java/com/tangem/data/network/AdaliteApi.java
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import com.tangem.data.network.model.AdaliteBody;
|
||||
import com.tangem.data.network.model.AdaliteResponse;
|
||||
import com.tangem.data.network.model.AdaliteResponseUtxo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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 AdaliteApi {
|
||||
@GET(ServerApiAdalite.ADALITE_ADDRESS)
|
||||
Call<AdaliteResponse> adaliteAddress(@Path("address") String address);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST(ServerApiAdalite.ADALITE_UNSPENT_OUTPUTS)
|
||||
Call<AdaliteResponseUtxo> adaliteUnspent(@Body String address);
|
||||
|
||||
// @GET(ServerApiAdalite.ADALITE_TRANSACTION)
|
||||
// Call<AdaliteResponse> adaliteTransaction(@Path("txId") String txId);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST(ServerApiAdalite.ADALITE_SEND)
|
||||
Call<List> adaliteSend(@Body AdaliteBody adaliteBody);
|
||||
}
|
||||
144
app/src/main/java/com/tangem/data/network/ServerApiAdalite.java
Normal file
144
app/src/main/java/com/tangem/data/network/ServerApiAdalite.java
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.data.network.model.AdaliteBody;
|
||||
import com.tangem.data.network.model.AdaliteResponse;
|
||||
import com.tangem.data.network.model.AdaliteResponseUtxo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
import retrofit2.converter.scalars.ScalarsConverterFactory;
|
||||
|
||||
public class ServerApiAdalite {
|
||||
private static String TAG = ServerApiAdalite.class.getSimpleName();
|
||||
|
||||
public static final String ADALITE_ADDRESS = "/api/addresses/summary/{address}";
|
||||
public static final String ADALITE_UNSPENT_OUTPUTS = "/api/bulk/addresses/utxo";
|
||||
// public static final String ADALITE_TRANSACTION = "/api/txs/raw/{txId}}";
|
||||
public static final String ADALITE_SEND = "/api/v2/txs/signed";
|
||||
|
||||
private int requestsCount = 0;
|
||||
|
||||
public static String lastNode;
|
||||
|
||||
public boolean isRequestsSequenceCompleted() {
|
||||
Log.i(TAG, String.format("isRequestsSequenceCompleted: %s (%d requests left)", String.valueOf(requestsCount <= 0), requestsCount));
|
||||
return requestsCount <= 0;
|
||||
}
|
||||
|
||||
private ResponseListener responseListener;
|
||||
|
||||
public interface ResponseListener {
|
||||
void onSuccess(String method, AdaliteResponse adaliteResponse);
|
||||
|
||||
void onSuccess(String method, AdaliteResponseUtxo adaliteResponseUtxo);
|
||||
|
||||
void onSuccess(String method, List listResponse);
|
||||
|
||||
void onFail(String method, String message);
|
||||
}
|
||||
|
||||
public void setResponseListener(ResponseListener listener) {
|
||||
responseListener = listener;
|
||||
}
|
||||
|
||||
public void requestData(String method, String wallet, String tx) {
|
||||
requestsCount++;
|
||||
String adaliteURL = "https://explorer2.adalite.io"; //TODO: make random selection
|
||||
this.lastNode = adaliteURL; //TODO: show node instead of URL
|
||||
|
||||
Retrofit retrofitAdalite = new Retrofit.Builder()
|
||||
.baseUrl(adaliteURL)
|
||||
.addConverterFactory(ScalarsConverterFactory.create())
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
|
||||
AdaliteApi adaliteApi = retrofitAdalite.create(AdaliteApi.class);
|
||||
|
||||
switch (method) {
|
||||
case ADALITE_ADDRESS:
|
||||
|
||||
Call<AdaliteResponse> addressCall = adaliteApi.adaliteAddress(wallet);
|
||||
addressCall.enqueue(new Callback<AdaliteResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<AdaliteResponse> call, @NonNull Response<AdaliteResponse> response) {
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
responseListener.onSuccess(method, response.body());
|
||||
Log.i(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
} else {
|
||||
responseListener.onFail(method, String.valueOf(response.code()));
|
||||
Log.e(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<AdaliteResponse> call, @NonNull Throwable t) {
|
||||
responseListener.onFail(method, String.valueOf(t.getMessage()));
|
||||
Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case ADALITE_UNSPENT_OUTPUTS:
|
||||
Call<AdaliteResponseUtxo> outputsCall = adaliteApi.adaliteUnspent("[\"" + wallet + "\"]");
|
||||
outputsCall.enqueue(new Callback<AdaliteResponseUtxo>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<AdaliteResponseUtxo> call, @NonNull Response<AdaliteResponseUtxo> response) {
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
responseListener.onSuccess(method, response.body());
|
||||
Log.i(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
} else {
|
||||
responseListener.onFail(method, String.valueOf(response.code()));
|
||||
Log.e(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<AdaliteResponseUtxo> call, @NonNull Throwable t) {
|
||||
responseListener.onFail(method, String.valueOf(t.getMessage()));
|
||||
Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case ADALITE_SEND:
|
||||
Call<List> sendCall = adaliteApi.adaliteSend(new AdaliteBody(tx));
|
||||
sendCall.enqueue(new Callback<List>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List> call, @NonNull Response<List> response) {
|
||||
if (response.code() == 200) {
|
||||
requestsCount--;
|
||||
responseListener.onSuccess(method, response.body());
|
||||
Log.i(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
} else {
|
||||
responseListener.onFail(method, String.valueOf(response.code()));
|
||||
Log.e(TAG, "requestData " + method + " onResponse " + response.code());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List> call, @NonNull Throwable t) {
|
||||
responseListener.onFail(method, String.valueOf(t.getMessage()));
|
||||
Log.e(TAG, "requestData " + method + " onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
responseListener.onFail(method, "undeclared method");
|
||||
Log.e(TAG, "requestData " + method + " onFailure - undeclared method");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.tangem.data.network.model;
|
||||
|
||||
public class AdaliteBody {
|
||||
private String signedTx;
|
||||
|
||||
public AdaliteBody(String signedTx) {
|
||||
this.signedTx = signedTx;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.tangem.data.network.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class AdaliteResponse(
|
||||
@SerializedName("Right")
|
||||
var right: AddressData? = null
|
||||
)
|
||||
|
||||
data class AdaliteResponseUtxo(
|
||||
@SerializedName("Right")
|
||||
var right: List<UtxoData>
|
||||
)
|
||||
|
||||
data class AddressData(
|
||||
@SerializedName("caAddress")
|
||||
var caAddress: String? = null,
|
||||
|
||||
@SerializedName("caBalance")
|
||||
var caBalance: AdaliteCoins? = null
|
||||
)
|
||||
|
||||
data class AdaliteCoins(
|
||||
@SerializedName("getCoin")
|
||||
var getCoin: Long? = null
|
||||
)
|
||||
|
||||
data class UtxoData(
|
||||
@SerializedName("cuId")
|
||||
var cuId: String? = null,
|
||||
|
||||
@SerializedName("cuOutIndex")
|
||||
var cuOutIndex: Int? = null,
|
||||
|
||||
@SerializedName("cuCoins")
|
||||
var cuCoins: AdaliteCoins? = null
|
||||
)
|
||||
|
|
@ -143,7 +143,7 @@ public abstract class CoinData {
|
|||
|
||||
public void clearInfo() {
|
||||
setIsBalanceEqual(false);
|
||||
setBalanceReceived(false); // TODO check
|
||||
setBalanceReceived(false);
|
||||
setValidationNodeDescription("");
|
||||
minFee=null;
|
||||
maxFee=null;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import android.text.InputFilter;
|
|||
import com.tangem.tangemcommon.reader.CardProtocol;
|
||||
import com.tangem.tangemcommon.tasks.SignTask;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
|
|
@ -15,6 +16,8 @@ import java.text.DecimalFormat;
|
|||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
import co.nstant.in.cbor.CborException;
|
||||
|
||||
/**
|
||||
* Created by Ilia on 15.02.2018.
|
||||
*/
|
||||
|
|
@ -189,7 +192,6 @@ public abstract class CoinEngine {
|
|||
|
||||
public abstract boolean checkNewTransactionAmount(Amount amount);
|
||||
|
||||
// TODO - move minFeeInInternalUnits to CoinData
|
||||
public abstract boolean checkNewTransactionAmountAndFee(Amount amount, Amount fee, Boolean isFeeIncluded);
|
||||
|
||||
public abstract boolean validateBalance(BalanceValidator balanceValidator);
|
||||
|
|
@ -214,7 +216,7 @@ public abstract class CoinEngine {
|
|||
|
||||
public abstract boolean validateAddress(String address);
|
||||
|
||||
public abstract String calculateAddress(byte[] pkUncompressed) throws NoSuchProviderException, NoSuchAlgorithmException;
|
||||
public abstract String calculateAddress(byte[] pkUncompressed) throws NoSuchProviderException, NoSuchAlgorithmException, CborException, IOException;
|
||||
|
||||
public abstract Amount convertToAmount(InternalAmount internalAmount) throws Exception;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.tangem.domain.wallet.eth.EthEngine
|
|||
import com.tangem.domain.wallet.token.TokenEngine
|
||||
import com.tangem.domain.wallet.bch.BtcCashEngine
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.domain.wallet.cardano.CardanoEngine
|
||||
import com.tangem.domain.wallet.ltc.LtcEngine
|
||||
import com.tangem.domain.wallet.nftToken.NftTokenEngine
|
||||
import com.tangem.domain.wallet.rsk.RskEngine
|
||||
|
|
@ -33,6 +34,7 @@ object CoinEngineFactory {
|
|||
Blockchain.Litecoin -> LtcEngine()
|
||||
Blockchain.Rootstock -> RskEngine()
|
||||
Blockchain.RootstockToken -> RskTokenEngine()
|
||||
Blockchain.Cardano -> CardanoEngine()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
@ -57,6 +59,8 @@ object CoinEngineFactory {
|
|||
RskEngine(context)
|
||||
else if (Blockchain.RootstockToken == context.blockchain)
|
||||
RskTokenEngine(context)
|
||||
else if (Blockchain.Cardano == context.blockchain)
|
||||
CardanoEngine(context)
|
||||
else
|
||||
return null
|
||||
} catch (e: Exception) {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ enum class BitcoinCashNode(val host: String, val port: Int, val proto: String) {
|
|||
N_005("bch.crypto.mldlabs.com", 50002, "ssl"),
|
||||
N_006("electron.coinucopia.io", 50002, "ssl"),
|
||||
N_007("blackie.c3-soft.com", 50002, "ssl"),
|
||||
N_008("electroncash.ueo.ch", 51002, "ssl"),
|
||||
N_009("electrum.imaginary.cash", 50002, "ssl"),
|
||||
N_010("bitcoincash.quangld.com", 50002, "ssl"),
|
||||
N_011("bch.stitthappens.com", 50002, "ssl"),
|
||||
N_008("electrum.imaginary.cash", 50002, "ssl"),
|
||||
N_009("bitcoincash.quangld.com", 50002, "ssl"),
|
||||
N_010("bch.stitthappens.com", 50002, "ssl"),
|
||||
}
|
||||
|
|
@ -2,44 +2,31 @@ package com.tangem.domain.wallet.btc
|
|||
|
||||
enum class BitcoinNode(val host: String, val port: Int, val proto: String) {
|
||||
N_001("electrum.anduck.net", 50001, "tcp"),
|
||||
N_002("ip119.ip-54-37-91.eu", 50001, "tcp"),
|
||||
N_003("electrum.qtornado.com", 50001, "tcp"),
|
||||
N_004("ip239.ip-54-36-234.eu", 50001, "tcp"),
|
||||
N_005("electrum-server.ninja", 50001, "tcp"),
|
||||
N_006("vps.hsmiths.com", 8080, "tcp"),
|
||||
N_007("ip120.ip-54-37-91.eu", 50001, "tcp"),
|
||||
N_008("ip101.ip-54-37-91.eu", 50001, "tcp"),
|
||||
N_009("e-x.not.fyi", 50001, "tcp"),
|
||||
N_010("electrum.vom-stausee.de", 50001, "tcp"),
|
||||
N_011("electrum2.eff.ro", 50001, "tcp"),
|
||||
N_012("electrum.coinucopia.io", 50001, "tcp"),
|
||||
N_013("b.ooze.cc", 50002, "ssl"),
|
||||
N_014("electrum.nute.net", 50002, "ssl"),
|
||||
N_015("electrum.coinop.cc", 50002, "ssl"),
|
||||
N_016("electrum.vom-stausee.de", 50002, "ssl"),
|
||||
N_017("ip119.ip-54-37-91.eu", 50002, "ssl"),
|
||||
N_018("ip101.ip-54-37-91.eu", 50002, "ssl"),
|
||||
N_019("dedi.jochen-hoenicke.de", 50002, "ssl"),
|
||||
N_020("ip239.ip-54-36-234.eu", 50002, "ssl"),
|
||||
N_021("e-x.not.fyi", 50002, "ssl"),
|
||||
N_022("ip120.ip-54-37-91.eu", 50002, "ssl"),
|
||||
N_023("electrum.villocq.com", 50002, "ssl"),
|
||||
N_024("electrum.anduck.net", 50012, "ssl"),
|
||||
N_025("technetium.network", 50002, "ssl"),
|
||||
N_026("electrum.coinucopia.io", 50002, "ssl"),
|
||||
N_027("dimon.trimon.de", 50002, "ssl"),
|
||||
N_028("btc.gravitech.net", 50002, "ssl"),
|
||||
N_029("hetzner01.fischl-online.de", 50002, "ssl"),
|
||||
N_030("fn.48.org", 50002, "ssl"),
|
||||
N_031("185.64.116.15", 50002, "ssl"),
|
||||
N_032("vps.hsmiths.com", 50002, "ssl"),
|
||||
N_033("104.250.141.242", 50002, "ssl"),
|
||||
N_034("electrum.qtornado.com", 50002, "ssl"),
|
||||
N_035("electrum-server.ninja", 50002, "ssl"),
|
||||
N_036("electrum2.eff.ro", 50002, "ssl"),
|
||||
N_037("electrum.hsmiths.com", 995, "ssl"),
|
||||
N_038("electrum.hsmiths.com", 50002, "ssl"),
|
||||
N_039("139.162.14.142", 50002, "ssl"),
|
||||
N_040("tardis.bauerj.eu", 50002, "ssl"),
|
||||
N_041("such.ninja", 50002, "ssl"),
|
||||
N_002("electrum.qtornado.com", 50001, "tcp"),
|
||||
N_003("e-x.not.fyi", 50001, "tcp"),
|
||||
N_004("electrum.vom-stausee.de", 50001, "tcp"),
|
||||
N_005("electrum2.eff.ro", 50001, "tcp"),
|
||||
N_006("electrum.coinucopia.io", 50001, "tcp"),
|
||||
N_007("electrum.nute.net", 50002, "ssl"),
|
||||
N_008("electrum.coinop.cc", 50002, "ssl"),
|
||||
N_009("electrum.vom-stausee.de", 50002, "ssl"),
|
||||
N_010("dedi.jochen-hoenicke.de", 50002, "ssl"),
|
||||
N_011("e-x.not.fyi", 50002, "ssl"),
|
||||
N_012("ip120.ip-54-37-91.eu", 50002, "ssl"),
|
||||
N_013("electrum.villocq.com", 50002, "ssl"),
|
||||
N_014("electrum.anduck.net", 50012, "ssl"),
|
||||
N_015("technetium.network", 50002, "ssl"),
|
||||
N_016("electrum.coinucopia.io", 50002, "ssl"),
|
||||
N_017("dimon.trimon.de", 50002, "ssl"),
|
||||
N_018("btc.gravitech.net", 50002, "ssl"),
|
||||
N_019("hetzner01.fischl-online.de", 50002, "ssl"),
|
||||
N_020("fn.48.org", 50002, "ssl"),
|
||||
N_021("vps.hsmiths.com", 50002, "ssl"),
|
||||
N_022("electrum.qtornado.com", 50002, "ssl"),
|
||||
N_023("electrum-server.ninja", 50002, "ssl"),
|
||||
N_024("electrum2.eff.ro", 50002, "ssl"),
|
||||
N_025("electrum.hsmiths.com", 995, "ssl"),
|
||||
N_026("electrum.hsmiths.com", 50002, "ssl"),
|
||||
N_027("139.162.14.142", 50002, "ssl"),
|
||||
N_028("tardis.bauerj.eu", 50002, "ssl"),
|
||||
}
|
||||
|
|
@ -195,7 +195,6 @@ public class BtcEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public Uri getShareWalletUri() {
|
||||
byte[] x = new byte[] {0,0,0,0,0,0,0,0};
|
||||
if (ctx.getCard().getDenomination() != null && !ctx.getCard().getDenominationText().equals("0.00")) {
|
||||
return Uri.parse("bitcoin:" + ctx.getCoinData().getWallet() + "?amount=" + convertToAmount(convertToInternalAmount(ctx.getCard().getDenomination())).toValueString(8));
|
||||
} else {
|
||||
|
|
|
|||
2098
app/src/main/java/com/tangem/domain/wallet/cardano/Blake2b.java
Normal file
2098
app/src/main/java/com/tangem/domain/wallet/cardano/Blake2b.java
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,122 @@
|
|||
package com.tangem.domain.wallet.cardano;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.domain.wallet.CoinData;
|
||||
import com.tangem.domain.wallet.CoinEngine;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CardanoData extends CoinData {
|
||||
public CardanoData() {
|
||||
super();
|
||||
}
|
||||
|
||||
private Long balance;
|
||||
|
||||
public String getUnspentInputsDescription() {
|
||||
try {
|
||||
// int gatheredUnspents = 0;
|
||||
if( unspentOutputs ==null ) return "";
|
||||
// for (int i = 0; i < unspentOutputs.size(); i++) {
|
||||
// if (unspentOutputs.get(i).Raw != null && unspentOutputs.get(i).Raw.length() > 1) gatheredUnspents++;
|
||||
// }
|
||||
return String.valueOf(unspentOutputs.size()) + " unspents";// (" + String.valueOf(gatheredUnspents) + " received)";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnspentOutput {
|
||||
public String txID;
|
||||
public Long Amount;
|
||||
public Integer Index;
|
||||
|
||||
public Bundle getAsBundle() {
|
||||
Bundle B = new Bundle();
|
||||
B.putString("txID", txID);
|
||||
B.putLong("Amount", Amount);
|
||||
B.putInt("Index", Index);
|
||||
return B;
|
||||
}
|
||||
|
||||
public void loadFromBundle(Bundle B) {
|
||||
txID = B.getString("txID");
|
||||
Amount = B.getLong("Amount");
|
||||
Index = B.getInt("Index");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<UnspentOutput> unspentOutputs = null;
|
||||
|
||||
public List<UnspentOutput> getUnspentOutputs() {
|
||||
if (unspentOutputs == null) unspentOutputs = new ArrayList<>();
|
||||
return unspentOutputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromBundle(Bundle B) {
|
||||
super.loadFromBundle(B);
|
||||
|
||||
if (B.containsKey("Balance")) balance = B.getLong("Balance");
|
||||
else balance = null;
|
||||
if (B.containsKey("UnspentTransactions")) {
|
||||
unspentOutputs = new ArrayList<>();
|
||||
Bundle BB = B.getBundle("UnspentTransactions");
|
||||
Integer i = 0;
|
||||
while (BB.containsKey(i.toString())) {
|
||||
UnspentOutput t = new UnspentOutput();
|
||||
t.loadFromBundle(BB.getBundle(i.toString()));
|
||||
unspentOutputs.add(t);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveToBundle(Bundle B) {
|
||||
super.saveToBundle(B);
|
||||
try {
|
||||
if (unspentOutputs != null) {
|
||||
Bundle BB = new Bundle();
|
||||
for (Integer i = 0; i < unspentOutputs.size(); i++) {
|
||||
BB.putBundle(i.toString(), unspentOutputs.get(i).getAsBundle());
|
||||
}
|
||||
B.putBundle("UnspentTransactions", BB);
|
||||
}
|
||||
if (balance != null) B.putLong("Balance", balance);
|
||||
} catch (Exception e) {
|
||||
Log.e("Can't save to bundle ", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearInfo() {
|
||||
super.clearInfo();
|
||||
balance = null;
|
||||
unspentOutputs = null;
|
||||
}
|
||||
|
||||
public CoinEngine.InternalAmount getBalanceInInternalUnits() {
|
||||
return new CoinEngine.InternalAmount(BigDecimal.valueOf(balance),"Lovelace");
|
||||
}
|
||||
|
||||
public void setBalance(Long balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public Long getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public boolean hasBalanceInfo() {
|
||||
return balance != null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,759 @@
|
|||
package com.tangem.domain.wallet.cardano;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.text.InputFilter;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.data.network.ServerApiAdalite;
|
||||
import com.tangem.data.network.model.AdaliteResponse;
|
||||
import com.tangem.data.network.model.AdaliteResponseUtxo;
|
||||
import com.tangem.data.network.model.UtxoData;
|
||||
import com.tangem.domain.wallet.BTCUtils;
|
||||
import com.tangem.domain.wallet.BalanceValidator;
|
||||
import com.tangem.domain.wallet.Base58;
|
||||
import com.tangem.domain.wallet.CoinData;
|
||||
import com.tangem.domain.wallet.CoinEngine;
|
||||
import com.tangem.domain.wallet.TangemContext;
|
||||
import com.tangem.tangemcommon.data.TangemCard;
|
||||
import com.tangem.tangemcommon.reader.CardProtocol;
|
||||
import com.tangem.tangemcommon.tasks.SignTask;
|
||||
import com.tangem.tangemcommon.util.Util;
|
||||
import com.tangem.util.DecimalDigitsInputFilter;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import org.spongycastle.crypto.Digest;
|
||||
import org.spongycastle.crypto.util.DigestFactory;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import co.nstant.in.cbor.CborBuilder;
|
||||
import co.nstant.in.cbor.CborDecoder;
|
||||
import co.nstant.in.cbor.CborEncoder;
|
||||
import co.nstant.in.cbor.CborException;
|
||||
import co.nstant.in.cbor.builder.ArrayBuilder;
|
||||
import co.nstant.in.cbor.model.Array;
|
||||
import co.nstant.in.cbor.model.ByteString;
|
||||
import co.nstant.in.cbor.model.DataItem;
|
||||
import co.nstant.in.cbor.model.UnsignedInteger;
|
||||
|
||||
import static com.tangem.domain.wallet.Base58.decodeBase58;
|
||||
import static com.tangem.domain.wallet.Base58.encodeBase58;
|
||||
|
||||
public class CardanoEngine extends CoinEngine {
|
||||
|
||||
private static final String TAG = CardanoEngine.class.getSimpleName();
|
||||
|
||||
private static final long protocolMagic = 764824073;
|
||||
|
||||
public CardanoData coinData = null;
|
||||
|
||||
public CardanoEngine(TangemContext context) throws Exception {
|
||||
super(context);
|
||||
if (context.getCoinData() == null) {
|
||||
coinData = new CardanoData();
|
||||
context.setCoinData(coinData);
|
||||
} else if (context.getCoinData() instanceof CardanoData) {
|
||||
coinData = (CardanoData) context.getCoinData();
|
||||
} else {
|
||||
throw new Exception("Invalid type of Blockchain data for CardanoEngine");
|
||||
}
|
||||
}
|
||||
|
||||
public CardanoEngine() {
|
||||
super();
|
||||
}
|
||||
|
||||
private static int getDecimals() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
|
||||
private void checkBlockchainDataExists() throws Exception {
|
||||
if (coinData == null) throw new Exception("No blockchain data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean awaitingConfirmation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBalanceHTML() {
|
||||
Amount balance = getBalance();
|
||||
if (balance != null) {
|
||||
return balance.toDescriptionString(getDecimals());
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBalanceCurrency() {
|
||||
return "ADA";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOfflineBalanceHTML() {
|
||||
InternalAmount offlineInternalAmount = convertToInternalAmount(ctx.getCard().getOfflineBalance());
|
||||
Amount offlineAmount = convertToAmount(offlineInternalAmount);
|
||||
return offlineAmount.toDescriptionString(getDecimals());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBalanceNotZero() {
|
||||
if (coinData == null) return false;
|
||||
if (coinData.getBalanceInInternalUnits() == null) return false;
|
||||
return coinData.getBalanceInInternalUnits().notZero();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBalanceInfo() {
|
||||
if (coinData == null) return false;
|
||||
return coinData.hasBalanceInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExtractPossible() {
|
||||
if (!hasBalanceInfo()) {
|
||||
ctx.setMessage(R.string.cannot_obtain_data_from_blockchain);
|
||||
} else if (!isBalanceNotZero()) {
|
||||
ctx.setMessage(R.string.wallet_empty);
|
||||
} else if (awaitingConfirmation()) {
|
||||
ctx.setMessage(R.string.please_wait_while_previous);
|
||||
} else if (coinData.getUnspentOutputs().size() == 0) {
|
||||
ctx.setMessage(R.string.please_wait_for_confirmation);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeeCurrency() {
|
||||
return "ADA";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateAddress(String address) {
|
||||
if (address == null || address.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] decAddress = Base58.decodeBase58(address);
|
||||
|
||||
if (decAddress == null || decAddress.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(decAddress);
|
||||
try {
|
||||
List<DataItem> addressList = ((Array) new CborDecoder(bais).decode().get(0)).getDataItems();
|
||||
byte[] addressBytes = ((ByteString) addressList.get(0)).getBytes();
|
||||
long addressChecksum = ((UnsignedInteger) addressList.get(1)).getValue().longValue();
|
||||
|
||||
final CRC32 crc32 = new CRC32();
|
||||
crc32.update(addressBytes);
|
||||
long calculatedChecksum = crc32.getValue();
|
||||
|
||||
if (addressChecksum != calculatedChecksum) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNeedCheckNode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri getWalletExplorerUri() {
|
||||
return Uri.parse("https://cardanoexplorer.com/address/" + ctx.getCoinData().getWallet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri getShareWalletUri() {
|
||||
return Uri.parse(ctx.getCoinData().getWallet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputFilter[] getAmountInputFilters() {
|
||||
return new InputFilter[]{new DecimalDigitsInputFilter(getDecimals())};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNewTransactionAmount(Amount amount) {
|
||||
if (coinData == null) return false;
|
||||
if (amount.compareTo(convertToAmount(coinData.getBalanceInInternalUnits())) > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNewTransactionAmountAndFee(Amount amountValue, Amount feeValue, Boolean isIncludeFee) {
|
||||
InternalAmount fee;
|
||||
InternalAmount amount;
|
||||
|
||||
try {
|
||||
checkBlockchainDataExists();
|
||||
amount = convertToInternalAmount(amountValue);
|
||||
fee = convertToInternalAmount(feeValue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fee == null || amount == null)
|
||||
return false;
|
||||
|
||||
if (fee.isZero() || amount.isZero())
|
||||
return false;
|
||||
|
||||
if (isIncludeFee && (amount.compareTo(coinData.getBalanceInInternalUnits()) > 0 || amount.compareTo(fee) < 0))
|
||||
return false;
|
||||
|
||||
if (!isIncludeFee && amount.add(fee).compareTo(coinData.getBalanceInInternalUnits()) > 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateBalance(BalanceValidator balanceValidator) {
|
||||
try {
|
||||
if (((ctx.getCard().getOfflineBalance() == null) && !ctx.getCoinData().isBalanceReceived()) || (!ctx.getCoinData().isBalanceReceived() && (ctx.getCard().getRemainingSignatures() != ctx.getCard().getMaxSignatures()))) {
|
||||
balanceValidator.setScore(0);
|
||||
balanceValidator.setFirstLine("Unknown balance");
|
||||
balanceValidator.setSecondLine("Balance cannot be verified. Swipe down to refresh.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (coinData.isBalanceReceived()) {// && coinData.isBalanceEqual()) { TODO:check
|
||||
balanceValidator.setScore(100);
|
||||
balanceValidator.setFirstLine("Verified balance");
|
||||
balanceValidator.setSecondLine("Balance confirmed in blockchain");
|
||||
if (coinData.getBalanceInInternalUnits().isZero()) {
|
||||
balanceValidator.setFirstLine("Empty wallet");
|
||||
balanceValidator.setSecondLine("");
|
||||
}
|
||||
}
|
||||
|
||||
if ((ctx.getCard().getOfflineBalance() != null) && !coinData.isBalanceReceived() && (ctx.getCard().getRemainingSignatures() == ctx.getCard().getMaxSignatures()) && coinData.getBalanceInInternalUnits().notZero()) {
|
||||
balanceValidator.setScore(80);
|
||||
balanceValidator.setFirstLine("Verified offline balance");
|
||||
balanceValidator.setSecondLine("Can't obtain balance from blockchain. Restore internet connection to be more confident. ");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Amount getBalance() {
|
||||
if (!hasBalanceInfo()) return null;
|
||||
return convertToAmount(coinData.getBalanceInInternalUnits());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String evaluateFeeEquivalent(String fee) {
|
||||
if (!coinData.getAmountEquivalentDescriptionAvailable()) return "";
|
||||
try {
|
||||
Amount feeAmount = new Amount(fee, getFeeCurrency());
|
||||
return feeAmount.toEquivalentString(coinData.getRate());
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBalanceEquivalent() {
|
||||
if (coinData == null || !coinData.getAmountEquivalentDescriptionAvailable()) return "";
|
||||
Amount balance = getBalance();
|
||||
if (balance == null) return "";
|
||||
return balance.toEquivalentString(coinData.getRate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String calculateAddress(byte[] pkUncompressed) throws CborException, IOException {
|
||||
|
||||
ByteArrayOutputStream exBaos = new ByteArrayOutputStream();
|
||||
exBaos.write(pkUncompressed);
|
||||
exBaos.write(BTCUtils.fromHex("0000000000000000000000000000000000000000000000000000000000000000"));
|
||||
byte[] pkExtended = exBaos.toByteArray();
|
||||
|
||||
exBaos.reset();
|
||||
new CborEncoder(exBaos).encode(new CborBuilder()
|
||||
.addArray()
|
||||
.add(0)
|
||||
.addArray()
|
||||
.add(0)
|
||||
.add(pkExtended)
|
||||
.end()
|
||||
.addMap()
|
||||
.end()
|
||||
.end()
|
||||
.build());
|
||||
byte[] forSha3 = exBaos.toByteArray();
|
||||
|
||||
Digest sha3 = DigestFactory.createSHA3_256();
|
||||
sha3.update(forSha3, 0, forSha3.length);
|
||||
byte[] forBlake = new byte[32];
|
||||
sha3.doFinal(forBlake, 0);
|
||||
|
||||
final Blake2b blake2b = Blake2b.Digest.newInstance(28);
|
||||
byte[] pkHash = blake2b.digest(forBlake);
|
||||
|
||||
//pkHash + attributes
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
new CborEncoder(baos).encode(new CborBuilder()
|
||||
.addArray()
|
||||
.add(pkHash)
|
||||
.addMap()//additional attributes
|
||||
.end()
|
||||
.add(0)//address type
|
||||
.end()
|
||||
.build());
|
||||
byte[] addr = baos.toByteArray();
|
||||
|
||||
final CRC32 crc32 = new CRC32();
|
||||
crc32.update(addr);
|
||||
long checksum = crc32.getValue();
|
||||
|
||||
DataItem addrItem = new CborBuilder().add(addr).build().get(0);
|
||||
addrItem.setTag(24);
|
||||
|
||||
//addr + checksum
|
||||
baos.reset();
|
||||
new CborEncoder(baos).encode(new CborBuilder()
|
||||
.addArray()
|
||||
.add(addrItem)
|
||||
.add(checksum)
|
||||
.end()
|
||||
.build());
|
||||
|
||||
byte[] hexAddress = baos.toByteArray();
|
||||
return encodeBase58(hexAddress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Amount convertToAmount(InternalAmount internalAmount) {
|
||||
BigDecimal d = internalAmount.divide(new BigDecimal("1000000"));
|
||||
return new Amount(d, getBalanceCurrency());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Amount convertToAmount(String strAmount, String currency) {
|
||||
return new Amount(strAmount, currency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalAmount convertToInternalAmount(Amount amount) {
|
||||
BigDecimal d = amount.multiply(new BigDecimal("1000000"));
|
||||
return new InternalAmount(d, "Lovelace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalAmount convertToInternalAmount(byte[] bytes) {
|
||||
if (bytes == null) return null;
|
||||
byte[] reversed = new byte[bytes.length];
|
||||
for (int i = 0; i < bytes.length; i++) reversed[i] = bytes[bytes.length - i - 1];
|
||||
return new InternalAmount(Util.byteArrayToLong(reversed), "Lovelace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] convertToByteArray(InternalAmount internalAmount) {
|
||||
byte[] bytes = Util.longToByteArray(internalAmount.longValueExact());
|
||||
// byte[] reversed = new byte[bytes.length]; TODO: check if needed
|
||||
// for (int i = 0; i < bytes.length; i++) reversed[i] = bytes[bytes.length - i - 1];
|
||||
// return reversed;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoinData createCoinData() {
|
||||
return new CardanoData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnspentInputsDescription() {
|
||||
return coinData.getUnspentInputsDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignTask.TransactionToSign constructTransaction(Amount amountValue, Amount feeValue, boolean IncFee, String targetAddress) throws Exception {
|
||||
checkBlockchainDataExists();
|
||||
|
||||
String myAddress = ctx.getCoinData().getWallet();
|
||||
byte[] pbKey = ctx.getCard().getWalletPublicKey();
|
||||
List<CardanoData.UnspentOutput> utxoList = coinData.getUnspentOutputs();
|
||||
long fullAmount = coinData.getBalance();
|
||||
|
||||
// long fullAmount = 0; TODO: check
|
||||
// for (int i = 0; i < unspentOutputs.size(); ++i) {
|
||||
// fullAmount += unspentOutputs.get(i).value;
|
||||
// }
|
||||
|
||||
long fees = convertToInternalAmount(feeValue).longValueExact();
|
||||
long amount = convertToInternalAmount(amountValue).longValueExact();
|
||||
long change = fullAmount - amount;
|
||||
if (IncFee) {
|
||||
amount = amount - fees;
|
||||
} else {
|
||||
change = change - fees;
|
||||
}
|
||||
|
||||
final long amountFinal = amount;
|
||||
final long changeFinal = change;
|
||||
|
||||
if (amount + fees > fullAmount) {
|
||||
throw new CardProtocol.TangemException_WrongAmount(String.format("Balance (%d) < change (%d) + amount (%d)", fullAmount, change, amount));
|
||||
}
|
||||
|
||||
CborBuilder cborBuilder = new CborBuilder();
|
||||
ArrayBuilder<CborBuilder> txArray = cborBuilder.addArray();
|
||||
ArrayBuilder<ArrayBuilder<CborBuilder>> inputsArray = txArray.startArray();
|
||||
ArrayBuilder<ArrayBuilder<CborBuilder>> outputsArray = txArray.startArray();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
//Inputs
|
||||
for (CardanoData.UnspentOutput utxo : utxoList) {
|
||||
baos.reset();
|
||||
|
||||
//txID + inputPos
|
||||
new CborEncoder(baos).encode(new CborBuilder()
|
||||
.addArray()
|
||||
.add(Util.fromHexString(utxo.txID))
|
||||
.add(utxo.Index)
|
||||
.end()
|
||||
.build());
|
||||
byte[] input = baos.toByteArray();
|
||||
|
||||
DataItem inputItem = new CborBuilder().add(input).build().get(0);
|
||||
inputItem.setTag(24);
|
||||
|
||||
//input type + input
|
||||
inputsArray
|
||||
.addArray()
|
||||
.add(0)
|
||||
.add(inputItem)
|
||||
.end();
|
||||
}
|
||||
|
||||
//1st output
|
||||
DataItem targetAddressItem = new CborDecoder(new ByteArrayInputStream(decodeBase58(targetAddress))).decode().get(0);
|
||||
outputsArray
|
||||
.addArray()
|
||||
.add(targetAddressItem)
|
||||
.add(amountFinal)
|
||||
.end();
|
||||
//2nd output (optional)
|
||||
if (changeFinal > 0) {
|
||||
DataItem myAddressItem = new CborDecoder(new ByteArrayInputStream(decodeBase58(myAddress))).decode().get(0);
|
||||
outputsArray
|
||||
.addArray()
|
||||
.add(myAddressItem)
|
||||
.add(changeFinal)
|
||||
.end();
|
||||
}
|
||||
|
||||
inputsArray.end();
|
||||
outputsArray.end();
|
||||
|
||||
txArray.addMap().end();
|
||||
|
||||
baos.reset();
|
||||
new CborEncoder(baos).encode(cborBuilder.build());
|
||||
byte[] txBody = baos.toByteArray();
|
||||
|
||||
final Blake2b blake2b = Blake2b.Digest.newInstance(32);//28?
|
||||
byte[] txHash = blake2b.digest(txBody);
|
||||
|
||||
baos.reset();
|
||||
new CborEncoder(baos).encode(new CborBuilder().add(protocolMagic).build());
|
||||
byte[] magic = baos.toByteArray();
|
||||
|
||||
//dataToSign prefix
|
||||
baos.reset();
|
||||
baos.write(new byte[]{(byte) 0x01});
|
||||
baos.write(magic);
|
||||
baos.write(new byte[]{(byte) 0x58, (byte) 0x20});
|
||||
|
||||
baos.write(txHash);
|
||||
byte[] dataToSign = baos.toByteArray();
|
||||
|
||||
|
||||
return new SignTask.TransactionToSign() {
|
||||
|
||||
@Override
|
||||
public boolean isSigningMethodSupported(TangemCard.SigningMethod signingMethod) {
|
||||
return signingMethod == TangemCard.SigningMethod.Sign_Hash || signingMethod == TangemCard.SigningMethod.Sign_Raw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[][] getHashesToSign() throws Exception {
|
||||
byte[][] dataForSign = new byte[1][];
|
||||
dataForSign[0] = dataToSign;
|
||||
return dataForSign;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getRawDataToSign() throws Exception {
|
||||
throw new Exception("Signing Raw Data is not supported for Cardano");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHashAlgToSign() {
|
||||
return "sha-256x2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getIssuerTransactionSignature(byte[] dataToSignByIssuer) throws Exception {
|
||||
throw new Exception("Issuer validation not supported!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] onSignCompleted(byte[] signFromCard) throws Exception {
|
||||
ByteArrayOutputStream exBaos = new ByteArrayOutputStream();
|
||||
exBaos.write(ctx.getCard().getWalletPublicKey());
|
||||
exBaos.write(BTCUtils.fromHex("0000000000000000000000000000000000000000000000000000000000000000"));
|
||||
byte[] pkExtended = exBaos.toByteArray();
|
||||
|
||||
//pubkey + signature
|
||||
baos.reset();
|
||||
new CborEncoder(baos).encode(new CborBuilder()
|
||||
.addArray()
|
||||
.add(pkExtended)
|
||||
.add(signFromCard)
|
||||
.end()
|
||||
.build());
|
||||
byte[] witnessBody = baos.toByteArray();
|
||||
DataItem witnessBodyItem = new CborBuilder().add(witnessBody).build().get(0);
|
||||
witnessBodyItem.setTag(24);
|
||||
|
||||
//array of witnesses
|
||||
CborBuilder witnessBuilder = new CborBuilder();
|
||||
ArrayBuilder<CborBuilder> witnessArrayBuilder = witnessBuilder.addArray();
|
||||
|
||||
//witness type + witness body
|
||||
for (CardanoData.UnspentOutput utxo : coinData.getUnspentOutputs()) {
|
||||
witnessArrayBuilder
|
||||
.addArray()
|
||||
.add(0)
|
||||
.add(witnessBodyItem)
|
||||
.end();
|
||||
}
|
||||
|
||||
baos.reset();
|
||||
new CborEncoder(baos).encode(witnessBuilder.build());
|
||||
byte[] witness = baos.toByteArray();
|
||||
|
||||
baos.reset();
|
||||
baos.write(new byte[]{(byte) 0x82});
|
||||
baos.write(txBody);
|
||||
baos.write(witness);
|
||||
// new CborEncoder(baos).encode(new CborBuilder()
|
||||
// .addArray()
|
||||
// .add(txBody)
|
||||
// .add(witness)
|
||||
// .end()
|
||||
// .build());
|
||||
byte[] txForSend = baos.toByteArray();
|
||||
notifyOnNeedSendTransaction(txForSend);
|
||||
//String hex = BTCUtils.toHex(txForSend);
|
||||
return txForSend;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private int calculateEstimatedTransactionSize(String targetAddress, Amount amount) {
|
||||
Amount feeDummy = new Amount(new BigDecimal(0.2).setScale(getDecimals(), RoundingMode.DOWN), getFeeCurrency());
|
||||
try {
|
||||
OnNeedSendTransaction onNeedSendTransactionBackup = onNeedSendTransaction;
|
||||
onNeedSendTransaction =(tx)->{}; // empty function to bypass exception
|
||||
|
||||
SignTask.TransactionToSign ttsDummy = constructTransaction(amount, feeDummy, true, targetAddress);
|
||||
byte[] txForSendDummy = ttsDummy.onSignCompleted(new byte[64]);
|
||||
|
||||
onNeedSendTransaction = onNeedSendTransactionBackup;
|
||||
Log.e(TAG, "txForSendDummy.length=" + String.valueOf(txForSendDummy.length));
|
||||
return txForSendDummy.length;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Can't calculate transaction size -> use default!");
|
||||
return 1000;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestBalanceAndUnspentTransactions(BlockchainRequestsCallbacks blockchainRequestsCallbacks) {
|
||||
final ServerApiAdalite serverApiAdalite = new ServerApiAdalite();
|
||||
|
||||
ServerApiAdalite.ResponseListener adaliteListener = new ServerApiAdalite.ResponseListener() {
|
||||
@Override
|
||||
public void onSuccess(String method, AdaliteResponse adaliteResponse) {
|
||||
Log.i(TAG, "onSuccess: " + method);
|
||||
try {
|
||||
String walletAddress = adaliteResponse.getRight().getCaAddress();
|
||||
if (!walletAddress.equals(coinData.getWallet())) {
|
||||
// todo - check
|
||||
throw new Exception("Invalid wallet address in answer!");
|
||||
}
|
||||
coinData.setBalanceReceived(true);
|
||||
coinData.setBalance(adaliteResponse.getRight().getCaBalance().getGetCoin());
|
||||
coinData.setValidationNodeDescription(ServerApiAdalite.lastNode);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "FAIL ADALITE_ADDRESS Exception");
|
||||
}
|
||||
|
||||
if (serverApiAdalite.isRequestsSequenceCompleted()) {
|
||||
blockchainRequestsCallbacks.onComplete(!ctx.hasError());
|
||||
} else {
|
||||
blockchainRequestsCallbacks.onProgress();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSuccess(String method, AdaliteResponseUtxo adaliteResponseUtxo) {
|
||||
Log.i(TAG, "onSuccess: " + method);
|
||||
try {
|
||||
coinData.getUnspentOutputs().clear();
|
||||
for (UtxoData utxo : adaliteResponseUtxo.getRight()) {
|
||||
CardanoData.UnspentOutput unspentOutput = new CardanoData.UnspentOutput();
|
||||
unspentOutput.txID = utxo.getCuId();
|
||||
unspentOutput.Amount = utxo.getCuCoins().getGetCoin();
|
||||
unspentOutput.Index = utxo.getCuOutIndex();
|
||||
coinData.getUnspentOutputs().add(unspentOutput);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (serverApiAdalite.isRequestsSequenceCompleted()) {
|
||||
blockchainRequestsCallbacks.onComplete(!ctx.hasError());
|
||||
} else {
|
||||
blockchainRequestsCallbacks.onProgress();
|
||||
Log.e(TAG, "FAIL INSIGHT_UNSPENT_OUTPUTS Exception");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String method, List listResponse) {
|
||||
Log.e(TAG, "Wrong response type for requestBalanceAndUnspentTransactions");
|
||||
ctx.setError("Wrong response type for requestBalanceAndUnspentTransactions");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String method, String message) {
|
||||
Log.i(TAG, "onFail: " + method + " " + message);
|
||||
ctx.setError(message);
|
||||
if (serverApiAdalite.isRequestsSequenceCompleted()) {
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
} else {
|
||||
blockchainRequestsCallbacks.onProgress();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
serverApiAdalite.setResponseListener(adaliteListener);
|
||||
|
||||
serverApiAdalite.requestData(ServerApiAdalite.ADALITE_ADDRESS, ctx.getCoinData().getWallet(), "");
|
||||
serverApiAdalite.requestData(ServerApiAdalite.ADALITE_UNSPENT_OUTPUTS, ctx.getCoinData().getWallet(), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestFee(BlockchainRequestsCallbacks blockchainRequestsCallbacks, String targetAddress, Amount amount) {
|
||||
final double A = 0.155381;
|
||||
final double B = 0.000043946;
|
||||
int calcSize = calculateEstimatedTransactionSize(targetAddress, amount);
|
||||
|
||||
double fee = A + B * calcSize;
|
||||
Amount feeAmount = new Amount(new BigDecimal(fee).setScale(getDecimals(), RoundingMode.UP), getFeeCurrency());
|
||||
|
||||
coinData.minFee = feeAmount;
|
||||
coinData.normalFee = feeAmount;
|
||||
coinData.maxFee = feeAmount;
|
||||
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestSendTransaction(BlockchainRequestsCallbacks blockchainRequestsCallbacks, byte[] txForSend) {
|
||||
final ServerApiAdalite serverApiAdalite = new ServerApiAdalite();
|
||||
final String txStr = Base64.encodeToString(txForSend, Base64.NO_WRAP);
|
||||
// BTCUtils.toHex(txForSend);
|
||||
|
||||
final ServerApiAdalite.ResponseListener responseListener = new ServerApiAdalite.ResponseListener() {
|
||||
@Override
|
||||
public void onSuccess(String method, AdaliteResponse adaliteResponse) {
|
||||
Log.e(TAG, "Wrong response type for requestSendTransaction");
|
||||
ctx.setError("Wrong response type for requestSendTransaction");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String method, AdaliteResponseUtxo adaliteResponseUtxo) {
|
||||
Log.e(TAG, "Wrong response type for requestSendTransaction");
|
||||
ctx.setError("Wrong response type for requestSendTransaction");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String method, List listResponse) {
|
||||
if (method.equals(ServerApiAdalite.ADALITE_SEND)) {
|
||||
String resultString = listResponse.toString();
|
||||
try {
|
||||
if (resultString.isEmpty()) {
|
||||
ctx.setError("No response from node");
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
} else { // TODO: Make check for a valid send response
|
||||
ctx.setError(null);
|
||||
blockchainRequestsCallbacks.onComplete(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (e.getMessage() != null) {
|
||||
ctx.setError(e.getMessage());
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
} else {
|
||||
ctx.setError(e.getClass().getName());
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
Log.e(TAG, resultString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(String method, String message) {
|
||||
if (!serverApiAdalite.isRequestsSequenceCompleted()) {
|
||||
ctx.setError(message);
|
||||
blockchainRequestsCallbacks.onComplete(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
serverApiAdalite.setResponseListener(responseListener);
|
||||
|
||||
serverApiAdalite.requestData(ServerApiAdalite.ADALITE_SEND, "", txStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowSelectFeeLevel() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package com.tangem.domain.wallet.cardano;
|
||||
|
||||
public final class CardanoUtils {
|
||||
}
|
||||
|
|
@ -253,7 +253,7 @@ public class DucatusEngine extends BtcEngine {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (coinData.isBalanceReceived() && coinData.isBalanceEqual()) {
|
||||
if (coinData.isBalanceReceived()) {// && coinData.isBalanceEqual()) { TODO:check
|
||||
balanceValidator.setScore(100);
|
||||
balanceValidator.setFirstLine("Verified balance");
|
||||
balanceValidator.setSecondLine("Balance confirmed in blockchain");
|
||||
|
|
|
|||
|
|
@ -321,8 +321,8 @@ public class EthEngine extends CoinEngine {
|
|||
|
||||
if (!coinData.getUnconfirmedTXCount().equals(coinData.getConfirmedTXCount())) {
|
||||
balanceValidator.setScore(0);
|
||||
balanceValidator.setFirstLine("Unguaranteed balance");
|
||||
balanceValidator.setSecondLine("Transaction is in progress. Wait for confirmation in blockchain.");
|
||||
balanceValidator.setFirstLine("Transaction in progress");
|
||||
balanceValidator.setSecondLine("Wait for confirmation in blockchain");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -394,8 +394,8 @@ public class TokenEngine extends CoinEngine {
|
|||
|
||||
if (!coinData.getUnconfirmedTXCount().equals(coinData.getConfirmedTXCount())) {
|
||||
balanceValidator.setScore(0);
|
||||
balanceValidator.setFirstLine("Unguaranteed balance");
|
||||
balanceValidator.setSecondLine("Transaction is in progress. Wait for confirmation in blockchain.");
|
||||
balanceValidator.setFirstLine("Transaction in progress");
|
||||
balanceValidator.setSecondLine("Wait for confirmation in blockchain");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -87,9 +87,8 @@ class ConfirmTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallbac
|
|||
|
||||
btnSend.visibility = View.INVISIBLE
|
||||
|
||||
val allowFeeLevelSelection = engine.allowSelectFeeLevel()
|
||||
for (lol in rgFee.touchables) {
|
||||
lol.isEnabled = allowFeeLevelSelection
|
||||
if (!engine.allowSelectFeeLevel()) {
|
||||
rgFee.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
// set listeners
|
||||
|
|
|
|||
|
|
@ -729,6 +729,7 @@ class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback
|
|||
Blockchain.Litecoin -> "litecoin"
|
||||
Blockchain.Rootstock -> "bitcoin"
|
||||
Blockchain.RootstockToken -> "bitcoin"
|
||||
Blockchain.Cardano -> "cardano"
|
||||
else -> {
|
||||
throw Exception("Can''t get rate for blockchain " + ctx.blockchainName)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@
|
|||
|
||||
<EditText
|
||||
android:id="@+id/etFee"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:enabled="false"
|
||||
|
|
@ -278,7 +278,7 @@
|
|||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintWidth_min="150dp" />
|
||||
app:layout_constraintWidth_min="130dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvCurrency2"
|
||||
|
|
|
|||
BIN
tangemcard-android/src/main/res/drawable/card_ff32.png
Normal file
BIN
tangemcard-android/src/main/res/drawable/card_ff32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
|
|
@ -49,7 +49,7 @@ class LocalStorage
|
|||
artworks = HashMap()
|
||||
}
|
||||
|
||||
if (artworks.count() == 0) {
|
||||
if (artworks.count() < 21) {
|
||||
// forceSave=true only on the last one
|
||||
putResourceArtworkToCatalog(R.drawable.card_default, false)
|
||||
putResourceArtworkToCatalog(R.drawable.card_default_nft, false)
|
||||
|
|
@ -70,7 +70,8 @@ class LocalStorage
|
|||
putResourceArtworkToCatalog(R.drawable.card_ru029, false)
|
||||
putResourceArtworkToCatalog(R.drawable.card_ru030, false)
|
||||
putResourceArtworkToCatalog(R.drawable.card_ru031, false)
|
||||
putResourceArtworkToCatalog(R.drawable.card_ru032, true)
|
||||
putResourceArtworkToCatalog(R.drawable.card_ru032, false)
|
||||
putResourceArtworkToCatalog(R.drawable.card_ff32, true)
|
||||
}
|
||||
if (batchesFile.exists()) {
|
||||
try {
|
||||
|
|
@ -243,6 +244,7 @@ class LocalStorage
|
|||
card.batch == "0020" -> R.drawable.card_ru030
|
||||
card.batch == "0021" -> R.drawable.card_ru031
|
||||
card.batch == "0022" -> R.drawable.card_ru032
|
||||
card.batch == "FF32" -> R.drawable.card_ff32
|
||||
|
||||
else -> null
|
||||
}
|
||||
|
|
|
|||
BIN
tangemserver-android/src/main/res/drawable/card_ff32.png
Normal file
BIN
tangemserver-android/src/main/res/drawable/card_ff32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
Loading…
Add table
Add a link
Reference in a new issue