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;
|
||||
}
|
||||
|
||||
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
|
||||
Future<void> rescan({required int height}) async {
|
||||
// TODO.
|
||||
if (height > this.bestHeight) {
|
||||
return;
|
||||
}
|
||||
libdcrwallet.rescanFromHeight(walletInfo.name, height.toString());
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -103,5 +103,17 @@ class CWDecred extends Decred {
|
|||
return decredWallet.unspents();
|
||||
}
|
||||
|
||||
@override
|
||||
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(() => RescanPage(getIt.get<RescanViewModel>()));
|
||||
getIt.registerFactory(() => RescanPage(getIt.get<RescanViewModel>(), getIt.get<AppStore>().wallet!.type));
|
||||
|
||||
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/primary_button.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
|
||||
class RescanPage extends BasePage {
|
||||
RescanPage(this._rescanViewModel)
|
||||
RescanPage(this._rescanViewModel, this.type)
|
||||
: _blockchainHeightWidgetKey = GlobalKey<BlockchainHeightState>();
|
||||
|
||||
@override
|
||||
|
@ -19,6 +20,7 @@ class RescanPage extends BasePage {
|
|||
_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) {
|
||||
|
@ -30,6 +32,7 @@ class RescanPage extends BasePage {
|
|||
child: Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||
Observer(
|
||||
builder: (_) => BlockchainHeightWidget(
|
||||
type: this.type,
|
||||
key: _blockchainHeightWidgetKey,
|
||||
onHeightOrDateEntered: (value) => _rescanViewModel.isButtonEnabled = value,
|
||||
isSilentPaymentsScan: _rescanViewModel.isSilentPaymentsScan,
|
||||
|
|
|
@ -9,10 +9,14 @@ import 'package:intl/intl.dart';
|
|||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/monero/monero.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 {
|
||||
BlockchainHeightWidget({
|
||||
GlobalKey? key,
|
||||
this.type,
|
||||
this.onHeightChange,
|
||||
this.focusNode,
|
||||
this.onHeightOrDateEntered,
|
||||
|
@ -26,6 +30,7 @@ class BlockchainHeightWidget extends StatefulWidget {
|
|||
this.blockHeightTextFieldKey,
|
||||
}) : super(key: key);
|
||||
|
||||
final WalletType? type;
|
||||
final Function(int)? onHeightChange;
|
||||
final Function(bool)? onHeightOrDateEntered;
|
||||
final FocusNode? focusNode;
|
||||
|
@ -183,7 +188,9 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
|||
bitcoinMempoolAPIEnabled: await widget.bitcoinMempoolAPIEnabled,
|
||||
);
|
||||
} 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);
|
||||
} else {
|
||||
assert(widget.walletType == WalletType.wownero,
|
||||
|
|
|
@ -388,6 +388,7 @@ abstract class DashboardViewModelBase with Store {
|
|||
wallet.type == WalletType.monero ||
|
||||
wallet.type == WalletType.litecoin ||
|
||||
wallet.type == WalletType.wownero ||
|
||||
wallet.type == WalletType.decred ||
|
||||
wallet.type == WalletType.haven;
|
||||
|
||||
@computed
|
||||
|
|
|
@ -3,14 +3,16 @@
|
|||
. ./config.sh
|
||||
CW_DECRED_DIR=${WORKDIR}/cake_wallet/cw_decred
|
||||
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
|
||||
rm -fr $LIBWALLET_PATH
|
||||
fi
|
||||
mkdir -p $LIBWALLET_PATH
|
||||
git clone $LIBWALLET_URL $LIBWALLET_PATH --branch cgo
|
||||
git clone $LIBWALLET_URL $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"
|
||||
|
||||
|
|
|
@ -2,14 +2,16 @@
|
|||
|
||||
. ./config.sh
|
||||
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
|
||||
rm -fr $LIBWALLET_PATH
|
||||
fi
|
||||
mkdir -p $LIBWALLET_PATH
|
||||
git clone $LIBWALLET_URL $LIBWALLET_PATH --branch cgo
|
||||
git clone $LIBWALLET_URL $LIBWALLET_PATH
|
||||
cd $LIBWALLET_PATH
|
||||
git checkout $LIBWALLET_COMMIT
|
||||
|
||||
SYSROOT=`xcrun --sdk iphoneos --show-sdk-path`
|
||||
CLANG="clang -isysroot ${SYSROOT}"
|
||||
|
|
|
@ -1461,6 +1461,8 @@ abstract class Decred {
|
|||
|
||||
List<Unspent> getUnspents(Object wallet);
|
||||
void updateUnspents(Object wallet);
|
||||
|
||||
int heightByDate(DateTime date);
|
||||
}
|
||||
""";
|
||||
|
||||
|
|
Loading…
Reference in a new issue