mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-29 04:49:51 +00:00
apply some changes from SP Fix pr
This commit is contained in:
parent
46c1d6fd8d
commit
f162ea4780
3 changed files with 20 additions and 24 deletions
|
@ -8,6 +8,7 @@ import 'package:cw_bitcoin/bitcoin_amount_format.dart';
|
||||||
import 'package:cw_core/utils/print_verbose.dart';
|
import 'package:cw_core/utils/print_verbose.dart';
|
||||||
import 'package:cw_bitcoin/bitcoin_wallet.dart';
|
import 'package:cw_bitcoin/bitcoin_wallet.dart';
|
||||||
import 'package:cw_bitcoin/litecoin_wallet.dart';
|
import 'package:cw_bitcoin/litecoin_wallet.dart';
|
||||||
|
import 'package:cw_core/utils/proxy_wrapper.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:blockchain_utils/blockchain_utils.dart';
|
import 'package:blockchain_utils/blockchain_utils.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
@ -48,7 +49,6 @@ import 'package:mobx/mobx.dart';
|
||||||
import 'package:rxdart/subjects.dart';
|
import 'package:rxdart/subjects.dart';
|
||||||
import 'package:sp_scanner/sp_scanner.dart';
|
import 'package:sp_scanner/sp_scanner.dart';
|
||||||
import 'package:hex/hex.dart';
|
import 'package:hex/hex.dart';
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
|
|
||||||
part 'electrum_wallet.g.dart';
|
part 'electrum_wallet.g.dart';
|
||||||
|
|
||||||
|
@ -491,9 +491,9 @@ abstract class ElectrumWalletBase
|
||||||
Future<void> updateFeeRates() async {
|
Future<void> updateFeeRates() async {
|
||||||
if (await checkIfMempoolAPIIsEnabled() && type == WalletType.bitcoin) {
|
if (await checkIfMempoolAPIIsEnabled() && type == WalletType.bitcoin) {
|
||||||
try {
|
try {
|
||||||
final response = await http
|
final response = await ProxyWrapper()
|
||||||
.get(Uri.parse("https://mempool.cakewallet.com/api/v1/fees/recommended"))
|
.get(clearnetUri: Uri.parse("https://mempool.cakewallet.com/api/v1/fees/recommended"))
|
||||||
.timeout(Duration(seconds: 5));
|
.timeout(Duration(seconds: 15));
|
||||||
|
|
||||||
final result = json.decode(response.body) as Map<String, dynamic>;
|
final result = json.decode(response.body) as Map<String, dynamic>;
|
||||||
final slowFee = (result['economyFee'] as num?)?.toInt() ?? 0;
|
final slowFee = (result['economyFee'] as num?)?.toInt() ?? 0;
|
||||||
|
@ -1876,20 +1876,16 @@ abstract class ElectrumWalletBase
|
||||||
|
|
||||||
if (height != null && height > 0 && await checkIfMempoolAPIIsEnabled()) {
|
if (height != null && height > 0 && await checkIfMempoolAPIIsEnabled()) {
|
||||||
try {
|
try {
|
||||||
final blockHash = await http.get(
|
final blockHash = await ProxyWrapper()
|
||||||
Uri.parse(
|
.get(clearnetUri: Uri.parse("https://mempool.cakewallet.com/api/v1/block-height/$height"))
|
||||||
"https://mempool.cakewallet.com/api/v1/block-height/$height",
|
.timeout(Duration(seconds: 15));
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (blockHash.statusCode == 200 &&
|
if (blockHash.statusCode == 200 &&
|
||||||
blockHash.body.isNotEmpty &&
|
blockHash.body.isNotEmpty &&
|
||||||
jsonDecode(blockHash.body) != null) {
|
jsonDecode(blockHash.body) != null) {
|
||||||
final blockResponse = await http.get(
|
final blockResponse = await ProxyWrapper()
|
||||||
Uri.parse(
|
.get(clearnetUri: Uri.parse("https://mempool.cakewallet.com/api/v1/block/${blockHash}"))
|
||||||
"https://mempool.cakewallet.com/api/v1/block/${blockHash.body}",
|
.timeout(Duration(seconds: 15));
|
||||||
),
|
|
||||||
);
|
|
||||||
if (blockResponse.statusCode == 200 &&
|
if (blockResponse.statusCode == 200 &&
|
||||||
blockResponse.body.isNotEmpty &&
|
blockResponse.body.isNotEmpty &&
|
||||||
jsonDecode(blockResponse.body)['timestamp'] != null) {
|
jsonDecode(blockResponse.body)['timestamp'] != null) {
|
||||||
|
|
|
@ -51,7 +51,7 @@ extension PsbtSigner on PsbtV2 {
|
||||||
List<BigInt> taprootAmounts = [];
|
List<BigInt> taprootAmounts = [];
|
||||||
List<Script> taprootScripts = [];
|
List<Script> taprootScripts = [];
|
||||||
|
|
||||||
if (utxos.any((e) => e.utxo.isP2tr)) {
|
if (utxos.any((e) => e.utxo.isP2tr())) {
|
||||||
for (final input in tx.inputs) {
|
for (final input in tx.inputs) {
|
||||||
final utxo = utxos.firstWhereOrNull(
|
final utxo = utxos.firstWhereOrNull(
|
||||||
(u) => u.utxo.txHash == input.txId && u.utxo.vout == input.txIndex);
|
(u) => u.utxo.txHash == input.txId && u.utxo.vout == input.txIndex);
|
||||||
|
@ -76,7 +76,7 @@ extension PsbtSigner on PsbtV2 {
|
||||||
/// We receive the owner's ScriptPubKey
|
/// We receive the owner's ScriptPubKey
|
||||||
final script = _findLockingScript(utxo, false);
|
final script = _findLockingScript(utxo, false);
|
||||||
|
|
||||||
final int sighash = utxo.utxo.isP2tr
|
final int sighash = utxo.utxo.isP2tr()
|
||||||
? BitcoinOpCodeConst.TAPROOT_SIGHASH_ALL
|
? BitcoinOpCodeConst.TAPROOT_SIGHASH_ALL
|
||||||
: BitcoinOpCodeConst.SIGHASH_ALL;
|
: BitcoinOpCodeConst.SIGHASH_ALL;
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ extension PsbtSigner on PsbtV2 {
|
||||||
/// now we need sign the transaction digest
|
/// now we need sign the transaction digest
|
||||||
final sig = signer(digest, utxo, utxo.privateKey, sighash);
|
final sig = signer(digest, utxo, utxo.privateKey, sighash);
|
||||||
|
|
||||||
if (utxo.utxo.isP2tr) {
|
if (utxo.utxo.isP2tr()) {
|
||||||
setInputTapKeySig(i, Uint8List.fromList(BytesUtils.fromHexString(sig)));
|
setInputTapKeySig(i, Uint8List.fromList(BytesUtils.fromHexString(sig)));
|
||||||
} else {
|
} else {
|
||||||
setInputPartialSig(
|
setInputPartialSig(
|
||||||
|
@ -106,7 +106,7 @@ extension PsbtSigner on PsbtV2 {
|
||||||
List<BigInt> taprootAmounts,
|
List<BigInt> taprootAmounts,
|
||||||
List<Script> tapRootPubKeys) {
|
List<Script> tapRootPubKeys) {
|
||||||
if (utxo.isSegwit()) {
|
if (utxo.isSegwit()) {
|
||||||
if (utxo.isP2tr) {
|
if (utxo.isP2tr()) {
|
||||||
return transaction.getTransactionTaprootDigset(
|
return transaction.getTransactionTaprootDigset(
|
||||||
txIndex: input,
|
txIndex: input,
|
||||||
scriptPubKeys: tapRootPubKeys,
|
scriptPubKeys: tapRootPubKeys,
|
||||||
|
@ -129,23 +129,23 @@ extension PsbtSigner on PsbtV2 {
|
||||||
switch (utxo.utxo.scriptType) {
|
switch (utxo.utxo.scriptType) {
|
||||||
case PubKeyAddressType.p2pk:
|
case PubKeyAddressType.p2pk:
|
||||||
return senderPub.toRedeemScript();
|
return senderPub.toRedeemScript();
|
||||||
case SegwitAddressType.p2wsh:
|
case SegwitAddresType.p2wsh:
|
||||||
if (isTaproot) {
|
if (isTaproot) {
|
||||||
return senderPub.toP2wshAddress().toScriptPubKey();
|
return senderPub.toP2wshAddress().toScriptPubKey();
|
||||||
}
|
}
|
||||||
return senderPub.toP2wshRedeemScript();
|
return senderPub.toP2wshRedeemScript();
|
||||||
case P2pkhAddressType.p2pkh:
|
case P2pkhAddressType.p2pkh:
|
||||||
return senderPub.toP2pkhAddress().toScriptPubKey();
|
return senderPub.toP2pkhAddress().toScriptPubKey();
|
||||||
case SegwitAddressType.p2wpkh:
|
case SegwitAddresType.p2wpkh:
|
||||||
if (isTaproot) {
|
if (isTaproot) {
|
||||||
return senderPub.toP2wpkhAddress().toScriptPubKey();
|
return senderPub.toP2wpkhAddress().toScriptPubKey();
|
||||||
}
|
}
|
||||||
return senderPub.toP2pkhAddress().toScriptPubKey();
|
return senderPub.toP2pkhAddress().toScriptPubKey();
|
||||||
case SegwitAddressType.p2tr:
|
case SegwitAddresType.p2tr:
|
||||||
return senderPub
|
return senderPub
|
||||||
.toTaprootAddress(tweak: utxo.utxo.isSilentPayment != true)
|
.toTaprootAddress(tweak: utxo.utxo.isSilentPayment != true)
|
||||||
.toScriptPubKey();
|
.toScriptPubKey();
|
||||||
case SegwitAddressType.mweb:
|
case SegwitAddresType.mweb:
|
||||||
return Script(script: []);
|
return Script(script: []);
|
||||||
case P2shAddressType.p2pkhInP2sh:
|
case P2shAddressType.p2pkhInP2sh:
|
||||||
if (isTaproot) {
|
if (isTaproot) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ class PSBTTransactionBuild {
|
||||||
for (var i = 0; i < inputs.length; i++) {
|
for (var i = 0; i < inputs.length; i++) {
|
||||||
final input = inputs[i];
|
final input = inputs[i];
|
||||||
|
|
||||||
printV(input.utxo.isP2tr);
|
printV(input.utxo.isP2tr());
|
||||||
printV(input.utxo.isSegwit());
|
printV(input.utxo.isSegwit());
|
||||||
printV(input.utxo.isP2shSegwit());
|
printV(input.utxo.isP2shSegwit());
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class PSBTTransactionBuild {
|
||||||
setInputSegwit(i, input);
|
setInputSegwit(i, input);
|
||||||
} else if (input.utxo.isP2shSegwit()) {
|
} else if (input.utxo.isP2shSegwit()) {
|
||||||
setInputP2shSegwit(i, input);
|
setInputP2shSegwit(i, input);
|
||||||
} else if (input.utxo.isP2tr) {
|
} else if (input.utxo.isP2tr()) {
|
||||||
// ToDo: (Konsti) Handle Taproot Inputs
|
// ToDo: (Konsti) Handle Taproot Inputs
|
||||||
} else {
|
} else {
|
||||||
setInputP2pkh(i, input);
|
setInputP2pkh(i, input);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue