mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 14:24:24 +00:00
fix: use right accounts for contract deployment
This commit is contained in:
parent
b5a3897795
commit
576836df87
@ -165,7 +165,8 @@ class BlockchainConnector {
|
|||||||
logger: this.logger,
|
logger: this.logger,
|
||||||
isDev: this.isDev,
|
isDev: this.isDev,
|
||||||
type: type,
|
type: type,
|
||||||
web3Endpoint: self.web3Endpoint
|
web3Endpoint: self.web3Endpoint,
|
||||||
|
events: this.events
|
||||||
};
|
};
|
||||||
this.provider = new Provider(providerOptions);
|
this.provider = new Provider(providerOptions);
|
||||||
|
|
||||||
|
@ -14,7 +14,13 @@ class Provider {
|
|||||||
this.web3Endpoint = options.web3Endpoint;
|
this.web3Endpoint = options.web3Endpoint;
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.isDev = options.isDev;
|
this.isDev = options.isDev;
|
||||||
|
this.events = options.events;
|
||||||
this.nonceCache = {};
|
this.nonceCache = {};
|
||||||
|
|
||||||
|
this.events.setCommandHandler("blockchain:provider:contract:accounts:get", cb => {
|
||||||
|
const accounts = this.accounts.map(a => a.address);
|
||||||
|
cb(accounts);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getNonce(address, callback) {
|
getNonce(address, callback) {
|
||||||
@ -123,7 +129,7 @@ class Provider {
|
|||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
if (self.accounts.length) {
|
if (self.accounts.length) {
|
||||||
result.result = self.addresses; // Send our addresses
|
result.result = self.blockchainAccounts.map(a => a.address);
|
||||||
}
|
}
|
||||||
cb(null, result);
|
cb(null, result);
|
||||||
});
|
});
|
||||||
|
@ -113,10 +113,7 @@ class ContractDeployer {
|
|||||||
// TODO: can potentially go to a beforeDeploy plugin
|
// TODO: can potentially go to a beforeDeploy plugin
|
||||||
function getAccounts(next) {
|
function getAccounts(next) {
|
||||||
deploymentAccount = self.blockchain.defaultAccount();
|
deploymentAccount = self.blockchain.defaultAccount();
|
||||||
self.blockchain.getAccounts(function (err, _accounts) {
|
self.events.request('blockchain:provider:contract:accounts:get', _accounts => {
|
||||||
if (err) {
|
|
||||||
return next(new Error(err));
|
|
||||||
}
|
|
||||||
accounts = _accounts;
|
accounts = _accounts;
|
||||||
|
|
||||||
// applying deployer account configuration, if any
|
// applying deployer account configuration, if any
|
||||||
|
@ -26,6 +26,10 @@ class Test {
|
|||||||
this.provider = null;
|
this.provider = null;
|
||||||
this.accounts = [];
|
this.accounts = [];
|
||||||
this.embarkjs = {};
|
this.embarkjs = {};
|
||||||
|
|
||||||
|
this.events.setCommandHandler("blockchain:provider:contract:accounts:get", cb => {
|
||||||
|
cb(this.accounts);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
init(callback) {
|
init(callback) {
|
||||||
|
@ -65,10 +65,12 @@ class AccountParser {
|
|||||||
logger.warn(`Private key ending with ${accountConfig.privateKey.substr(accountConfig.privateKey.length - 5)} is not a HEX string`);
|
logger.warn(`Private key ending with ${accountConfig.privateKey.substr(accountConfig.privateKey.length - 5)} is not a HEX string`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const key = Buffer.from(accountConfig.privateKey.substr(2), 'hex');
|
||||||
if (returnAddress) {
|
if (returnAddress) {
|
||||||
return ethereumjsWallet.fromPrivateKey(accountConfig.privateKey).getChecksumAddressString();
|
return ethereumjsWallet.fromPrivateKey(key).getChecksumAddressString();
|
||||||
}
|
}
|
||||||
return Object.assign(web3.eth.accounts.privateKeyToAccount(accountConfig.privateKey), {hexBalance});
|
return Object.assign(web3.eth.accounts.privateKeyToAccount(key), {hexBalance});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accountConfig.privateKeyFile) {
|
if (accountConfig.privateKeyFile) {
|
||||||
@ -103,6 +105,9 @@ class AccountParser {
|
|||||||
logger.warn(`Private key is not a HEX string in file ${accountConfig.privateKeyFile} at index ${index}`);
|
logger.warn(`Private key is not a HEX string in file ${accountConfig.privateKeyFile} at index ${index}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key = Buffer.from(key.substr(2), 'hex');
|
||||||
|
|
||||||
if (returnAddress) {
|
if (returnAddress) {
|
||||||
return ethereumjsWallet.fromPrivateKey(key).getChecksumAddressString();
|
return ethereumjsWallet.fromPrivateKey(key).getChecksumAddressString();
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ describe('embark.AccountParser', function () {
|
|||||||
privateKey: 'myKey'
|
privateKey: 'myKey'
|
||||||
}, web3, testLogger);
|
}, web3, testLogger);
|
||||||
|
|
||||||
assert.deepEqual(account, {key: '0xmyKey', hexBalance: null});
|
assert.deepEqual(account, {key: Buffer.from('myKey', 'hex'), hexBalance: null});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return two accounts from the keys in the file', function () {
|
it('should return two accounts from the keys in the file', function () {
|
||||||
@ -47,8 +47,8 @@ describe('embark.AccountParser', function () {
|
|||||||
}, web3, testLogger);
|
}, web3, testLogger);
|
||||||
|
|
||||||
assert.deepEqual(account, [
|
assert.deepEqual(account, [
|
||||||
{key: '0xkey1', hexBalance: null},
|
{key: Buffer.from('key1', 'hex'), hexBalance: null},
|
||||||
{key: '0xkey2', hexBalance: null}
|
{key: Buffer.from('key2', 'hex'), hexBalance: null}
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user