From 1a5f64b1869a955223d98cc56dbde7e3c1d149d8 Mon Sep 17 00:00:00 2001 From: Duddino Date: Wed, 14 Aug 2024 15:10:11 +0200 Subject: [PATCH] Finish mn controller --- scripts/dashboard/RestoreWallet.vue | 4 +- scripts/masternode/Masternode.vue | 58 ++++++++------------- scripts/masternode/MasternodeController.vue | 46 +++++++++++----- 3 files changed, 57 insertions(+), 51 deletions(-) diff --git a/scripts/dashboard/RestoreWallet.vue b/scripts/dashboard/RestoreWallet.vue index 5b28b2fbe..731cea66a 100644 --- a/scripts/dashboard/RestoreWallet.vue +++ b/scripts/dashboard/RestoreWallet.vue @@ -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' diff --git a/scripts/masternode/Masternode.vue b/scripts/masternode/Masternode.vue index 003c39ba3..a4dc4b356 100644 --- a/scripts/masternode/Masternode.vue +++ b/scripts/masternode/Masternode.vue @@ -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, @@ -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; } /** @@ -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, }); @@ -341,7 +321,7 @@ async function refreshMasternodeData(cMasternode, fAlert = false) { doms.domMnTextErrors.innerHTML = 'Masternode is currently OFFLINE'; if ( - !wallet.isViewOnly() || + !wallet.isViewOnly || (await restoreWallet(translation.walletUnlockCreateMN)) ) { createAlert('warning', ALERTS.MN_OFFLINE_STARTING, 6000); @@ -443,6 +423,7 @@ function closeShowPrivKeyModal() {}