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 {
|
try {
|
||||||
final blockHash = await http.get(
|
final blockHash = await http.get(
|
||||||
Uri.parse(
|
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) {
|
jsonDecode(blockHash.body) != null) {
|
||||||
final blockResponse = await http.get(
|
final blockResponse = await http.get(
|
||||||
Uri.parse(
|
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 &&
|
if (blockResponse.statusCode == 200 &&
|
||||||
|
|
|
@ -270,7 +270,7 @@ const bitcoinDates = {
|
||||||
Future<int> getBitcoinHeightByDateAPI({required DateTime date}) async {
|
Future<int> getBitcoinHeightByDateAPI({required DateTime date}) async {
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse(
|
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'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: json.encode(body),
|
body: json.encode(body),
|
||||||
);
|
);
|
||||||
|
|
||||||
client.close();
|
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>;
|
final resBody = json.decode(response.body) as Map<String, dynamic>;
|
||||||
return !(resBody['result']['offline'] as bool);
|
return !(resBody['result']['offline'] as bool);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ String getTxKey(String txId) {
|
||||||
final status = monero.Wallet_status(wptr!);
|
final status = monero.Wallet_status(wptr!);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
final error = monero.Wallet_errorString(wptr!);
|
final error = monero.Wallet_errorString(wptr!);
|
||||||
return txId+"_"+error;
|
return "";
|
||||||
}
|
}
|
||||||
return txKey;
|
return txKey;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,15 @@ Future<PendingTransactionDescription> createTransactionSync(
|
||||||
List<String> preferredInputs = const []}) async {
|
List<String> preferredInputs = const []}) async {
|
||||||
|
|
||||||
final amt = amount == null ? 0 : monero.Wallet_amountFromString(amount);
|
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 address_ = address.toNativeUtf8();
|
||||||
final paymentId_ = paymentId.toNativeUtf8();
|
final paymentId_ = paymentId.toNativeUtf8();
|
||||||
if (preferredInputs.isEmpty) {
|
if (preferredInputs.isEmpty) {
|
||||||
|
@ -101,7 +109,6 @@ Future<PendingTransactionDescription> createTransactionSync(
|
||||||
|
|
||||||
final preferredInputs_ = preferredInputs.join(monero.defaultSeparatorStr).toNativeUtf8();
|
final preferredInputs_ = preferredInputs.join(monero.defaultSeparatorStr).toNativeUtf8();
|
||||||
|
|
||||||
final waddr = wptr!.address;
|
|
||||||
final addraddr = address_.address;
|
final addraddr = address_.address;
|
||||||
final paymentIdAddr = paymentId_.address;
|
final paymentIdAddr = paymentId_.address;
|
||||||
final preferredInputsAddr = preferredInputs_.address;
|
final preferredInputsAddr = preferredInputs_.address;
|
||||||
|
@ -362,16 +369,7 @@ class Transaction {
|
||||||
confirmations = monero.TransactionInfo_confirmations(txInfo),
|
confirmations = monero.TransactionInfo_confirmations(txInfo),
|
||||||
fee = monero.TransactionInfo_fee(txInfo),
|
fee = monero.TransactionInfo_fee(txInfo),
|
||||||
description = monero.TransactionInfo_description(txInfo),
|
description = monero.TransactionInfo_description(txInfo),
|
||||||
key = getTxKey(txInfo);
|
key = getTxKey(monero.TransactionInfo_hash(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Transaction.dummy({
|
Transaction.dummy({
|
||||||
required this.displayLabel,
|
required this.displayLabel,
|
||||||
|
|
|
@ -160,14 +160,15 @@ final storeMutex = Mutex();
|
||||||
|
|
||||||
int lastStorePointer = 0;
|
int lastStorePointer = 0;
|
||||||
int lastStoreHeight = 0;
|
int lastStoreHeight = 0;
|
||||||
void storeSync() async {
|
void storeSync({bool force = false}) async {
|
||||||
final addr = wptr!.address;
|
final addr = wptr!.address;
|
||||||
final synchronized = await Isolate.run(() {
|
final synchronized = await Isolate.run(() {
|
||||||
return monero.Wallet_synchronized(Pointer.fromAddress(addr));
|
return monero.Wallet_synchronized(Pointer.fromAddress(addr));
|
||||||
});
|
});
|
||||||
if (lastStorePointer == wptr!.address &&
|
if (lastStorePointer == wptr!.address &&
|
||||||
lastStoreHeight + 5000 > monero.Wallet_blockChainHeight(wptr!) &&
|
lastStoreHeight + 5000 > monero.Wallet_blockChainHeight(wptr!) &&
|
||||||
!synchronized) {
|
!synchronized &&
|
||||||
|
!force) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lastStorePointer = wptr!.address;
|
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/amount_converter.dart';
|
||||||
|
|
||||||
import 'package:cw_core/pending_transaction.dart';
|
import 'package:cw_core/pending_transaction.dart';
|
||||||
|
import 'package:cw_monero/api/wallet.dart';
|
||||||
|
|
||||||
class DoubleSpendException implements Exception {
|
class DoubleSpendException implements Exception {
|
||||||
DoubleSpendException();
|
DoubleSpendException();
|
||||||
|
@ -53,6 +54,7 @@ class PendingMoneroTransaction with PendingTransaction {
|
||||||
|
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
storeSync(force: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -273,7 +273,19 @@ Future<void> defaultSettingsMigration(
|
||||||
newDefaultUri: newCakeWalletBitcoinUri,
|
newDefaultUri: newCakeWalletBitcoinUri,
|
||||||
currentNodePreferenceKey: PreferencesKey.currentBitcoinElectrumSererIdKey,
|
currentNodePreferenceKey: PreferencesKey.currentBitcoinElectrumSererIdKey,
|
||||||
useSSL: true,
|
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;
|
break;
|
||||||
|
|
||||||
|
@ -300,11 +312,11 @@ Future<void> _changeDefaultNode({
|
||||||
required String newDefaultUri,
|
required String newDefaultUri,
|
||||||
required String currentNodePreferenceKey,
|
required String currentNodePreferenceKey,
|
||||||
required bool useSSL,
|
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 {
|
}) async {
|
||||||
final currentNodeId = sharedPreferences.getInt(currentNodePreferenceKey);
|
final currentNodeId = sharedPreferences.getInt(currentNodePreferenceKey);
|
||||||
final currentNode = nodes.values.firstWhere((node) => node.key == currentNodeId);
|
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) {
|
if (shouldReplace) {
|
||||||
var newNodeId =
|
var newNodeId =
|
||||||
|
|
|
@ -159,7 +159,7 @@ abstract class TransactionDetailsViewModelBase with Store {
|
||||||
case WalletType.monero:
|
case WalletType.monero:
|
||||||
return 'https://monero.com/tx/${txId}';
|
return 'https://monero.com/tx/${txId}';
|
||||||
case WalletType.bitcoin:
|
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:
|
case WalletType.litecoin:
|
||||||
return 'https://blockchair.com/litecoin/transaction/${txId}';
|
return 'https://blockchair.com/litecoin/transaction/${txId}';
|
||||||
case WalletType.bitcoinCash:
|
case WalletType.bitcoinCash:
|
||||||
|
|
Loading…
Reference in a new issue