mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-19 01:04:43 +00:00
decred: Add rescan.
This commit is contained in:
parent
0dc7baeae7
commit
ccc3db5007
10 changed files with 50 additions and 8 deletions
|
@ -206,3 +206,13 @@ String listUnspents(String walletName) {
|
||||||
);
|
);
|
||||||
return res.payload;
|
return res.payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String rescanFromHeight(String walletName, String height) {
|
||||||
|
final cName = walletName.toCString();
|
||||||
|
final cHeight = height.toCString();
|
||||||
|
final res = executePayloadFn(
|
||||||
|
fn: () => dcrwalletApi.rescanFromHeight(cName, cHeight),
|
||||||
|
ptrsToFree: [cName, cHeight],
|
||||||
|
);
|
||||||
|
return res.payload;
|
||||||
|
}
|
||||||
|
|
|
@ -401,7 +401,10 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> rescan({required int height}) async {
|
Future<void> rescan({required int height}) async {
|
||||||
// TODO.
|
if (height > this.bestHeight) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
libdcrwallet.rescanFromHeight(walletInfo.name, height.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -103,5 +103,17 @@ class CWDecred extends Decred {
|
||||||
return decredWallet.unspents();
|
return decredWallet.unspents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
void updateUnspents(Object wallet) async {}
|
void updateUnspents(Object wallet) async {}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int heightByDate(DateTime date) {
|
||||||
|
final genesisBlocktime =
|
||||||
|
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.
|
||||||
|
return (minutesDiff / 5).toInt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1113,7 +1113,7 @@ Future<void> setup({
|
||||||
|
|
||||||
getIt.registerFactory(() => RescanViewModel(getIt.get<AppStore>().wallet!));
|
getIt.registerFactory(() => RescanViewModel(getIt.get<AppStore>().wallet!));
|
||||||
|
|
||||||
getIt.registerFactory(() => RescanPage(getIt.get<RescanViewModel>()));
|
getIt.registerFactory(() => RescanPage(getIt.get<RescanViewModel>(), getIt.get<AppStore>().wallet!.type));
|
||||||
|
|
||||||
getIt.registerFactory(() => FaqPage(getIt.get<SettingsStore>()));
|
getIt.registerFactory(() => FaqPage(getIt.get<SettingsStore>()));
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,10 @@ import 'package:cake_wallet/src/screens/base_page.dart';
|
||||||
import 'package:cake_wallet/src/widgets/blockchain_height_widget.dart';
|
import 'package:cake_wallet/src/widgets/blockchain_height_widget.dart';
|
||||||
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||||
import 'package:cake_wallet/generated/i18n.dart';
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
|
import 'package:cw_core/wallet_type.dart';
|
||||||
|
|
||||||
class RescanPage extends BasePage {
|
class RescanPage extends BasePage {
|
||||||
RescanPage(this._rescanViewModel)
|
RescanPage(this._rescanViewModel, this.type)
|
||||||
: _blockchainHeightWidgetKey = GlobalKey<BlockchainHeightState>();
|
: _blockchainHeightWidgetKey = GlobalKey<BlockchainHeightState>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -19,6 +20,7 @@ class RescanPage extends BasePage {
|
||||||
_rescanViewModel.isSilentPaymentsScan ? S.current.silent_payments_scanning : S.current.rescan;
|
_rescanViewModel.isSilentPaymentsScan ? S.current.silent_payments_scanning : S.current.rescan;
|
||||||
final GlobalKey<BlockchainHeightState> _blockchainHeightWidgetKey;
|
final GlobalKey<BlockchainHeightState> _blockchainHeightWidgetKey;
|
||||||
final RescanViewModel _rescanViewModel;
|
final RescanViewModel _rescanViewModel;
|
||||||
|
final WalletType type;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget body(BuildContext context) {
|
Widget body(BuildContext context) {
|
||||||
|
@ -30,6 +32,7 @@ class RescanPage extends BasePage {
|
||||||
child: Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
child: Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||||
Observer(
|
Observer(
|
||||||
builder: (_) => BlockchainHeightWidget(
|
builder: (_) => BlockchainHeightWidget(
|
||||||
|
type: this.type,
|
||||||
key: _blockchainHeightWidgetKey,
|
key: _blockchainHeightWidgetKey,
|
||||||
onHeightOrDateEntered: (value) => _rescanViewModel.isButtonEnabled = value,
|
onHeightOrDateEntered: (value) => _rescanViewModel.isButtonEnabled = value,
|
||||||
isSilentPaymentsScan: _rescanViewModel.isSilentPaymentsScan,
|
isSilentPaymentsScan: _rescanViewModel.isSilentPaymentsScan,
|
||||||
|
|
|
@ -9,10 +9,14 @@ import 'package:intl/intl.dart';
|
||||||
import 'package:cake_wallet/generated/i18n.dart';
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
import 'package:cake_wallet/monero/monero.dart';
|
import 'package:cake_wallet/monero/monero.dart';
|
||||||
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
|
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
|
||||||
|
import 'package:cake_wallet/decred/decred.dart';
|
||||||
|
import 'package:cw_core/wallet_type.dart';
|
||||||
|
|
||||||
|
|
||||||
class BlockchainHeightWidget extends StatefulWidget {
|
class BlockchainHeightWidget extends StatefulWidget {
|
||||||
BlockchainHeightWidget({
|
BlockchainHeightWidget({
|
||||||
GlobalKey? key,
|
GlobalKey? key,
|
||||||
|
this.type,
|
||||||
this.onHeightChange,
|
this.onHeightChange,
|
||||||
this.focusNode,
|
this.focusNode,
|
||||||
this.onHeightOrDateEntered,
|
this.onHeightOrDateEntered,
|
||||||
|
@ -26,6 +30,7 @@ class BlockchainHeightWidget extends StatefulWidget {
|
||||||
this.blockHeightTextFieldKey,
|
this.blockHeightTextFieldKey,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final WalletType? type;
|
||||||
final Function(int)? onHeightChange;
|
final Function(int)? onHeightChange;
|
||||||
final Function(bool)? onHeightOrDateEntered;
|
final Function(bool)? onHeightOrDateEntered;
|
||||||
final FocusNode? focusNode;
|
final FocusNode? focusNode;
|
||||||
|
@ -183,7 +188,9 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
||||||
bitcoinMempoolAPIEnabled: await widget.bitcoinMempoolAPIEnabled,
|
bitcoinMempoolAPIEnabled: await widget.bitcoinMempoolAPIEnabled,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (widget.walletType == WalletType.monero) {
|
if (widget.type == WalletType.decred) {
|
||||||
|
height = decred!.heightByDate(date);
|
||||||
|
} else if (widget.walletType == WalletType.monero) {
|
||||||
height = monero!.getHeightByDate(date: date);
|
height = monero!.getHeightByDate(date: date);
|
||||||
} else {
|
} else {
|
||||||
assert(widget.walletType == WalletType.wownero,
|
assert(widget.walletType == WalletType.wownero,
|
||||||
|
|
|
@ -388,6 +388,7 @@ abstract class DashboardViewModelBase with Store {
|
||||||
wallet.type == WalletType.monero ||
|
wallet.type == WalletType.monero ||
|
||||||
wallet.type == WalletType.litecoin ||
|
wallet.type == WalletType.litecoin ||
|
||||||
wallet.type == WalletType.wownero ||
|
wallet.type == WalletType.wownero ||
|
||||||
|
wallet.type == WalletType.decred ||
|
||||||
wallet.type == WalletType.haven;
|
wallet.type == WalletType.haven;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
|
|
|
@ -3,14 +3,16 @@
|
||||||
. ./config.sh
|
. ./config.sh
|
||||||
CW_DECRED_DIR=${WORKDIR}/cake_wallet/cw_decred
|
CW_DECRED_DIR=${WORKDIR}/cake_wallet/cw_decred
|
||||||
LIBWALLET_PATH="${WORKDIR}/decred/libwallet"
|
LIBWALLET_PATH="${WORKDIR}/decred/libwallet"
|
||||||
LIBWALLET_URL="https://github.com/itswisdomagain/libwallet.git"
|
LIBWALLET_URL="https://github.com/decred/libwallet.git"
|
||||||
|
LIBWALLET_COMMIT="9f39f38b460e2dece5704cbc4aee293c741ee710"
|
||||||
|
|
||||||
if [ -e $LIBWALLET_PATH ]; then
|
if [ -e $LIBWALLET_PATH ]; then
|
||||||
rm -fr $LIBWALLET_PATH
|
rm -fr $LIBWALLET_PATH
|
||||||
fi
|
fi
|
||||||
mkdir -p $LIBWALLET_PATH
|
mkdir -p $LIBWALLET_PATH
|
||||||
git clone $LIBWALLET_URL $LIBWALLET_PATH --branch cgo
|
git clone $LIBWALLET_URL $LIBWALLET_PATH
|
||||||
cd $LIBWALLET_PATH
|
cd $LIBWALLET_PATH
|
||||||
|
git checkout $LIBWALLET_COMMIT
|
||||||
|
|
||||||
export CPATH="$(clang -v 2>&1 | grep "Selected GCC installation" | rev | cut -d' ' -f1 | rev)/include"
|
export CPATH="$(clang -v 2>&1 | grep "Selected GCC installation" | rev | cut -d' ' -f1 | rev)/include"
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,16 @@
|
||||||
|
|
||||||
. ./config.sh
|
. ./config.sh
|
||||||
LIBWALLET_PATH="${EXTERNAL_IOS_SOURCE_DIR}/libwallet"
|
LIBWALLET_PATH="${EXTERNAL_IOS_SOURCE_DIR}/libwallet"
|
||||||
LIBWALLET_URL="https://github.com/itswisdomagain/libwallet.git"
|
LIBWALLET_URL="https://github.com/decred/libwallet.git"
|
||||||
|
LIBWALLET_COMMIT="9f39f38b460e2dece5704cbc4aee293c741ee710"
|
||||||
|
|
||||||
if [ -e $LIBWALLET_PATH ]; then
|
if [ -e $LIBWALLET_PATH ]; then
|
||||||
rm -fr $LIBWALLET_PATH
|
rm -fr $LIBWALLET_PATH
|
||||||
fi
|
fi
|
||||||
mkdir -p $LIBWALLET_PATH
|
mkdir -p $LIBWALLET_PATH
|
||||||
git clone $LIBWALLET_URL $LIBWALLET_PATH --branch cgo
|
git clone $LIBWALLET_URL $LIBWALLET_PATH
|
||||||
cd $LIBWALLET_PATH
|
cd $LIBWALLET_PATH
|
||||||
|
git checkout $LIBWALLET_COMMIT
|
||||||
|
|
||||||
SYSROOT=`xcrun --sdk iphoneos --show-sdk-path`
|
SYSROOT=`xcrun --sdk iphoneos --show-sdk-path`
|
||||||
CLANG="clang -isysroot ${SYSROOT}"
|
CLANG="clang -isysroot ${SYSROOT}"
|
||||||
|
|
|
@ -1461,6 +1461,8 @@ abstract class Decred {
|
||||||
|
|
||||||
List<Unspent> getUnspents(Object wallet);
|
List<Unspent> getUnspents(Object wallet);
|
||||||
void updateUnspents(Object wallet);
|
void updateUnspents(Object wallet);
|
||||||
|
|
||||||
|
int heightByDate(DateTime date);
|
||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue