mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-11 13:14:32 +00:00
pass in correct values
This commit is contained in:
parent
85d69c0cb2
commit
17cbc390e4
2 changed files with 15 additions and 7 deletions
|
@ -1314,6 +1314,8 @@ class BitcoinWallet extends CoinServiceAPI
|
||||||
checkChangeAddressForTransactions: _checkChangeAddressForTransactions,
|
checkChangeAddressForTransactions: _checkChangeAddressForTransactions,
|
||||||
addDerivation: addDerivation,
|
addDerivation: addDerivation,
|
||||||
addDerivations: addDerivations,
|
addDerivations: addDerivations,
|
||||||
|
dustLimitP2PKH: DUST_LIMIT_P2PKH,
|
||||||
|
minConfirms: MINIMUM_CONFIRMATIONS,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||||
import 'package:stackwallet/exceptions/wallet/insufficient_balance_exception.dart';
|
import 'package:stackwallet/exceptions/wallet/insufficient_balance_exception.dart';
|
||||||
import 'package:stackwallet/exceptions/wallet/paynym_send_exception.dart';
|
import 'package:stackwallet/exceptions/wallet/paynym_send_exception.dart';
|
||||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||||
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
|
|
||||||
import 'package:stackwallet/utilities/bip32_utils.dart';
|
import 'package:stackwallet/utilities/bip32_utils.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
|
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
|
||||||
|
@ -35,6 +34,8 @@ mixin PaynymWalletInterface {
|
||||||
late final MainDB _db;
|
late final MainDB _db;
|
||||||
late final ElectrumX _electrumXClient;
|
late final ElectrumX _electrumXClient;
|
||||||
late final SecureStorageInterface _secureStorage;
|
late final SecureStorageInterface _secureStorage;
|
||||||
|
late final int _dustLimitP2PKH;
|
||||||
|
late final int _minConfirms;
|
||||||
|
|
||||||
// passed in wallet functions
|
// passed in wallet functions
|
||||||
late final Future<List<String>> Function() _getMnemonic;
|
late final Future<List<String>> Function() _getMnemonic;
|
||||||
|
@ -79,6 +80,8 @@ mixin PaynymWalletInterface {
|
||||||
required MainDB db,
|
required MainDB db,
|
||||||
required ElectrumX electrumXClient,
|
required ElectrumX electrumXClient,
|
||||||
required SecureStorageInterface secureStorage,
|
required SecureStorageInterface secureStorage,
|
||||||
|
required int dustLimitP2PKH,
|
||||||
|
required int minConfirms,
|
||||||
required Future<List<String>> Function() getMnemonic,
|
required Future<List<String>> Function() getMnemonic,
|
||||||
required Future<int> Function() getChainHeight,
|
required Future<int> Function() getChainHeight,
|
||||||
required Future<String> Function() getCurrentChangeAddress,
|
required Future<String> Function() getCurrentChangeAddress,
|
||||||
|
@ -125,6 +128,8 @@ mixin PaynymWalletInterface {
|
||||||
_db = db;
|
_db = db;
|
||||||
_electrumXClient = electrumXClient;
|
_electrumXClient = electrumXClient;
|
||||||
_secureStorage = secureStorage;
|
_secureStorage = secureStorage;
|
||||||
|
_dustLimitP2PKH = dustLimitP2PKH;
|
||||||
|
_minConfirms = minConfirms;
|
||||||
_getMnemonic = getMnemonic;
|
_getMnemonic = getMnemonic;
|
||||||
_getChainHeight = getChainHeight;
|
_getChainHeight = getChainHeight;
|
||||||
_getCurrentChangeAddress = getCurrentChangeAddress;
|
_getCurrentChangeAddress = getCurrentChangeAddress;
|
||||||
|
@ -353,7 +358,7 @@ mixin PaynymWalletInterface {
|
||||||
int additionalOutputs = 0,
|
int additionalOutputs = 0,
|
||||||
List<UTXO>? utxos,
|
List<UTXO>? utxos,
|
||||||
}) async {
|
}) async {
|
||||||
const amountToSend = DUST_LIMIT;
|
final amountToSend = _dustLimitP2PKH;
|
||||||
final List<UTXO> availableOutputs =
|
final List<UTXO> availableOutputs =
|
||||||
utxos ?? await _db.getUTXOs(_walletId).findAll();
|
utxos ?? await _db.getUTXOs(_walletId).findAll();
|
||||||
final List<UTXO> spendableOutputs = [];
|
final List<UTXO> spendableOutputs = [];
|
||||||
|
@ -362,8 +367,8 @@ mixin PaynymWalletInterface {
|
||||||
// Build list of spendable outputs and totaling their satoshi amount
|
// Build list of spendable outputs and totaling their satoshi amount
|
||||||
for (var i = 0; i < availableOutputs.length; i++) {
|
for (var i = 0; i < availableOutputs.length; i++) {
|
||||||
if (availableOutputs[i].isBlocked == false &&
|
if (availableOutputs[i].isBlocked == false &&
|
||||||
availableOutputs[i].isConfirmed(
|
availableOutputs[i]
|
||||||
await _getChainHeight(), MINIMUM_CONFIRMATIONS) ==
|
.isConfirmed(await _getChainHeight(), _minConfirms) ==
|
||||||
true) {
|
true) {
|
||||||
spendableOutputs.add(availableOutputs[i]);
|
spendableOutputs.add(availableOutputs[i]);
|
||||||
spendableSatoshiValue += availableOutputs[i].value;
|
spendableSatoshiValue += availableOutputs[i].value;
|
||||||
|
@ -440,13 +445,13 @@ mixin PaynymWalletInterface {
|
||||||
feeForWithChange = vSizeForWithChange * 1000;
|
feeForWithChange = vSizeForWithChange * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (satoshisBeingUsed - amountToSend > feeForNoChange + DUST_LIMIT) {
|
if (satoshisBeingUsed - amountToSend > feeForNoChange + _dustLimitP2PKH) {
|
||||||
// try to add change output due to "left over" amount being greater than
|
// try to add change output due to "left over" amount being greater than
|
||||||
// the estimated fee + the dust limit
|
// the estimated fee + the dust limit
|
||||||
int changeAmount = satoshisBeingUsed - amountToSend - feeForWithChange;
|
int changeAmount = satoshisBeingUsed - amountToSend - feeForWithChange;
|
||||||
|
|
||||||
// check estimates are correct and build notification tx
|
// check estimates are correct and build notification tx
|
||||||
if (changeAmount >= DUST_LIMIT &&
|
if (changeAmount >= _dustLimitP2PKH &&
|
||||||
satoshisBeingUsed - amountToSend - changeAmount == feeForWithChange) {
|
satoshisBeingUsed - amountToSend - changeAmount == feeForWithChange) {
|
||||||
final txn = await _createNotificationTx(
|
final txn = await _createNotificationTx(
|
||||||
targetPaymentCodeString: targetPaymentCodeString,
|
targetPaymentCodeString: targetPaymentCodeString,
|
||||||
|
@ -572,7 +577,8 @@ mixin PaynymWalletInterface {
|
||||||
);
|
);
|
||||||
|
|
||||||
// todo: modify address once segwit support is in our bip47
|
// todo: modify address once segwit support is in our bip47
|
||||||
txb.addOutput(targetPaymentCode.notificationAddressP2PKH(), DUST_LIMIT);
|
txb.addOutput(
|
||||||
|
targetPaymentCode.notificationAddressP2PKH(), _dustLimitP2PKH);
|
||||||
txb.addOutput(opReturnScript, 0);
|
txb.addOutput(opReturnScript, 0);
|
||||||
|
|
||||||
// TODO: add possible change output and mark output as dangerous
|
// TODO: add possible change output and mark output as dangerous
|
||||||
|
|
Loading…
Reference in a new issue