mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-16 23:57:11 +00:00
restructure lib initialization
This commit is contained in:
parent
ad071bc1b2
commit
1a5ddea9a8
@ -3,10 +3,10 @@ var readYaml = require('read-yaml');
|
|||||||
BlockchainConfig = require('./blockchain.js');
|
BlockchainConfig = require('./blockchain.js');
|
||||||
ContractsConfig = require('./contracts.js');
|
ContractsConfig = require('./contracts.js');
|
||||||
|
|
||||||
Config = {
|
config = {
|
||||||
Blockchain: BlockchainConfig,
|
Blockchain: BlockchainConfig,
|
||||||
Contracts: ContractsConfig
|
Contracts: ContractsConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Config
|
module.exports = config
|
||||||
|
|
||||||
|
@ -4,21 +4,25 @@ var fs = require('fs');
|
|||||||
var Blockchain = require('./blockchain.js');
|
var Blockchain = require('./blockchain.js');
|
||||||
var toposort = require('toposort');
|
var toposort = require('toposort');
|
||||||
|
|
||||||
ContractsConfig = function(files, blockchainConfig, web3) {
|
ContractsConfig = function(blockchainConfig, web3) {
|
||||||
|
this.blockchainConfig = blockchainConfig;
|
||||||
|
this.web3 = web3;
|
||||||
|
this.contractFiles = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
ContractsConfig.prototype.init = function(files) {
|
||||||
this.all_contracts = [];
|
this.all_contracts = [];
|
||||||
this.contractDB = {};
|
this.contractDB = {};
|
||||||
this.contractFiles = files;
|
this.contractFiles = files;
|
||||||
this.web3 = web3;
|
|
||||||
this.contractDependencies = {};
|
this.contractDependencies = {};
|
||||||
this.blockchainConfig = blockchainConfig;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.web3.setProvider(new this.web3.providers.HttpProvider("http://" + blockchainConfig.rpcHost + ":" + blockchainConfig.rpcPort));
|
this.web3.setProvider(new this.web3.providers.HttpProvider("http://" + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort));
|
||||||
primaryAddress = this.web3.eth.coinbase;
|
primaryAddress = this.web3.eth.coinbase;
|
||||||
this.web3.eth.defaultAccount = primaryAddress;
|
this.web3.eth.defaultAccount = primaryAddress;
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
e = _error;
|
e = _error;
|
||||||
throw new Error("can't connect to " + blockchainConfig.rpcHost + ":" + blockchainConfig.rpcPort + " check if an ethereum node is running");
|
throw new Error("can't connect to " + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort + " check if an ethereum node is running");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("address is : " + primaryAddress);
|
console.log("address is : " + primaryAddress);
|
||||||
|
20
lib/index.js
20
lib/index.js
@ -12,12 +12,18 @@ var syncMe = require('sync-me');
|
|||||||
var methodmissing = require('methodmissing');
|
var methodmissing = require('methodmissing');
|
||||||
var jasmine = require('jasmine');
|
var jasmine = require('jasmine');
|
||||||
|
|
||||||
embark = {}
|
var Tests = require('./test.js');
|
||||||
embark.Tests = require('./test.js');
|
var Blockchain = require('./blockchain.js');
|
||||||
embark.Blockchain = require('./blockchain.js');
|
var Deploy = require('./deploy.js');
|
||||||
embark.Deploy = require('./deploy.js');
|
var Release = require('./ipfs.js');
|
||||||
embark.Release = require('./ipfs.js');
|
var Config = require('./config/config.js');
|
||||||
embark.Config = require('./config/config.js');
|
|
||||||
|
|
||||||
module.exports = embark;
|
Embark = {
|
||||||
|
init: function() {
|
||||||
|
this.blockchainConfig = (new Config.BlockchainConfig());
|
||||||
|
this.contractsConfig = (new Config.ContractsConfig(this.blockchainConfig, web3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Embark;
|
||||||
|
|
||||||
|
@ -6,14 +6,10 @@ require('mocha-sinon');
|
|||||||
|
|
||||||
describe('embark.config.contracts', function() {
|
describe('embark.config.contracts', function() {
|
||||||
var blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml').config("development");
|
var blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml').config("development");
|
||||||
//sinon.stub(web3, "setProvider");
|
|
||||||
//sinon.stub(web3.eth.compile, "solidity", function() {
|
|
||||||
// return "compiled_code";
|
|
||||||
//});
|
|
||||||
|
|
||||||
describe('#loadConfigFile', function() {
|
describe('#loadConfigFile', function() {
|
||||||
it('should read and load yml file', function() {
|
it('should read and load yml file', function() {
|
||||||
var contractsConfig = new Config.Contracts([], blockchainConfig, web3);
|
var contractsConfig = new Config.Contracts(blockchainConfig, web3);
|
||||||
contractsConfig.loadConfigFile('test/support/contracts.yml');
|
contractsConfig.loadConfigFile('test/support/contracts.yml');
|
||||||
|
|
||||||
assert.equal(contractsConfig.contractConfig.hasOwnProperty('development'), true)
|
assert.equal(contractsConfig.contractConfig.hasOwnProperty('development'), true)
|
||||||
@ -47,8 +43,9 @@ describe('embark.config.contracts', function() {
|
|||||||
'test/support/contracts/simple_storage.sol',
|
'test/support/contracts/simple_storage.sol',
|
||||||
'test/support/contracts/another_storage.sol'
|
'test/support/contracts/another_storage.sol'
|
||||||
]
|
]
|
||||||
contractsConfig = new Config.Contracts(files, blockchainConfig, web3);
|
contractsConfig = new Config.Contracts(blockchainConfig, web3);
|
||||||
contractsConfig.loadConfigFile('test/support/contracts.yml');
|
contractsConfig.loadConfigFile('test/support/contracts.yml');
|
||||||
|
contractsConfig.init(files);
|
||||||
contractsConfig.compileContracts();
|
contractsConfig.compileContracts();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -65,8 +62,9 @@ describe('embark.config.contracts', function() {
|
|||||||
'test/support/contracts/another_storage.sol',
|
'test/support/contracts/another_storage.sol',
|
||||||
'test/support/contracts/wallets.sol'
|
'test/support/contracts/wallets.sol'
|
||||||
]
|
]
|
||||||
contractsConfig = new Config.Contracts(files, blockchainConfig, web3);
|
contractsConfig = new Config.Contracts(blockchainConfig, web3);
|
||||||
contractsConfig.loadConfigFile('test/support/arguments.yml');
|
contractsConfig.loadConfigFile('test/support/arguments.yml');
|
||||||
|
contractsConfig.init(files);
|
||||||
contractsConfig.compileContracts('development');
|
contractsConfig.compileContracts('development');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -11,8 +11,9 @@ describe('embark.deploy', function() {
|
|||||||
'test/support/contracts/wallets.sol'
|
'test/support/contracts/wallets.sol'
|
||||||
];
|
];
|
||||||
var blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml').config("development");
|
var blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml').config("development");
|
||||||
var contractsConfig = new Config.Contracts(files, blockchainConfig, web3);
|
var contractsConfig = new Config.Contracts(blockchainConfig, web3);
|
||||||
contractsConfig.loadConfigFile('test/support/arguments.yml');
|
contractsConfig.loadConfigFile('test/support/arguments.yml');
|
||||||
|
contractsConfig.init(files);
|
||||||
var deploy = new Deploy('development', files, blockchainConfig, contractsConfig);
|
var deploy = new Deploy('development', files, blockchainConfig, contractsConfig);
|
||||||
|
|
||||||
describe('#deploy_contracts', function() {
|
describe('#deploy_contracts', function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user