add 0x if private key doesn't have it

This commit is contained in:
Jonathan Rainville 2018-05-14 16:38:15 -04:00
parent 7b1a219b51
commit c5f80c72b9
2 changed files with 9 additions and 1 deletions

View File

@ -60,12 +60,18 @@ class Provider {
getAccount(accountConfig) { getAccount(accountConfig) {
if (accountConfig.privateKey) { if (accountConfig.privateKey) {
if (!accountConfig.privateKey.startsWith('0x')) {
accountConfig.privateKey = '0x' + accountConfig.privateKey;
}
return this.web3.eth.accounts.privateKeyToAccount(accountConfig.privateKey); return this.web3.eth.accounts.privateKeyToAccount(accountConfig.privateKey);
} }
if (accountConfig.privateKeyFile) { if (accountConfig.privateKeyFile) {
let fileContent = fs.readFileSync(fs.dappPath(accountConfig.privateKeyFile)).toString(); let fileContent = fs.readFileSync(fs.dappPath(accountConfig.privateKeyFile)).toString();
fileContent = fileContent.trim().split(/[,;]/); fileContent = fileContent.trim().split(/[,;]/);
return fileContent.map(key => { return fileContent.map(key => {
if (!key.startsWith('0x')) {
key = '0x' + key;
}
return this.web3.eth.accounts.privateKeyToAccount(key); return this.web3.eth.accounts.privateKeyToAccount(key);
}); });
} }

View File

@ -92,5 +92,7 @@
"Development blockchain has changed to use the --dev option.": "Development blockchain has changed to use the --dev option.", "Development blockchain has changed to use the --dev option.": "Development blockchain has changed to use the --dev option.",
"You can reset your workspace to fix the problem with": "You can reset your workspace to fix the problem with", "You can reset your workspace to fix the problem with": "You can reset your workspace to fix the problem with",
"Otherwise, you can change your data directory in blockchain.json (datadir)": "Otherwise, you can change your data directory in blockchain.json (datadir)", "Otherwise, you can change your data directory in blockchain.json (datadir)": "Otherwise, you can change your data directory in blockchain.json (datadir)",
"tip: you can resize the terminal or disable the dashboard with": "tip: you can resize the terminal or disable the dashboard with" "tip: you can resize the terminal or disable the dashboard with": "tip: you can resize the terminal or disable the dashboard with",
"help": "help",
"quit": "quit"
} }