Skip to content

Commit

Permalink
Finish mn controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino committed Aug 14, 2024
1 parent 0f26b08 commit 1a5f64b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 51 deletions.
4 changes: 2 additions & 2 deletions scripts/dashboard/RestoreWallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ watch(show, (show) => {
async function importWif(wif, extsk) {
const secret = await ParsedSecret.parse(wif);
if (secret.masterKey) {
await wallet.setMasterKey({ mk: secret.masterKey, extsk });
if (wallet.hasShield && !extsk) {
await wallet.value.setMasterKey({ mk: secret.masterKey, extsk });
if (wallet.value.hasShield && !extsk) {
createAlert(
'warning',
'Could not decrypt sk even if password is correct, please contact a developer'
Expand Down
58 changes: 22 additions & 36 deletions scripts/masternode/Masternode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { cChainParams } from '../chain_params';
import Modal from '../Modal.vue';
import { ref, watch, reactive } from 'vue';
import { getNetwork } from '../network';
import { translation } from '../i18n.js';
import { translation, ALERTS } from '../i18n.js';
import {
generateMasternodePrivkey,
parseIpAddress,
Expand Down Expand Up @@ -41,42 +41,22 @@ watch(isSynced, () => {
* @param {boolean} fRestart - Whether this is a Restart or a first Start
*/
async function startMasternode(fRestart = false) {
const database = await Database.getInstance();
const cMasternode = await database.getMasternode(wallet.getMasterKey());
if (cMasternode) {
if (
wallet.isViewOnly() &&
!(await restoreWallet(translation.walletUnlockMNStart))
)
return;
if (await cMasternode.start()) {
const strMsg = fRestart ? ALERTS.MN_RESTARTED : ALERTS.MN_STARTED;
createAlert('success', strMsg, 4000);
} else {
const strMsg = fRestart
? ALERTS.MN_RESTART_FAILED
: ALERTS.MN_START_FAILED;
createAlert('warning', strMsg, 4000);
}
if (isViewOnly.value && !(await restoreWallet())) {
return;
}
if (await masternode.value.start()) {
const strMsg = fRestart ? ALERTS.MN_RESTARTED : ALERTS.MN_STARTED;
createAlert('success', strMsg, 4000);
} else {
const strMsg = fRestart
? ALERTS.MN_RESTART_FAILED
: ALERTS.MN_START_FAILED;
createAlert('warning', strMsg, 4000);
}
}
async function destroyMasternode() {
const database = await Database.getInstance();
const cMasternode = await database.getMasternode(wallet.getMasterKey());
if (cMasternode) {
// Unlock the coin and update the balance
wallet.unlockCoin(
new COutpoint({
txid: cMasternode.collateralTxId,
n: cMasternode.outidx,
})
);
database.removeMasternode(wallet.getMasterKey());
createAlert('success', ALERTS.MN_DESTROYED, 5000);
updateMasternodeTab();
}
masternode.value = null;
}
/**
Expand All @@ -98,7 +78,7 @@ function importMasternode(privateKey, ip, utxo) {
masternode.value = new Masternode({
walletPrivateKeyPath: wallet.getPath(utxo.script),
mnPrivateKey: privateKey,
collateralTxId: utxo.outpoint.toUnique(),
collateralTxId: utxo.outpoint.txid,
outidx: utxo.outpoint.n,
addr: address,
});
Expand Down Expand Up @@ -341,7 +321,7 @@ async function refreshMasternodeData(cMasternode, fAlert = false) {
doms.domMnTextErrors.innerHTML =
'Masternode is currently <b>OFFLINE</b>';
if (
!wallet.isViewOnly() ||
!wallet.isViewOnly ||
(await restoreWallet(translation.walletUnlockCreateMN))
) {
createAlert('warning', ALERTS.MN_OFFLINE_STARTING, 6000);
Expand Down Expand Up @@ -443,6 +423,7 @@ function closeShowPrivKeyModal() {}
<template>
<RestoreWallet
:show="showRestoreWallet"
:wallet="wallet"
@close="showRestoreWallet = false"
/>
<CreateMasternode
Expand All @@ -453,7 +434,12 @@ function closeShowPrivKeyModal() {}
@createMasternode="createMasternode"
@importMasternode="importMasternode"
/>
<MasternodeController v-if="masternode" :masternode="masternode" />
<MasternodeController
v-if="masternode"
:masternode="masternode"
@start="({ restart }) => startMasternode(restart)"
@destroy="destroyMasternode"
/>
<Modal :show="showMasternodePrivateKey">
<template #header>
<b>{{ translation?.ALERTS?.CONFIRM_POPUP_MN_P_KEY }}</b>
Expand Down
46 changes: 33 additions & 13 deletions scripts/masternode/MasternodeController.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
<script setup>
import { toRefs, ref } from 'vue';
import { toRefs, ref, watch } from 'vue';
import Masternode from '../masternode';
import { createAlert } from '../misc';
import { ALERTS } from '../i18n';
const props = defineProps({ masternode: Masternode });
const emit = defineEmits(['start']);
const emit = defineEmits(['start', 'destroy']);
const { masternode } = toRefs(props);
const status = ref();
watch(status, (status) => {
if (status === 'MISSING') {
createAlert('warning', ALERTS.MN_OFFLINE_STARTING, 6000);
emit('start');
}
});
const lastSeen = ref();
const protocol = ref();
const netType = ref();
const ip = ref();
async function updateMasternodeData() {
const data = await masternode.value.getFullData();
const lastSeen = new Date(data.lastseen).toLocaleTimeString();
lastSeen.value = new Date(data.lastseen).toLocaleTimeString() || 'Unknown';
status.value = await masternode.value.getStatus();
protocol.value = data.version;
netType.value = data?.network?.toUpperCase() || 'Unknown';
ip.value = masternode.value.addr;
}
updateMasternodeData();
</script>
Expand All @@ -30,7 +44,7 @@ updateMasternodeData();
>
Status
<small id="mnProtocol" style="opacity: 0.5">
{{ status }}
{{ protocol }}
</small>
</h4>
<h2
Expand All @@ -45,16 +59,18 @@ updateMasternodeData();
width: 100%;
padding: 10px;
"
></h2>
>
{{ status }}
</h2>
</div>
<div class="stake-box large-box col-md-4">
<h4
id="mnNetType"
class="stake-balances"
style="background-color: #2c0044; border-radius: 10px"
></h4>
>
{{ netType }}
</h4>
<h2
id="mnNetIP"
class="stake-balances"
style="
overflow-wrap: anywhere;
Expand All @@ -67,7 +83,9 @@ updateMasternodeData();
font-family: mono !important;
font-size: x-large;
"
></h2>
>
{{ ip }}
</h2>
</div>
<div class="stake-box large-box col-md-4">
<h4
Expand All @@ -89,16 +107,18 @@ updateMasternodeData();
padding: 10px;
font-size: xx-large;
"
></h2>
>
{{ lastSeen }}
</h2>
</div>
</div>
<br />
<center id="controlMasternode" style="display: none; width: 100%">
<center>
<button
class="pivx-button-big"
onclick="MPW.destroyMasternode()"
@click="emit('destroy')"
style="margin: 20px; font-weight: 550 !important"
>
<span class="buttoni-icon"
Expand All @@ -111,7 +131,7 @@ updateMasternodeData();
<button
class="pivx-button-big"
onclick="MPW.startMasternode(true)"
@click="emit('start', { restart: true })"
style="margin: 20px; font-weight: 550 !important"
>
<span class="buttoni-icon"
Expand Down

0 comments on commit 1a5f64b

Please sign in to comment.