From b99c8db08c4f49f0e035156e1fe561a9d9f5b3bd Mon Sep 17 00:00:00 2001 From: pshenmic Date: Fri, 17 Mar 2023 13:55:34 +0400 Subject: [PATCH 1/2] fix(dashmate): run as wallet during setup when funding key is used --- .../src/core/wallet/importPrivateKey.js | 6 +++-- .../tasks/registerMasternodeTaskFactory.js | 26 ++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/dashmate/src/core/wallet/importPrivateKey.js b/packages/dashmate/src/core/wallet/importPrivateKey.js index 8d11b2f9b61..4c516517888 100644 --- a/packages/dashmate/src/core/wallet/importPrivateKey.js +++ b/packages/dashmate/src/core/wallet/importPrivateKey.js @@ -4,10 +4,12 @@ * @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 ac20facec5c..668cba115d9 100644 --- a/packages/dashmate/src/listr/tasks/registerMasternodeTaskFactory.js +++ b/packages/dashmate/src/listr/tasks/registerMasternodeTaskFactory.js @@ -20,6 +20,8 @@ const { * @param {waitForConfirmations} waitForConfirmations * @param {registerMasternode} registerMasternode * @param {waitForBalanceToConfirm} waitForBalanceToConfirm + * @param {renderServiceTemplates} renderServiceTemplates + * @param {writeServiceConfigs} writeServiceConfigs * @return {registerMasternodeTask} */ function registerMasternodeTaskFactory( @@ -34,6 +36,8 @@ function registerMasternodeTaskFactory( waitForConfirmations, registerMasternode, waitForBalanceToConfirm, + renderServiceTemplates, + writeServiceConfigs ) { /** * @typedef {registerMasternodeTask} @@ -52,7 +56,14 @@ function registerMasternodeTaskFactory( }, task: async (ctx) => { ctx.coreServicePassed = false; - ctx.coreService = await startCore(config, { wallet: true, addressIndex: true }); + 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}); }, }, { @@ -172,7 +183,7 @@ function registerMasternodeTaskFactory( // eslint-disable-next-line no-param-reassign task.output = `Collateral transaction ID: ${ctx.collateralTxId}`; }, - options: { persistentOutput: true }, + options: {persistentOutput: true}, }, { title: 'Wait for 1 confirmation', @@ -276,7 +287,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 + }, }, ]); } From 69a288aa4f17c89ba226c60c71947cd62e1fc9b6 Mon Sep 17 00:00:00 2001 From: pshenmic Date: Tue, 21 Mar 2023 17:17:22 +0400 Subject: [PATCH 2/2] chore(dashmate): lint fix --- .../src/core/wallet/importPrivateKey.js | 3 +-- .../tasks/registerMasternodeTaskFactory.js | 20 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/dashmate/src/core/wallet/importPrivateKey.js b/packages/dashmate/src/core/wallet/importPrivateKey.js index 4c516517888..d6e1f4f42a5 100644 --- a/packages/dashmate/src/core/wallet/importPrivateKey.js +++ b/packages/dashmate/src/core/wallet/importPrivateKey.js @@ -8,8 +8,7 @@ * @return {Promise} */ async function importPrivateKey(coreService, privateKey, walletName = null) { - - return coreService.getRpcClient().importPrivKey(privateKey, {wallet: walletName}); + 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 668cba115d9..a2cffaa415a 100644 --- a/packages/dashmate/src/listr/tasks/registerMasternodeTaskFactory.js +++ b/packages/dashmate/src/listr/tasks/registerMasternodeTaskFactory.js @@ -37,7 +37,7 @@ function registerMasternodeTaskFactory( registerMasternode, waitForBalanceToConfirm, renderServiceTemplates, - writeServiceConfigs + writeServiceConfigs, ) { /** * @typedef {registerMasternodeTask} @@ -56,14 +56,14 @@ function registerMasternodeTaskFactory( }, task: async (ctx) => { ctx.coreServicePassed = false; - ctx.masternodePrivateKey = config.get('core.masternode.operator.privateKey') + ctx.masternodePrivateKey = config.get('core.masternode.operator.privateKey'); - config.set('core.masternode.enable', false) - config.set('core.masternode.operator.privateKey', null) + 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}); + ctx.coreService = await startCore(config, { wallet: true, addressIndex: true }); }, }, { @@ -183,7 +183,7 @@ function registerMasternodeTaskFactory( // eslint-disable-next-line no-param-reassign task.output = `Collateral transaction ID: ${ctx.collateralTxId}`; }, - options: {persistentOutput: true}, + options: { persistentOutput: true }, }, { title: 'Wait for 1 confirmation', @@ -288,14 +288,14 @@ function registerMasternodeTaskFactory( title: 'Stop Core', enabled: (ctx) => !ctx.coreServicePassed, task: async (ctx) => { - ctx.coreService.stop() + ctx.coreService.stop(); - config.set('core.masternode.enable', true) - config.set('core.masternode.operator.privateKey', ctx.masternodePrivateKey) + 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 + ctx.masternodePrivateKey = null; }, }, ]);