diff --git a/packages/dashmate/src/core/wallet/importPrivateKey.js b/packages/dashmate/src/core/wallet/importPrivateKey.js index 8d11b2f9b61..d6e1f4f42a5 100644 --- a/packages/dashmate/src/core/wallet/importPrivateKey.js +++ b/packages/dashmate/src/core/wallet/importPrivateKey.js @@ -4,10 +4,11 @@ * @typedef {importPrivateKey} * @param {CoreService} coreService * @param {string} privateKey + * @param {string?} walletName * @return {Promise} */ -async function importPrivateKey(coreService, privateKey) { - return coreService.getRpcClient().importPrivKey(privateKey, { wallet: 'main' }); +async function importPrivateKey(coreService, privateKey, walletName = null) { + return coreService.getRpcClient().importPrivKey(privateKey, { wallet: walletName }); } module.exports = importPrivateKey; diff --git a/packages/dashmate/src/listr/tasks/registerMasternodeTaskFactory.js b/packages/dashmate/src/listr/tasks/registerMasternodeTaskFactory.js index 10366094a2d..18949b55091 100644 --- a/packages/dashmate/src/listr/tasks/registerMasternodeTaskFactory.js +++ b/packages/dashmate/src/listr/tasks/registerMasternodeTaskFactory.js @@ -21,6 +21,8 @@ const { * @param {waitForConfirmations} waitForConfirmations * @param {registerMasternode} registerMasternode * @param {waitForBalanceToConfirm} waitForBalanceToConfirm + * @param {renderServiceTemplates} renderServiceTemplates + * @param {writeServiceConfigs} writeServiceConfigs * @return {registerMasternodeTask} */ function registerMasternodeTaskFactory( @@ -35,6 +37,8 @@ function registerMasternodeTaskFactory( waitForConfirmations, registerMasternode, waitForBalanceToConfirm, + renderServiceTemplates, + writeServiceConfigs, ) { /** * @typedef {registerMasternodeTask} @@ -56,6 +60,13 @@ function registerMasternodeTaskFactory( }, task: async (ctx) => { ctx.coreServicePassed = false; + ctx.masternodePrivateKey = config.get('core.masternode.operator.privateKey'); + + config.set('core.masternode.enable', false); + config.set('core.masternode.operator.privateKey', null); + const configFiles = renderServiceTemplates(config); + writeServiceConfigs(config.getName(), configFiles); + ctx.coreService = await startCore(config, { wallet: true, addressIndex: true }); }, }, @@ -281,7 +292,16 @@ function registerMasternodeTaskFactory( { title: 'Stop Core', enabled: (ctx) => !ctx.coreServicePassed, - task: async (ctx) => ctx.coreService.stop(), + task: async (ctx) => { + ctx.coreService.stop(); + + config.set('core.masternode.enable', true); + config.set('core.masternode.operator.privateKey', ctx.masternodePrivateKey); + const configFiles = renderServiceTemplates(config); + writeServiceConfigs(config.getName(), configFiles); + + ctx.masternodePrivateKey = null; + }, }, ]); }