Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/dashmate/src/core/wallet/importPrivateKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* @typedef {importPrivateKey}
* @param {CoreService} coreService
* @param {string} privateKey
* @param {string?} walletName
* @return {Promise<void>}
*/
async function importPrivateKey(coreService, privateKey) {
return coreService.getRpcClient().importPrivKey(privateKey, { wallet: 'main' });
async function importPrivateKey(coreService, privateKey, walletName = null) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep main default value?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about that. We only invoke importPrivateKey() inside registerMasternodeTask, which is currently only used during setup local phase. ConfigureCoreTask are creating wallet separately before executing registerMasternodeTask, and its obvious that we should use main. But when registerMasternodeTask are invoked via command, it does not have any predefined created wallets, so it will fail with error that it cannot find such wallet.

Should we move createwallet rpc command inside registerMastenodeTask?

return coreService.getRpcClient().importPrivKey(privateKey, { wallet: walletName });
}

module.exports = importPrivateKey;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const {
* @param {waitForConfirmations} waitForConfirmations
* @param {registerMasternode} registerMasternode
* @param {waitForBalanceToConfirm} waitForBalanceToConfirm
* @param {renderServiceTemplates} renderServiceTemplates
* @param {writeServiceConfigs} writeServiceConfigs
* @return {registerMasternodeTask}
*/
function registerMasternodeTaskFactory(
Expand All @@ -35,6 +37,8 @@ function registerMasternodeTaskFactory(
waitForConfirmations,
registerMasternode,
waitForBalanceToConfirm,
renderServiceTemplates,
writeServiceConfigs,
) {
/**
* @typedef {registerMasternodeTask}
Expand All @@ -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 });
},
},
Expand Down Expand Up @@ -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;
},
},
]);
}
Expand Down