fix restore from height and block number
This commit is contained in:
parent
67a1db7d63
commit
6b9230779c
|
@ -45,12 +45,16 @@ export class Daemon {
|
|||
if (!fs.existsSync(lokid_path)) {
|
||||
resolve(false);
|
||||
}
|
||||
child_process.exec(lokid_version_cmd, { detached: true }, (error, stdout) => {
|
||||
if (error) {
|
||||
resolve(false);
|
||||
child_process.exec(
|
||||
lokid_version_cmd,
|
||||
{ detached: true },
|
||||
(error, stdout) => {
|
||||
if (error) {
|
||||
resolve(false);
|
||||
}
|
||||
resolve(stdout);
|
||||
}
|
||||
resolve(stdout);
|
||||
});
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -152,7 +156,10 @@ export class Daemon {
|
|||
|
||||
// TODO: Check if we need to push this command for staging too
|
||||
if (daemon.type === "local_remote" && net_type === "mainnet") {
|
||||
args.push("--bootstrap-daemon-address", `${daemon.remote_host}:${daemon.remote_port}`);
|
||||
args.push(
|
||||
"--bootstrap-daemon-address",
|
||||
`${daemon.remote_host}:${daemon.remote_port}`
|
||||
);
|
||||
}
|
||||
|
||||
// save this info for later RPC calls
|
||||
|
@ -166,15 +173,26 @@ export class Daemon {
|
|||
.then(status => {
|
||||
if (status === "closed") {
|
||||
if (process.platform === "win32") {
|
||||
this.daemonProcess = child_process.spawn(path.join(__ryo_bin, "lokid.exe"), args);
|
||||
this.daemonProcess = child_process.spawn(
|
||||
path.join(__ryo_bin, "lokid.exe"),
|
||||
args
|
||||
);
|
||||
} else {
|
||||
this.daemonProcess = child_process.spawn(path.join(__ryo_bin, "lokid"), args, {
|
||||
detached: true
|
||||
});
|
||||
this.daemonProcess = child_process.spawn(
|
||||
path.join(__ryo_bin, "lokid"),
|
||||
args,
|
||||
{
|
||||
detached: true
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
this.daemonProcess.stdout.on("data", data => process.stdout.write(`Daemon: ${data}`));
|
||||
this.daemonProcess.on("error", err => process.stderr.write(`Daemon: ${err}`));
|
||||
this.daemonProcess.stdout.on("data", data =>
|
||||
process.stdout.write(`Daemon: ${data}`)
|
||||
);
|
||||
this.daemonProcess.on("error", err =>
|
||||
process.stderr.write(`Daemon: ${err}`)
|
||||
);
|
||||
this.daemonProcess.on("close", code => {
|
||||
process.stderr.write(`Daemon: exited with code ${code} \n`);
|
||||
this.daemonProcess = null;
|
||||
|
@ -193,7 +211,11 @@ export class Daemon {
|
|||
clearInterval(intrvl);
|
||||
resolve();
|
||||
} else {
|
||||
if (this.daemonProcess && data.error.cause && data.error.cause.code === "ECONNREFUSED") {
|
||||
if (
|
||||
this.daemonProcess &&
|
||||
data.error.cause &&
|
||||
data.error.cause.code === "ECONNREFUSED"
|
||||
) {
|
||||
// Ignore
|
||||
} else {
|
||||
clearInterval(intrvl);
|
||||
|
@ -293,11 +315,17 @@ export class Daemon {
|
|||
if (data.error.code == -2) {
|
||||
// Too big height
|
||||
this.getRPC("last_block_header").then(data => {
|
||||
if (data.hasOwnProperty("error") || !data.hasOwnProperty("result")) {
|
||||
if (
|
||||
data.hasOwnProperty("error") ||
|
||||
!data.hasOwnProperty("result")
|
||||
) {
|
||||
return reject();
|
||||
}
|
||||
|
||||
let new_pivot = [data.result.block_header.height, data.result.block_header.timestamp];
|
||||
let new_pivot = [
|
||||
data.result.block_header.height,
|
||||
data.result.block_header.timestamp
|
||||
];
|
||||
|
||||
// If we are within an hour that is good enough
|
||||
// If for some reason there is a > 1h gap between blocks
|
||||
|
@ -315,7 +343,10 @@ export class Daemon {
|
|||
}
|
||||
}
|
||||
|
||||
let new_pivot = [data.result.block_header.height, data.result.block_header.timestamp];
|
||||
let new_pivot = [
|
||||
data.result.block_header.height,
|
||||
data.result.block_header.timestamp
|
||||
];
|
||||
|
||||
// If we are within an hour that is good enough
|
||||
// If for some reason there is a > 1h gap between blocks
|
||||
|
@ -330,7 +361,11 @@ export class Daemon {
|
|||
})
|
||||
.then(pivot_or_height => {
|
||||
return Array.isArray(pivot_or_height)
|
||||
? this.timestampToHeight(timestamp, pivot_or_height, recursion_limit + 1)
|
||||
? this.timestampToHeight(
|
||||
timestamp,
|
||||
pivot_or_height,
|
||||
recursion_limit + 1
|
||||
)
|
||||
: pivot_or_height;
|
||||
})
|
||||
.catch(() => {
|
||||
|
@ -374,7 +409,11 @@ export class Daemon {
|
|||
Promise.all(actions).then(data => {
|
||||
let daemon_info = {};
|
||||
for (let n of data) {
|
||||
if (n == undefined || !n.hasOwnProperty("result") || n.result == undefined) {
|
||||
if (
|
||||
n == undefined ||
|
||||
!n.hasOwnProperty("result") ||
|
||||
n.result == undefined
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (n.method == "get_info") {
|
||||
|
@ -404,14 +443,24 @@ export class Daemon {
|
|||
Promise.all(actions).then(data => {
|
||||
let daemon_info = {};
|
||||
for (let n of data) {
|
||||
if (n == undefined || !n.hasOwnProperty("result") || n.result == undefined) {
|
||||
if (
|
||||
n == undefined ||
|
||||
!n.hasOwnProperty("result") ||
|
||||
n.result == undefined
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (n.method == "get_connections" && n.result.hasOwnProperty("connections")) {
|
||||
if (
|
||||
n.method == "get_connections" &&
|
||||
n.result.hasOwnProperty("connections")
|
||||
) {
|
||||
daemon_info.connections = n.result.connections;
|
||||
} else if (n.method == "get_bans" && n.result.hasOwnProperty("bans")) {
|
||||
daemon_info.bans = n.result.bans;
|
||||
} else if (n.method == "get_txpool_backlog" && n.result.hasOwnProperty("backlog")) {
|
||||
} else if (
|
||||
n.method == "get_txpool_backlog" &&
|
||||
n.result.hasOwnProperty("backlog")
|
||||
) {
|
||||
daemon_info.tx_pool_backlog = n.result.backlog;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -516,6 +516,7 @@ export class WalletRPC {
|
|||
});
|
||||
}
|
||||
|
||||
// the date should be in ms from epoch (Jan 1 1970)
|
||||
restoreWallet(
|
||||
filename,
|
||||
password,
|
||||
|
@ -544,10 +545,10 @@ export class WalletRPC {
|
|||
});
|
||||
return;
|
||||
}
|
||||
let restore_height = Number.parseInt(refresh_start_timestamp_or_height);
|
||||
|
||||
let restore_height = refresh_start_timestamp_or_height;
|
||||
|
||||
if (!Number.isInteger(restore_height)) {
|
||||
// if the height can't be parsed just start from block 0
|
||||
if (!restore_height) {
|
||||
restore_height = 0;
|
||||
}
|
||||
seed = seed.trim().replace(/\s{2,}/g, " ");
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<div class="lokinet-input">
|
||||
<div class="q-px-md q-pt-md">
|
||||
<div class="q-mb-lg description">
|
||||
{{ $t("strings.lokinetDescription") }}
|
||||
{{ $t("strings.lokinetNameDescription") }}
|
||||
</div>
|
||||
<!-- <LNSInputForm
|
||||
ref="form"
|
||||
|
@ -26,4 +26,10 @@ export default {
|
|||
};
|
||||
</script>
|
||||
|
||||
<style></style>
|
||||
<style lang="scss">
|
||||
.lokinet-input {
|
||||
.description {
|
||||
white-space: pre-line;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
<template>
|
||||
<q-page>
|
||||
<div class="q-mx-md">
|
||||
<LokiField class="q-mt-md" :label="$t('fieldLabels.walletName')" :error="$v.wallet.name.$error">
|
||||
<LokiField
|
||||
class="q-mt-md"
|
||||
:label="$t('fieldLabels.walletName')"
|
||||
:error="$v.wallet.name.$error"
|
||||
>
|
||||
<q-input
|
||||
v-model="wallet.name"
|
||||
:placeholder="$t('placeholders.walletName')"
|
||||
|
@ -13,7 +17,11 @@
|
|||
/>
|
||||
</LokiField>
|
||||
|
||||
<LokiField class="q-mt-md" :label="$t('fieldLabels.mnemonicSeed')" :error="$v.wallet.seed.$error">
|
||||
<LokiField
|
||||
class="q-mt-md"
|
||||
:label="$t('fieldLabels.mnemonicSeed')"
|
||||
:error="$v.wallet.seed.$error"
|
||||
>
|
||||
<q-input
|
||||
v-model="wallet.seed"
|
||||
class="full-width text-area-loki"
|
||||
|
@ -28,14 +36,39 @@
|
|||
|
||||
<div class="row items-end q-mt-md">
|
||||
<div class="col-md-9 col-sm-8">
|
||||
<LokiField v-if="wallet.refresh_type == 'date'" :label="$t('fieldLabels.restoreFromDate')">
|
||||
<q-input v-model="wallet.refresh_start_date" mask="date" borderless dense>
|
||||
<LokiField
|
||||
v-if="wallet.refresh_type == 'date'"
|
||||
:label="$t('fieldLabels.restoreFromDate')"
|
||||
>
|
||||
<q-input
|
||||
v-model="wallet.refresh_start_date"
|
||||
mask="date"
|
||||
borderless
|
||||
dense
|
||||
>
|
||||
<template v-slot:append>
|
||||
<q-icon v-if="wallet.refresh_type == 'date'" name="event" class="cursor-pointer">
|
||||
<q-popup-proxy ref="qDateProxy" transition-show="scale" transition-hide="scale">
|
||||
<q-date v-model="wallet.refresh_start_date" :dark="theme == 'dark'" :options="dateRangeOptions">
|
||||
<q-icon
|
||||
v-if="wallet.refresh_type == 'date'"
|
||||
name="event"
|
||||
class="cursor-pointer"
|
||||
>
|
||||
<q-popup-proxy
|
||||
ref="qDateProxy"
|
||||
transition-show="scale"
|
||||
transition-hide="scale"
|
||||
>
|
||||
<q-date
|
||||
v-model="wallet.refresh_start_date"
|
||||
:dark="theme == 'dark'"
|
||||
:options="dateRangeOptions"
|
||||
>
|
||||
<div class="row items-center justify-end">
|
||||
<q-btn v-close-popup label="Close" color="primary" flat />
|
||||
<q-btn
|
||||
v-close-popup
|
||||
label="Close"
|
||||
color="primary"
|
||||
flat
|
||||
/>
|
||||
</div>
|
||||
</q-date>
|
||||
</q-popup-proxy>
|
||||
|
@ -111,7 +144,12 @@
|
|||
@keyup.enter="restore_wallet"
|
||||
/>
|
||||
</LokiField>
|
||||
<q-btn class="submit-button" color="primary" :label="$t('buttons.restoreWallet')" @click="restore_wallet" />
|
||||
<q-btn
|
||||
class="submit-button"
|
||||
color="primary"
|
||||
:label="$t('buttons.restoreWallet')"
|
||||
@click="restore_wallet"
|
||||
/>
|
||||
</div>
|
||||
</q-page>
|
||||
</template>
|
||||
|
@ -121,6 +159,7 @@ import { required, numeric } from "vuelidate/lib/validators";
|
|||
import { mapState } from "vuex";
|
||||
import LokiField from "components/loki_field";
|
||||
import { date } from "quasar";
|
||||
import _ from "lodash";
|
||||
|
||||
const timeStampFirstBlock = 1525305600000;
|
||||
const qDateFormat = "YYYY/MM/DD";
|
||||
|
@ -208,7 +247,12 @@ export default {
|
|||
.replace(/\t/g, " ")
|
||||
.replace(/\s{2,}/g, " ")
|
||||
.split(" ");
|
||||
if (seed.length !== 14 && seed.length !== 24 && seed.length !== 25 && seed.length !== 26) {
|
||||
if (
|
||||
seed.length !== 14 &&
|
||||
seed.length !== 24 &&
|
||||
seed.length !== 25 &&
|
||||
seed.length !== 26
|
||||
) {
|
||||
this.$q.notify({
|
||||
type: "negative",
|
||||
timeout: 1000,
|
||||
|
@ -238,7 +282,17 @@ export default {
|
|||
delay: 0
|
||||
});
|
||||
|
||||
this.$gateway.send("wallet", "restore_wallet", this.wallet);
|
||||
// we don't want the data in the form changing
|
||||
const wallet_data = _.cloneDeep(this.wallet);
|
||||
|
||||
// we want the date in javascript ms format
|
||||
const dateSeconds = date
|
||||
.extractDate(this.wallet.refresh_start_date, "YYYY/MM/DD")
|
||||
.getTime();
|
||||
|
||||
wallet_data["refresh_start_date"] = dateSeconds;
|
||||
|
||||
this.$gateway.send("wallet", "restore_wallet", wallet_data);
|
||||
},
|
||||
// Ensures the date is valid
|
||||
dateRangeOptions(dateSelected) {
|
||||
|
|
Loading…
Reference in New Issue