mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39:22 +00:00
Merge branch 'main' into CW-766-coin-control-fixes-and-enhancements
This commit is contained in:
commit
edf9f29d23
8 changed files with 57 additions and 23 deletions
|
@ -1707,7 +1707,7 @@ abstract class ElectrumWalletBase
|
|||
try {
|
||||
final blockHash = await http.get(
|
||||
Uri.parse(
|
||||
"http://mempool.cakewallet.com:8999/api/v1/block-height/$height",
|
||||
"https://mempool.cakewallet.com/api/v1/block-height/$height",
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -1716,7 +1716,7 @@ abstract class ElectrumWalletBase
|
|||
jsonDecode(blockHash.body) != null) {
|
||||
final blockResponse = await http.get(
|
||||
Uri.parse(
|
||||
"http://mempool.cakewallet.com:8999/api/v1/block/${blockHash.body}",
|
||||
"https://mempool.cakewallet.com/api/v1/block/${blockHash.body}",
|
||||
),
|
||||
);
|
||||
if (blockResponse.statusCode == 200 &&
|
||||
|
|
|
@ -270,7 +270,7 @@ const bitcoinDates = {
|
|||
Future<int> getBitcoinHeightByDateAPI({required DateTime date}) async {
|
||||
final response = await http.get(
|
||||
Uri.parse(
|
||||
"http://mempool.cakewallet.com:8999/api/v1/mining/blocks/timestamp/${(date.millisecondsSinceEpoch / 1000).round()}",
|
||||
"https://mempool.cakewallet.com/api/v1/mining/blocks/timestamp/${(date.millisecondsSinceEpoch / 1000).round()}",
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -203,9 +203,30 @@ class Node extends HiveObject with Keyable {
|
|||
headers: {'Content-Type': 'application/json'},
|
||||
body: json.encode(body),
|
||||
);
|
||||
|
||||
client.close();
|
||||
|
||||
if ((
|
||||
response.body.contains("400 Bad Request") // Some other generic error
|
||||
|| response.body.contains("plain HTTP request was sent to HTTPS port") // Cloudflare
|
||||
|| response.headers["location"] != null // Generic reverse proxy
|
||||
|| response.body.contains("301 Moved Permanently") // Poorly configured generic reverse proxy
|
||||
) && !(useSSL??false)
|
||||
) {
|
||||
|
||||
final oldUseSSL = useSSL;
|
||||
useSSL = true;
|
||||
try {
|
||||
final ret = await requestMoneroNode();
|
||||
if (ret == true) {
|
||||
await save();
|
||||
return ret;
|
||||
}
|
||||
useSSL = oldUseSSL;
|
||||
} catch (e) {
|
||||
useSSL = oldUseSSL;
|
||||
}
|
||||
}
|
||||
|
||||
final resBody = json.decode(response.body) as Map<String, dynamic>;
|
||||
return !(resBody['result']['offline'] as bool);
|
||||
} catch (_) {
|
||||
|
|
|
@ -18,7 +18,7 @@ String getTxKey(String txId) {
|
|||
final status = monero.Wallet_status(wptr!);
|
||||
if (status != 0) {
|
||||
final error = monero.Wallet_errorString(wptr!);
|
||||
return txId+"_"+error;
|
||||
return "";
|
||||
}
|
||||
return txKey;
|
||||
}
|
||||
|
@ -92,7 +92,15 @@ Future<PendingTransactionDescription> createTransactionSync(
|
|||
List<String> preferredInputs = const []}) async {
|
||||
|
||||
final amt = amount == null ? 0 : monero.Wallet_amountFromString(amount);
|
||||
|
||||
|
||||
final waddr = wptr!.address;
|
||||
|
||||
// force reconnection in case the os killed the connection?
|
||||
// fixes failed to get block height error.
|
||||
Isolate.run(() async {
|
||||
monero.Wallet_synchronized(Pointer.fromAddress(waddr));
|
||||
});
|
||||
|
||||
final address_ = address.toNativeUtf8();
|
||||
final paymentId_ = paymentId.toNativeUtf8();
|
||||
if (preferredInputs.isEmpty) {
|
||||
|
@ -101,7 +109,6 @@ Future<PendingTransactionDescription> createTransactionSync(
|
|||
|
||||
final preferredInputs_ = preferredInputs.join(monero.defaultSeparatorStr).toNativeUtf8();
|
||||
|
||||
final waddr = wptr!.address;
|
||||
final addraddr = address_.address;
|
||||
final paymentIdAddr = paymentId_.address;
|
||||
final preferredInputsAddr = preferredInputs_.address;
|
||||
|
@ -362,16 +369,7 @@ class Transaction {
|
|||
confirmations = monero.TransactionInfo_confirmations(txInfo),
|
||||
fee = monero.TransactionInfo_fee(txInfo),
|
||||
description = monero.TransactionInfo_description(txInfo),
|
||||
key = getTxKey(txInfo);
|
||||
|
||||
static String getTxKey(monero.TransactionInfo txInfo) {
|
||||
final txKey = monero.Wallet_getTxKey(wptr!, txid: monero.TransactionInfo_hash(txInfo));
|
||||
final status = monero.Wallet_status(wptr!);
|
||||
if (status != 0) {
|
||||
return "";
|
||||
}
|
||||
return txKey;
|
||||
}
|
||||
key = getTxKey(monero.TransactionInfo_hash(txInfo));
|
||||
|
||||
Transaction.dummy({
|
||||
required this.displayLabel,
|
||||
|
|
|
@ -160,14 +160,15 @@ final storeMutex = Mutex();
|
|||
|
||||
int lastStorePointer = 0;
|
||||
int lastStoreHeight = 0;
|
||||
void storeSync() async {
|
||||
void storeSync({bool force = false}) async {
|
||||
final addr = wptr!.address;
|
||||
final synchronized = await Isolate.run(() {
|
||||
return monero.Wallet_synchronized(Pointer.fromAddress(addr));
|
||||
});
|
||||
if (lastStorePointer == wptr!.address &&
|
||||
lastStoreHeight + 5000 > monero.Wallet_blockChainHeight(wptr!) &&
|
||||
!synchronized) {
|
||||
!synchronized &&
|
||||
!force) {
|
||||
return;
|
||||
}
|
||||
lastStorePointer = wptr!.address;
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:cw_core/crypto_currency.dart';
|
|||
import 'package:cw_core/amount_converter.dart';
|
||||
|
||||
import 'package:cw_core/pending_transaction.dart';
|
||||
import 'package:cw_monero/api/wallet.dart';
|
||||
|
||||
class DoubleSpendException implements Exception {
|
||||
DoubleSpendException();
|
||||
|
@ -53,6 +54,7 @@ class PendingMoneroTransaction with PendingTransaction {
|
|||
|
||||
rethrow;
|
||||
}
|
||||
storeSync(force: true);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -273,7 +273,19 @@ Future<void> defaultSettingsMigration(
|
|||
newDefaultUri: newCakeWalletBitcoinUri,
|
||||
currentNodePreferenceKey: PreferencesKey.currentBitcoinElectrumSererIdKey,
|
||||
useSSL: true,
|
||||
oldUri: 'cakewallet.com',
|
||||
oldUri: ['cakewallet.com'],
|
||||
);
|
||||
_changeDefaultNode(
|
||||
nodes: nodes,
|
||||
sharedPreferences: sharedPreferences,
|
||||
type: WalletType.tron,
|
||||
newDefaultUri: tronDefaultNodeUri,
|
||||
currentNodePreferenceKey: PreferencesKey.currentTronNodeIdKey,
|
||||
useSSL: true,
|
||||
oldUri: [
|
||||
'tron-rpc.publicnode.com:443',
|
||||
'api.trongrid.io',
|
||||
],
|
||||
);
|
||||
break;
|
||||
|
||||
|
@ -300,11 +312,11 @@ Future<void> _changeDefaultNode({
|
|||
required String newDefaultUri,
|
||||
required String currentNodePreferenceKey,
|
||||
required bool useSSL,
|
||||
required String oldUri, // leave empty if you want to force replace the node regardless of the user's current node
|
||||
required List<String> oldUri, // leave empty if you want to force replace the node regardless of the user's current node
|
||||
}) async {
|
||||
final currentNodeId = sharedPreferences.getInt(currentNodePreferenceKey);
|
||||
final currentNode = nodes.values.firstWhere((node) => node.key == currentNodeId);
|
||||
final shouldReplace = currentNode.uriRaw.contains(oldUri);
|
||||
final shouldReplace = oldUri.any((e) => currentNode.uriRaw.contains(e));
|
||||
|
||||
if (shouldReplace) {
|
||||
var newNodeId =
|
||||
|
|
|
@ -159,7 +159,7 @@ abstract class TransactionDetailsViewModelBase with Store {
|
|||
case WalletType.monero:
|
||||
return 'https://monero.com/tx/${txId}';
|
||||
case WalletType.bitcoin:
|
||||
return 'https://mempool.space/${wallet.isTestnet ? "testnet/" : ""}tx/${txId}';
|
||||
return 'https://mempool.cakewallet.com/${wallet.isTestnet ? "testnet/" : ""}tx/${txId}';
|
||||
case WalletType.litecoin:
|
||||
return 'https://blockchair.com/litecoin/transaction/${txId}';
|
||||
case WalletType.bitcoinCash:
|
||||
|
|
Loading…
Reference in a new issue