mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-18 08:45:05 +00:00
decred: Clean up code.
This commit is contained in:
parent
70bfc19f96
commit
05de46bee9
8 changed files with 42 additions and 42 deletions
|
@ -52,13 +52,12 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
// NOTE: Hitting this max fee would be unexpected with current on chain use
|
||||
// but this may need to be updated in the future.
|
||||
final maxFeeRate = 100000;
|
||||
final syncInterval = 30; // seconds
|
||||
static final defaultFeeRate = 10000;
|
||||
final String _password;
|
||||
final idPrefix = "decred_";
|
||||
bool watchingOnly;
|
||||
bool connecting = false;
|
||||
int bestHeight = 0;
|
||||
String bestHash = "";
|
||||
String persistantPeer = "";
|
||||
FeeCache feeRateFast = FeeCache(defaultFeeRate);
|
||||
FeeCache feeRateMedium = FeeCache(defaultFeeRate);
|
||||
|
@ -103,10 +102,6 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
final res = libdcrwallet.bestBlock(walletInfo.name);
|
||||
final decoded = json.decode(res);
|
||||
final hash = decoded["hash"] ?? "";
|
||||
if (this.bestHash != hash) {
|
||||
this.bestHash = hash;
|
||||
this.bestHeight = decoded["height"] ?? "";
|
||||
}
|
||||
updateBalance();
|
||||
var from = 0;
|
||||
while (true) {
|
||||
|
@ -198,7 +193,7 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
@override
|
||||
Future<void> connectToNode({required Node node}) async {
|
||||
if (connecting) {
|
||||
throw "decred already connecting";
|
||||
return;
|
||||
}
|
||||
connecting = true;
|
||||
String addr = "";
|
||||
|
@ -235,7 +230,7 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
@override
|
||||
Future<void> startSync() async {
|
||||
if (connecting) {
|
||||
throw "decred already connecting";
|
||||
return;
|
||||
}
|
||||
connecting = true;
|
||||
await this._startSync();
|
||||
|
@ -252,8 +247,8 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
name: walletInfo.name,
|
||||
peers: persistantPeer,
|
||||
);
|
||||
syncTimer = Timer.periodic(
|
||||
Duration(seconds: 5), (Timer t) => performBackgroundTasks());
|
||||
syncTimer = Timer.periodic(Duration(seconds: syncInterval),
|
||||
(Timer t) => performBackgroundTasks());
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
syncStatus = FailedSyncStatus();
|
||||
|
@ -272,16 +267,9 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
throw "unable to send with watching only wallet";
|
||||
});
|
||||
}
|
||||
final inputs = [];
|
||||
this.unspentCoinsInfo.values.forEach((unspent) {
|
||||
if (unspent.isSending) {
|
||||
final input = {"txid": unspent.hash, "vout": unspent.vout};
|
||||
inputs.add(input);
|
||||
}
|
||||
});
|
||||
final ignoreInputs = [];
|
||||
this.unspentCoinsInfo.values.forEach((unspent) {
|
||||
if (unspent.isFrozen) {
|
||||
if (unspent.isFrozen || !unspent.isSending) {
|
||||
final input = {"txid": unspent.hash, "vout": unspent.vout};
|
||||
ignoreInputs.add(input);
|
||||
}
|
||||
|
@ -300,8 +288,10 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
outputs.add(o);
|
||||
}
|
||||
;
|
||||
// The inputs are always used. Currently we don't have use for this
|
||||
// argument.
|
||||
final signReq = {
|
||||
"inputs": inputs,
|
||||
// "inputs": inputs,
|
||||
"ignoreInputs": ignoreInputs,
|
||||
"outputs": outputs,
|
||||
"feerate": creds.feeRate ?? defaultFeeRate,
|
||||
|
@ -445,8 +435,9 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
var rescanHeight = 0;
|
||||
if (!watchingOnly) {
|
||||
rescanHeight = walletBirthdayBlockHeight();
|
||||
// Sync has not yet reached the birthday block.
|
||||
if (rescanHeight == -1) {
|
||||
throw "cannot rescan before the birthday block has been set";
|
||||
return;
|
||||
}
|
||||
}
|
||||
libdcrwallet.rescanFromHeight(walletInfo.name, rescanHeight.toString());
|
||||
|
@ -557,6 +548,12 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
|
||||
if (coinInfoList.isEmpty) {
|
||||
this.addCoinInfo(coin);
|
||||
} else {
|
||||
final coinInfo = coinInfoList.first;
|
||||
|
||||
coin.isFrozen = coinInfo.isFrozen;
|
||||
coin.isSending = coinInfo.isSending;
|
||||
coin.note = coinInfo.note;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -581,7 +578,7 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
walletId: idPrefix + walletInfo.name,
|
||||
hash: coin.hash,
|
||||
isFrozen: false,
|
||||
isSending: false,
|
||||
isSending: coin.isSending,
|
||||
noteRaw: "",
|
||||
address: coin.address,
|
||||
value: coin.value,
|
||||
|
@ -598,6 +595,8 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
int walletBirthdayBlockHeight() {
|
||||
final res = libdcrwallet.birthState(walletInfo.name);
|
||||
final decoded = json.decode(res);
|
||||
// Having these values set indicates that sync has not reached the birthday
|
||||
// yet, so no birthday is set.
|
||||
if (decoded["setfromheight"] == true || decoded["setfromtime"] == true) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ class DecredWalletAddresses extends WalletAddresses {
|
|||
Future<void> init() async {}
|
||||
|
||||
@override
|
||||
Future<void> updateAddressesInBox() async {}
|
||||
|
||||
@override
|
||||
Future<void> saveAddressesInBox() async {}
|
||||
Future<void> updateAddressesInBox() async {
|
||||
await saveAddressesInBox();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,10 @@ class CWDecred extends Decred {
|
|||
}
|
||||
|
||||
@override
|
||||
void updateUnspents(Object wallet) async {}
|
||||
void updateUnspents(Object wallet) async {
|
||||
final decredWallet = wallet as DecredWallet;
|
||||
decredWallet.unspents();
|
||||
}
|
||||
|
||||
@override
|
||||
int heightByDate(DateTime date) {
|
||||
|
@ -121,8 +124,8 @@ class CWDecred extends Decred {
|
|||
DateTime.fromMillisecondsSinceEpoch(1454954400 * 1000);
|
||||
final minutesDiff = date.difference(genesisBlocktime).inMinutes;
|
||||
// Decred has five minute blocks on mainnet.
|
||||
// NOTE: This is off by about a day.
|
||||
// TODO: Remove this and just rescan from the wallet birthday.
|
||||
// NOTE: This is off by about a day but is currently unused by decred as we
|
||||
// rescan from the wallet birthday.
|
||||
return (minutesDiff / 5).toInt();
|
||||
}
|
||||
|
||||
|
|
|
@ -1114,7 +1114,7 @@ Future<void> setup({
|
|||
|
||||
getIt.registerFactory(() => RescanViewModel(getIt.get<AppStore>().wallet!));
|
||||
|
||||
getIt.registerFactory(() => RescanPage(getIt.get<RescanViewModel>(), getIt.get<AppStore>().wallet!.type));
|
||||
getIt.registerFactory(() => RescanPage(getIt.get<RescanViewModel>()));
|
||||
|
||||
getIt.registerFactory(() => FaqPage(getIt.get<SettingsStore>()));
|
||||
|
||||
|
|
|
@ -96,7 +96,6 @@ Future<void> defaultSettingsMigration(
|
|||
PreferencesKey.currentBalanceDisplayModeKey, BalanceDisplayMode.availableBalance.raw);
|
||||
await sharedPreferences.setBool('save_recipient_address', true);
|
||||
await resetToDefault(nodes);
|
||||
await setDefaultDecredNodeKey(sharedPreferences, nodes);
|
||||
await changeMoneroCurrentNodeToDefault(
|
||||
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
await changeBitcoinCurrentElectrumServerToDefault(
|
||||
|
@ -349,6 +348,9 @@ Future<void> defaultSettingsMigration(
|
|||
type: WalletType.litecoin,
|
||||
useSSL: true,
|
||||
);
|
||||
case 47:
|
||||
await addDecredNode(nodes: nodes);
|
||||
await setDefaultDecredNodeKey(sharedPreferences, nodes);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -819,6 +821,11 @@ Future<void> rewriteSecureStoragePin({required SecureStorage secureStorage}) asy
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> addDecredNode({required Box<Node> nodes}) async {
|
||||
final node = Node(uri: decredDefaultUri, type: WalletType.decred);
|
||||
await nodes.add(node);
|
||||
}
|
||||
|
||||
// If "node_list.resetToDefault" is called the old node.key will still be set in
|
||||
// preferences. Set it to whatever it is now.
|
||||
//
|
||||
|
@ -1285,7 +1292,6 @@ Future<void> checkCurrentNodes(
|
|||
}
|
||||
|
||||
if (currentDecredNodeServer == null) {
|
||||
final decredMainnetPort = ":9108";
|
||||
final node = Node(uri: decredDefaultUri, type: WalletType.decred);
|
||||
await nodeSource.add(node);
|
||||
await sharedPreferences.setInt(
|
||||
|
|
|
@ -12,7 +12,7 @@ import 'package:cake_wallet/generated/i18n.dart';
|
|||
import 'package:cw_core/wallet_type.dart';
|
||||
|
||||
class RescanPage extends BasePage {
|
||||
RescanPage(this._rescanViewModel, this.type)
|
||||
RescanPage(this._rescanViewModel)
|
||||
: _blockchainHeightWidgetKey = GlobalKey<BlockchainHeightState>();
|
||||
|
||||
@override
|
||||
|
@ -21,19 +21,17 @@ class RescanPage extends BasePage {
|
|||
: S.current.rescan;
|
||||
final GlobalKey<BlockchainHeightState> _blockchainHeightWidgetKey;
|
||||
final RescanViewModel _rescanViewModel;
|
||||
final WalletType type;
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
var child;
|
||||
if (type != WalletType.decred) {
|
||||
if (_rescanViewModel.wallet.type != WalletType.decred) {
|
||||
child = Padding(
|
||||
padding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
||||
child:
|
||||
Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||
Observer(
|
||||
builder: (_) => BlockchainHeightWidget(
|
||||
type: this.type,
|
||||
key: _blockchainHeightWidgetKey,
|
||||
onHeightOrDateEntered: (value) =>
|
||||
_rescanViewModel.isButtonEnabled = value,
|
||||
|
|
|
@ -16,7 +16,6 @@ import 'package:cw_core/wallet_type.dart';
|
|||
class BlockchainHeightWidget extends StatefulWidget {
|
||||
BlockchainHeightWidget({
|
||||
GlobalKey? key,
|
||||
this.type,
|
||||
this.onHeightChange,
|
||||
this.focusNode,
|
||||
this.onHeightOrDateEntered,
|
||||
|
@ -30,7 +29,6 @@ class BlockchainHeightWidget extends StatefulWidget {
|
|||
this.blockHeightTextFieldKey,
|
||||
}) : super(key: key);
|
||||
|
||||
final WalletType? type;
|
||||
final Function(int)? onHeightChange;
|
||||
final Function(bool)? onHeightOrDateEntered;
|
||||
final FocusNode? focusNode;
|
||||
|
@ -188,7 +186,7 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
|||
bitcoinMempoolAPIEnabled: await widget.bitcoinMempoolAPIEnabled,
|
||||
);
|
||||
} else {
|
||||
if (widget.type == WalletType.decred) {
|
||||
if (widget.walletType == WalletType.decred) {
|
||||
height = decred!.heightByDate(date);
|
||||
} else if (widget.walletType == WalletType.monero) {
|
||||
height = monero!.getHeightByDate(date: date);
|
||||
|
|
|
@ -49,9 +49,6 @@ abstract class NodeListViewModelBase with Store {
|
|||
|
||||
Future<void> reset() async {
|
||||
await resetToDefault(_nodeSource);
|
||||
final decredNode = getDecredDefaultNode(nodes: _nodeSource)!;
|
||||
final sharedPrefs = getIt.get<SharedPreferences>();
|
||||
await setDefaultDecredNodeKey(sharedPrefs, _nodeSource);
|
||||
|
||||
Node node;
|
||||
|
||||
|
@ -94,7 +91,7 @@ abstract class NodeListViewModelBase with Store {
|
|||
node = getWowneroDefaultNode(nodes: _nodeSource);
|
||||
break;
|
||||
case WalletType.decred:
|
||||
node = decredNode;
|
||||
node = getDecredDefaultNode(nodes: _nodeSource)!;
|
||||
break;
|
||||
default:
|
||||
throw Exception('Unexpected wallet type: ${_appStore.wallet!.type}');
|
||||
|
|
Loading…
Reference in a new issue