mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-12 09:32:33 +00:00
decred: Rescan from wallet birthday.
This commit is contained in:
parent
9dc0dd6db6
commit
0693d25413
6 changed files with 100 additions and 49 deletions
|
@ -302,3 +302,12 @@ String addresses(String walletName) {
|
|||
);
|
||||
return res.payload;
|
||||
}
|
||||
|
||||
String birthState(String walletName) {
|
||||
final cName = walletName.toCString();
|
||||
final res = executePayloadFn(
|
||||
fn: () => dcrwalletApi.birthState(cName),
|
||||
ptrsToFree: [cName],
|
||||
);
|
||||
return res.payload;
|
||||
}
|
||||
|
|
|
@ -428,10 +428,19 @@ abstract class DecredWalletBase extends WalletBase<DecredBalance,
|
|||
|
||||
@override
|
||||
Future<void> rescan({required int height}) async {
|
||||
if (height > this.bestHeight) {
|
||||
return;
|
||||
// The required height is not used. A birthday time is recorded in the
|
||||
// mnemonic. As long as not private data is imported into the wallet, we
|
||||
// can always rescan from there.
|
||||
var rescanHeight = 0;
|
||||
if (!watchingOnly) {
|
||||
final res = libdcrwallet.birthState(walletInfo.name);
|
||||
final decoded = json.decode(res);
|
||||
if (decoded["setfromheight"] == true || decoded["setfromtime"] == true) {
|
||||
throw "cannot rescan before the birthday block has been set";
|
||||
}
|
||||
rescanHeight = decoded["height"] ?? 0;
|
||||
}
|
||||
libdcrwallet.rescanFromHeight(walletInfo.name, height.toString());
|
||||
libdcrwallet.rescanFromHeight(walletInfo.name, rescanHeight.toString());
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -16,54 +16,85 @@ class RescanPage extends BasePage {
|
|||
: _blockchainHeightWidgetKey = GlobalKey<BlockchainHeightState>();
|
||||
|
||||
@override
|
||||
String get title =>
|
||||
_rescanViewModel.isSilentPaymentsScan ? S.current.silent_payments_scanning : S.current.rescan;
|
||||
String get title => _rescanViewModel.isSilentPaymentsScan
|
||||
? S.current.silent_payments_scanning
|
||||
: S.current.rescan;
|
||||
final GlobalKey<BlockchainHeightState> _blockchainHeightWidgetKey;
|
||||
final RescanViewModel _rescanViewModel;
|
||||
final WalletType type;
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
var 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,
|
||||
isSilentPaymentsScan: _rescanViewModel.isSilentPaymentsScan,
|
||||
isMwebScan: _rescanViewModel.isMwebScan,
|
||||
doSingleScan: _rescanViewModel.doSingleScan,
|
||||
hasDatePicker: !_rescanViewModel
|
||||
.isMwebScan, // disable date picker for mweb for now
|
||||
toggleSingleScan: () => _rescanViewModel.doSingleScan =
|
||||
!_rescanViewModel.doSingleScan,
|
||||
walletType: _rescanViewModel.wallet.type,
|
||||
bitcoinMempoolAPIEnabled:
|
||||
_rescanViewModel.isBitcoinMempoolAPIEnabled,
|
||||
)),
|
||||
Observer(
|
||||
builder: (_) => LoadingPrimaryButton(
|
||||
isLoading:
|
||||
_rescanViewModel.state == RescanWalletState.rescaning,
|
||||
text: S.of(context).rescan,
|
||||
onPressed: () async {
|
||||
if (_rescanViewModel.isSilentPaymentsScan) {
|
||||
return _toggleSilentPaymentsScanning(context);
|
||||
}
|
||||
|
||||
_rescanViewModel.rescanCurrentWallet(
|
||||
restoreHeight:
|
||||
_blockchainHeightWidgetKey.currentState!.height);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
color: Theme.of(context).primaryColor,
|
||||
textColor: Colors.white,
|
||||
isDisabled: !_rescanViewModel.isButtonEnabled,
|
||||
))
|
||||
]),
|
||||
);
|
||||
if (type == WalletType.decred) {
|
||||
child = Padding(
|
||||
padding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Spacer(),
|
||||
Observer(
|
||||
builder: (_) => LoadingPrimaryButton(
|
||||
isLoading: _rescanViewModel.state ==
|
||||
RescanWalletState.rescaning,
|
||||
text: S.of(context).rescan,
|
||||
onPressed: () async {
|
||||
await _rescanViewModel.rescanCurrentWallet(
|
||||
restoreHeight: 0);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
color: Theme.of(context).primaryColor,
|
||||
textColor: Colors.white,
|
||||
))
|
||||
]),
|
||||
);
|
||||
}
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => FocusScope.of(context).unfocus(),
|
||||
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,
|
||||
isSilentPaymentsScan: _rescanViewModel.isSilentPaymentsScan,
|
||||
isMwebScan: _rescanViewModel.isMwebScan,
|
||||
doSingleScan: _rescanViewModel.doSingleScan,
|
||||
hasDatePicker: !_rescanViewModel.isMwebScan,// disable date picker for mweb for now
|
||||
toggleSingleScan: () =>
|
||||
_rescanViewModel.doSingleScan = !_rescanViewModel.doSingleScan,
|
||||
walletType: _rescanViewModel.wallet.type,
|
||||
bitcoinMempoolAPIEnabled: _rescanViewModel.isBitcoinMempoolAPIEnabled,
|
||||
)),
|
||||
Observer(
|
||||
builder: (_) => LoadingPrimaryButton(
|
||||
isLoading: _rescanViewModel.state == RescanWalletState.rescaning,
|
||||
text: S.of(context).rescan,
|
||||
onPressed: () async {
|
||||
if (_rescanViewModel.isSilentPaymentsScan) {
|
||||
return _toggleSilentPaymentsScanning(context);
|
||||
}
|
||||
|
||||
_rescanViewModel.rescanCurrentWallet(
|
||||
restoreHeight: _blockchainHeightWidgetKey.currentState!.height);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
color: Theme.of(context).primaryColor,
|
||||
textColor: Colors.white,
|
||||
isDisabled: !_rescanViewModel.isButtonEnabled,
|
||||
))
|
||||
]),
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -73,14 +104,16 @@ class RescanPage extends BasePage {
|
|||
Navigator.of(context).pop();
|
||||
|
||||
final needsToSwitch =
|
||||
await bitcoin!.getNodeIsElectrsSPEnabled(_rescanViewModel.wallet) == false;
|
||||
await bitcoin!.getNodeIsElectrsSPEnabled(_rescanViewModel.wallet) ==
|
||||
false;
|
||||
|
||||
if (needsToSwitch) {
|
||||
return showPopUp<void>(
|
||||
context: navigatorKey.currentState!.context,
|
||||
builder: (BuildContext _dialogContext) => AlertWithTwoActions(
|
||||
alertTitle: S.of(_dialogContext).change_current_node_title,
|
||||
alertContent: S.of(_dialogContext).confirm_silent_payments_switch_node,
|
||||
alertContent:
|
||||
S.of(_dialogContext).confirm_silent_payments_switch_node,
|
||||
rightButtonText: S.of(_dialogContext).confirm,
|
||||
leftButtonText: S.of(_dialogContext).cancel,
|
||||
actionRightButton: () async {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
CW_DECRED_DIR=${WORKDIR}/cake_wallet/cw_decred
|
||||
LIBWALLET_PATH="${WORKDIR}/decred/libwallet"
|
||||
LIBWALLET_URL="https://github.com/decred/libwallet.git"
|
||||
LIBWALLET_VERSION="v1.0.2"
|
||||
LIBWALLET_VERSION="v1.0.4"
|
||||
|
||||
if [ -e $LIBWALLET_PATH ]; then
|
||||
rm -fr $LIBWALLET_PATH
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
. ./config.sh
|
||||
LIBWALLET_PATH="${EXTERNAL_IOS_SOURCE_DIR}/libwallet"
|
||||
LIBWALLET_URL="https://github.com/decred/libwallet.git"
|
||||
LIBWALLET_VERSION="v1.0.2"
|
||||
LIBWALLET_VERSION="v1.0.4"
|
||||
|
||||
if [ -e $LIBWALLET_PATH ]; then
|
||||
rm -fr $LIBWALLET_PATH
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
LIBWALLET_PATH="${EXTERNAL_MACOS_SOURCE_DIR}/libwallet"
|
||||
LIBWALLET_URL="https://github.com/itswisdomagain/libwallet.git"
|
||||
LIBWALLET_COMMIT_HASH=e1b9f6043359d191cfd2fbfaa345396a009d0946
|
||||
LIBWALLET_VERSION="v1.0.4"
|
||||
|
||||
echo "======================= DECRED LIBWALLET ========================="
|
||||
|
||||
|
@ -15,7 +15,7 @@ fi
|
|||
mkdir -p $LIBWALLET_PATH
|
||||
git clone $LIBWALLET_URL $LIBWALLET_PATH --branch cgo
|
||||
cd $LIBWALLET_PATH
|
||||
git checkout ${LIBWALLET_COMMIT_HASH}
|
||||
git checkout $LIBWALLET_VERSION
|
||||
|
||||
if [ -e ./build ]; then
|
||||
rm -fr ./build
|
||||
|
@ -31,4 +31,4 @@ mkdir -p $DEST_LIB_DIR
|
|||
mv ${LIBWALLET_PATH}/build/libdcrwallet.a $DEST_LIB_DIR
|
||||
|
||||
cd $CW_DECRED_DIR
|
||||
dart run ffigen
|
||||
dart run ffigen
|
||||
|
|
Loading…
Reference in a new issue