Updated on 2026-08-14
This commit is contained in:
parent
23ed2c949c
commit
2550dff2f4
8 changed files with 17 additions and 185 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.data.network.task.loaded_wallet;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.data.network.request.ElectrumRequest;
|
||||
import com.tangem.data.network.task.ElectrumTask;
|
||||
|
|
@ -144,8 +145,8 @@ public class UpdateWalletInfoTask extends ElectrumTask {
|
|||
Integer height = jsUnspent.getInt("height");
|
||||
String hash = jsUnspent.getString("tx_hash");
|
||||
if (height != -1) {
|
||||
String nodeAddress = engine.getNextNode(loadedWallet.getCard());
|
||||
int nodePort = engine.getNextNodePort(loadedWallet.getCard());
|
||||
String nodeAddress = engine.getNode(loadedWallet.getCard());
|
||||
int nodePort = engine.getNodePort(loadedWallet.getCard());
|
||||
UpdateWalletInfoTask updateWalletInfoTask = new UpdateWalletInfoTask(loadedWallet, nodeAddress, nodePort);
|
||||
// loadedWallet.updateTasks.add(updateWalletInfoTask);
|
||||
updateWalletInfoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.getHeader(mWalletAddress, String.valueOf(height)), ElectrumRequest.getTransaction(mWalletAddress, hash));
|
||||
|
|
@ -239,7 +240,7 @@ public class UpdateWalletInfoTask extends ElectrumTask {
|
|||
} catch (BitcoinException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Log.e("TX", raw);
|
||||
Log.e("TX", raw);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
|
|
|||
|
|
@ -29,15 +29,6 @@ import static com.tangem.util.FormatUtil.GetDecimalFormat;
|
|||
*/
|
||||
|
||||
public class BtcCashEngine extends CoinEngine {
|
||||
public String getNextNode(TangemCard mCard) {
|
||||
|
||||
return "35.157.238.5";
|
||||
}
|
||||
|
||||
public int getNextNodePort(TangemCard mCard) {
|
||||
|
||||
return 51001;
|
||||
}
|
||||
|
||||
public String getNode(TangemCard mCard) {
|
||||
return "35.157.238.5";
|
||||
|
|
|
|||
|
|
@ -32,41 +32,9 @@ import static com.tangem.util.FormatUtil.stringToBigDecimal;
|
|||
*/
|
||||
|
||||
public class BtcEngine extends CoinEngine {
|
||||
public String getNextNode(TangemCard mCard) {
|
||||
return getNextServiceHost(mCard);
|
||||
}
|
||||
|
||||
public int getNextNodePort(TangemCard mCard) {
|
||||
return getNextServicePort(mCard);
|
||||
}
|
||||
|
||||
public String getNode(TangemCard mCard) {
|
||||
return getServiceHost(mCard);
|
||||
}
|
||||
|
||||
public int getNodePort(TangemCard mCard) {
|
||||
return getServicePort(mCard);
|
||||
}
|
||||
|
||||
public void switchNode(TangemCard mCard) {
|
||||
SelectNextBitconServiceIndex();
|
||||
}
|
||||
|
||||
private static String[] getBitcoinServiceHosts() {
|
||||
return new String[]{
|
||||
// BitcoinNode.n1.getHost(),
|
||||
// BitcoinNode.n2.getHost(),
|
||||
// BitcoinNode.n3.getHost(),
|
||||
// BitcoinNode.n4.getHost(),
|
||||
// BitcoinNode.n5.getHost(),
|
||||
// BitcoinNode.n6.getHost(),
|
||||
// BitcoinNode.n7.getHost(),
|
||||
// BitcoinNode.n8.getHost(),
|
||||
// BitcoinNode.n9.getHost(),
|
||||
// BitcoinNode.n10.getHost(),
|
||||
// BitcoinNode.n11.getHost(),
|
||||
// BitcoinNode.n12.getHost(),
|
||||
|
||||
BitcoinNode.n13.getHost(),
|
||||
BitcoinNode.n14.getHost(),
|
||||
BitcoinNode.n15.getHost(),
|
||||
|
|
@ -78,19 +46,6 @@ public class BtcEngine extends CoinEngine {
|
|||
|
||||
private static Integer[] getBitcoinServicePorts() {
|
||||
return new Integer[]{
|
||||
// BitcoinNode.n1.getPort(),
|
||||
// BitcoinNode.n2.getPort(),
|
||||
// BitcoinNode.n3.getPort(),
|
||||
// BitcoinNode.n4.getPort(),
|
||||
// BitcoinNode.n5.getPort(),
|
||||
// BitcoinNode.n6.getPort(),
|
||||
// BitcoinNode.n7.getPort(),
|
||||
// BitcoinNode.n8.getPort(),
|
||||
// BitcoinNode.n9.getPort(),
|
||||
// BitcoinNode.n10.getPort(),
|
||||
// BitcoinNode.n11.getPort(),
|
||||
// BitcoinNode.n12.getPort(),
|
||||
|
||||
BitcoinNode.n13.getPort(),
|
||||
BitcoinNode.n14.getPort(),
|
||||
BitcoinNode.n15.getPort(),
|
||||
|
|
@ -117,124 +72,28 @@ public class BtcEngine extends CoinEngine {
|
|||
BitcoinNodeTestNet.n4.getPort()};
|
||||
}
|
||||
|
||||
static int serviceIndex = GetNextBitconMainNetServiceIndex();
|
||||
static int serviceIndex = 0;
|
||||
|
||||
static int dynamicIndex = GetNextBitconMainNetServiceIndex();
|
||||
|
||||
static int serviceIndexTestNet = GetNextBitconTestNetServiceIndex();
|
||||
|
||||
static int dynamicTestNetIndex = GetNextBitconTestNetServiceIndex();
|
||||
|
||||
static long lastChangeServiceIndex = 0;
|
||||
|
||||
public static int GetNextBitconMainNetServiceIndex() {
|
||||
Random r = new Random();
|
||||
return r.nextInt(getBitcoinServiceHosts().length);
|
||||
}
|
||||
|
||||
public static void SelectNextBitconMainNetServiceIndex() {
|
||||
//serviceIndex = GetNextBitconMainNetServiceIndex();
|
||||
serviceIndex++;
|
||||
if (serviceIndex > getBitcoinServiceHosts().length - 1) serviceIndex = 0;
|
||||
}
|
||||
|
||||
public static int GetNextBitconTestNetServiceIndex() {
|
||||
Random r = new Random();
|
||||
return r.nextInt(getBitcoinTestNetServiceHosts().length);
|
||||
}
|
||||
|
||||
public static void SelectNextBitconTestNetServiceIndex() {
|
||||
//serviceIndexTestNet = GetNextBitconTestNetServiceIndex();
|
||||
|
||||
serviceIndexTestNet++;
|
||||
if (serviceIndexTestNet > getBitcoinTestNetServiceHosts().length - 1)
|
||||
serviceIndexTestNet = 0;
|
||||
}
|
||||
|
||||
public static void setNextDynamicIndex() {
|
||||
//dynamicIndex = GetNextBitconMainNetServiceIndex();
|
||||
dynamicIndex++;
|
||||
if (dynamicIndex > getBitcoinServiceHosts().length - 1) dynamicIndex = 0;
|
||||
}
|
||||
|
||||
public static void setNextDynamicTestNet() {
|
||||
//dynamicTestNetIndex = GetNextBitconTestNetServiceIndex();
|
||||
dynamicTestNetIndex++;
|
||||
if (dynamicTestNetIndex > getBitcoinTestNetServiceHosts().length - 1)
|
||||
dynamicTestNetIndex = 0;
|
||||
|
||||
}
|
||||
|
||||
public static void SelectNextBitconServiceIndex() {
|
||||
long unixTime = System.currentTimeMillis() / 1000L;
|
||||
long nextStampOffset = 5;
|
||||
if (lastChangeServiceIndex == 0) {
|
||||
lastChangeServiceIndex = unixTime;
|
||||
} else if (lastChangeServiceIndex + nextStampOffset > unixTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastChangeServiceIndex = unixTime;
|
||||
|
||||
SelectNextBitconMainNetServiceIndex();
|
||||
SelectNextBitconTestNetServiceIndex();
|
||||
}
|
||||
|
||||
public static String getServiceHost(TangemCard mCard) {
|
||||
public String getNode(TangemCard mCard) {
|
||||
switch (mCard.getBlockchain()) {
|
||||
case Bitcoin:
|
||||
return getBitcoinServiceHosts()[serviceIndex]; //"hsmiths.changeip.net";
|
||||
case BitcoinTestNet:
|
||||
return getBitcoinTestNetServiceHosts()[serviceIndexTestNet]; //"testnetnode.arihanc.com";
|
||||
return getBitcoinServiceHosts()[serviceIndex]; //
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getNextServiceHost(TangemCard mCard) {
|
||||
switch (mCard.getBlockchain()) {
|
||||
case Bitcoin: {
|
||||
setNextDynamicIndex();
|
||||
return getBitcoinServiceHosts()[dynamicIndex];
|
||||
}
|
||||
case BitcoinTestNet: {
|
||||
setNextDynamicTestNet();
|
||||
return getBitcoinTestNetServiceHosts()[dynamicTestNetIndex]; //"testnetnode.arihanc.com";
|
||||
}
|
||||
//case BitcoinCash:
|
||||
//{
|
||||
// return GetBitcoinCashServiceHosts()[0];
|
||||
//}
|
||||
//case BitcoinCashTestNet: {
|
||||
// return GetBitcoinCashTestNetServiceHosts()[0];
|
||||
//}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getNextServicePort(TangemCard mCard) {
|
||||
switch (mCard.getBlockchain()) {
|
||||
case Bitcoin: {
|
||||
setNextDynamicIndex();
|
||||
return getBitcoinServicePorts()[dynamicIndex];//8080;
|
||||
}
|
||||
case BitcoinTestNet: {
|
||||
setNextDynamicTestNet();
|
||||
return getBitcoinTestNetServicePorts()[dynamicTestNetIndex];//51001;
|
||||
}
|
||||
}
|
||||
return 8080;
|
||||
}
|
||||
|
||||
public static int getServicePort(TangemCard mCard) {
|
||||
public int getNodePort(TangemCard mCard) {
|
||||
switch (mCard.getBlockchain()) {
|
||||
case Bitcoin:
|
||||
return getBitcoinServicePorts()[serviceIndex];//8080;
|
||||
case BitcoinTestNet:
|
||||
return getBitcoinTestNetServicePorts()[serviceIndexTestNet];//51001;
|
||||
}
|
||||
return 8080;
|
||||
}
|
||||
|
||||
public void switchNode(TangemCard mCard) {
|
||||
serviceIndex++;
|
||||
if (serviceIndex > getBitcoinServiceHosts().length - 1) serviceIndex = 0;
|
||||
}
|
||||
|
||||
public boolean inOutPutVisible() {
|
||||
return true;
|
||||
|
|
@ -525,7 +384,7 @@ public class BtcEngine extends CoinEngine {
|
|||
}
|
||||
|
||||
if (amount + fees > fullAmount) {
|
||||
throw new CardProtocol.TangemException_WrongAmount(String.format("Balance (%d) < amount (%d) + (%d)", fullAmount, change, amount));
|
||||
throw new CardProtocol.TangemException_WrongAmount(String.format("Balance (%d) < change (%d) + amount (%d)", fullAmount, change, amount));
|
||||
}
|
||||
|
||||
byte[][] dataForSign = new byte[unspentOutputs.size()][];
|
||||
|
|
|
|||
|
|
@ -13,10 +13,6 @@ import java.security.NoSuchProviderException;
|
|||
|
||||
public abstract class CoinEngine {
|
||||
|
||||
public abstract String getNextNode(TangemCard card);
|
||||
|
||||
public abstract int getNextNodePort(TangemCard card);
|
||||
|
||||
public abstract String getNode(TangemCard card);
|
||||
|
||||
public abstract int getNodePort(TangemCard card);
|
||||
|
|
|
|||
|
|
@ -27,14 +27,6 @@ import static com.tangem.util.FormatUtil.GetDecimalFormat;
|
|||
|
||||
public class EthEngine extends CoinEngine {
|
||||
|
||||
public String getNextNode(TangemCard mCard) {
|
||||
return "abc1.hsmiths.com";
|
||||
}
|
||||
|
||||
public int getNextNodePort(TangemCard mCard) {
|
||||
return 60001;
|
||||
}
|
||||
|
||||
public String getNode(TangemCard mCard) {
|
||||
return "abc1.hsmiths.com";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,13 +27,6 @@ import static com.tangem.util.FormatUtil.GetDecimalFormat;
|
|||
*/
|
||||
|
||||
public class TokenEngine extends CoinEngine {
|
||||
public String getNextNode(TangemCard mCard) {
|
||||
return "abc1.hsmiths.com";
|
||||
}
|
||||
|
||||
public int getNextNodePort(TangemCard mCard) {
|
||||
return 60001;
|
||||
}
|
||||
|
||||
public String getNode(TangemCard mCard) {
|
||||
return "abc1.hsmiths.com";
|
||||
|
|
|
|||
|
|
@ -121,8 +121,8 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
val engineCoin = CoinEngineFactory.create(card!!.blockchain)
|
||||
|
||||
for (i in 0 until data.allRequest) {
|
||||
val nodeAddress = engineCoin!!.getNextNode(card)
|
||||
val nodePort = engineCoin.getNextNodePort(card)
|
||||
val nodeAddress = engineCoin!!.getNode(card)
|
||||
val nodePort = engineCoin.getNodePort(card)
|
||||
val connectTaskEx = ConnectTask(this@ConfirmPaymentActivity, nodeAddress, nodePort, data)
|
||||
connectTaskEx.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.checkBalance(card!!.wallet))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -259,8 +259,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
val height = jsUnspent.getInt("height")
|
||||
val hash = jsUnspent.getString("tx_hash")
|
||||
if (height != -1) {
|
||||
val nodeAddress = engine.getNextNode(card)
|
||||
val nodePort = engine.getNextNodePort(card)
|
||||
val nodeAddress = engine.getNode(card)
|
||||
val nodePort = engine.getNodePort(card)
|
||||
val updateWalletInfoTask = UpdateWalletInfoTask(this, nodeAddress, nodePort)
|
||||
// loadedWallet.updateTasks.add(updateWalletInfoTask);
|
||||
updateWalletInfoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.getHeader(mWalletAddress, height.toString()), ElectrumRequest.getTransaction(mWalletAddress, hash))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue