mirror of https://github.com/embarklabs/embark.git
fix conflicts
This commit is contained in:
parent
4bb7f18155
commit
a6c8e83d40
|
@ -362,7 +362,7 @@ var EmbarkJS =
|
|||
var ipfs;
|
||||
if (provider === 'whisper') {
|
||||
this.currentMessages = EmbarkJS.Messages.Whisper;
|
||||
if (typeof variable === 'undefined') {
|
||||
if (typeof variable === 'undefined' && typeof(web3) === 'undefined') {
|
||||
if (options === undefined) {
|
||||
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
|
||||
} else {
|
||||
|
|
|
@ -315,7 +315,7 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
|
|||
var ipfs;
|
||||
if (provider === 'whisper') {
|
||||
this.currentMessages = EmbarkJS.Messages.Whisper;
|
||||
if (typeof variable === 'undefined') {
|
||||
if (typeof variable === 'undefined' && typeof(web3) === 'undefined') {
|
||||
if (options === undefined) {
|
||||
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
|
||||
} else {
|
||||
|
|
|
@ -18,21 +18,31 @@ class ABIGenerator {
|
|||
return "";
|
||||
}
|
||||
|
||||
result += "\nvar whenEnvIsLoaded = function(cb) {";
|
||||
result += "\n if (typeof window !== 'undefined' && window !== null) {";
|
||||
result += "\n window.addEventListener('load', cb);";
|
||||
result += "\n } else {";
|
||||
result += "\n cb();";
|
||||
result += "\n }";
|
||||
result += "\n}";
|
||||
|
||||
if (this.plugins) {
|
||||
providerPlugins = this.plugins.getPluginsFor('clientWeb3Provider');
|
||||
}
|
||||
|
||||
if (this.plugins && providerPlugins.length > 0) {
|
||||
providerPlugins.forEach(function (plugin) {
|
||||
providerPlugins.forEach(function(plugin) {
|
||||
result += plugin.generateProvider(self) + "\n";
|
||||
});
|
||||
} else {
|
||||
result += "\nwhenEnvIsLoaded(function() {";
|
||||
result += "\nif (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {";
|
||||
result += '\n\tweb3 = new Web3(web3.currentProvider);';
|
||||
result += "\n} else if (typeof Web3 !== 'undefined') {";
|
||||
result += '\n\tweb3 = new Web3(new Web3.providers.HttpProvider("http://' + this.rpcHost + ':' + this.rpcPort + '"));';
|
||||
result += '\n}';
|
||||
result += "\nweb3.eth.defaultAccount = web3.eth.accounts[0];";
|
||||
result += '\n})';
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -62,6 +72,16 @@ class ABIGenerator {
|
|||
let abi = JSON.stringify(contract.abiDefinition);
|
||||
let gasEstimates = JSON.stringify(contract.gasEstimates);
|
||||
|
||||
// TODO: refactor this
|
||||
result += "\nvar whenEnvIsLoaded = function(cb) {";
|
||||
result += "\n if (typeof window !== 'undefined' && window !== null) {";
|
||||
result += "\n window.addEventListener('load', cb);";
|
||||
result += "\n } else {";
|
||||
result += "\n cb();";
|
||||
result += "\n }";
|
||||
result += "\n}";
|
||||
|
||||
result += "\nwhenEnvIsLoaded(function() {";
|
||||
if (useEmbarkJS) {
|
||||
result += "\n" + className + " = new EmbarkJS.Contract({abi: " + abi + ", address: '" + contract.deployedAddress + "', code: '" + contract.code + "', gasEstimates: " + gasEstimates + "});";
|
||||
} else {
|
||||
|
@ -69,6 +89,7 @@ class ABIGenerator {
|
|||
result += "\n" + className + "Contract = web3.eth.contract(" + className + "Abi);";
|
||||
result += "\n" + className + " = " + className + "Contract.at('" + contract.deployedAddress + "');";
|
||||
}
|
||||
result += '\n});';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ describe('embark.ABIGenerator', function() {
|
|||
let generator = new ABIGenerator({blockchainConfig: {rpcHost: 'somehost', rpcPort: '1234'}, contractsManager: {}});
|
||||
|
||||
it('should generate code to connect to a provider', function() {
|
||||
let providerCode = "\nif (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {\n\tweb3 = new Web3(web3.currentProvider);\n} else if (typeof Web3 !== 'undefined') {\n\tweb3 = new Web3(new Web3.providers.HttpProvider(\"http://somehost:1234\"));\n}\nweb3.eth.defaultAccount = web3.eth.accounts[0];";
|
||||
var providerCode = "\nvar whenEnvIsLoaded = function(cb) {\n if (typeof window !== 'undefined' && window !== null) {\n window.addEventListener('load', cb);\n } else {\n cb();\n }\n}\nwhenEnvIsLoaded(function() {\nif (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {\n\tweb3 = new Web3(web3.currentProvider);\n} else if (typeof Web3 !== 'undefined') {\n\tweb3 = new Web3(new Web3.providers.HttpProvider(\"http://somehost:1234\"));\n}\nweb3.eth.defaultAccount = web3.eth.accounts[0];\n})"
|
||||
|
||||
assert.equal(generator.generateProvider(), providerCode);
|
||||
});
|
||||
|
@ -38,7 +38,7 @@ describe('embark.ABIGenerator', function() {
|
|||
let withEmbarkJS = true;
|
||||
|
||||
it('should generate contract code', function() {
|
||||
let contractCode = "\n\nSimpleStorage = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x123', code: '12345', gasEstimates: 12000});\nFoo = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x124', code: '123456', gasEstimates: 12000});";
|
||||
var contractCode = "\n\nvar whenEnvIsLoaded = function(cb) {\n if (typeof window !== 'undefined' && window !== null) {\n window.addEventListener('load', cb);\n } else {\n cb();\n }\n}\nwhenEnvIsLoaded(function() {\nSimpleStorage = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x123', code: '12345', gasEstimates: 12000});\n});\nvar whenEnvIsLoaded = function(cb) {\n if (typeof window !== 'undefined' && window !== null) {\n window.addEventListener('load', cb);\n } else {\n cb();\n }\n}\nwhenEnvIsLoaded(function() {\nFoo = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x124', code: '123456', gasEstimates: 12000});\n});";
|
||||
assert.equal(generator.generateContracts(withEmbarkJS), contractCode);
|
||||
});
|
||||
});
|
||||
|
@ -47,7 +47,7 @@ describe('embark.ABIGenerator', function() {
|
|||
let withEmbarkJS = false;
|
||||
|
||||
it('should generate contract code', function() {
|
||||
let contractCode = "\n\nSimpleStorageAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nSimpleStorageContract = web3.eth.contract(SimpleStorageAbi);\nSimpleStorage = SimpleStorageContract.at('0x123');\nFooAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nFooContract = web3.eth.contract(FooAbi);\nFoo = FooContract.at('0x124');";
|
||||
var contractCode = "\n\nvar whenEnvIsLoaded = function(cb) {\n if (typeof window !== 'undefined' && window !== null) {\n window.addEventListener('load', cb);\n } else {\n cb();\n }\n}\nwhenEnvIsLoaded(function() {\nSimpleStorageAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nSimpleStorageContract = web3.eth.contract(SimpleStorageAbi);\nSimpleStorage = SimpleStorageContract.at('0x123');\n});\nvar whenEnvIsLoaded = function(cb) {\n if (typeof window !== 'undefined' && window !== null) {\n window.addEventListener('load', cb);\n } else {\n cb();\n }\n}\nwhenEnvIsLoaded(function() {\nFooAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nFooContract = web3.eth.contract(FooAbi);\nFoo = FooContract.at('0x124');\n});";
|
||||
assert.equal(generator.generateContracts(withEmbarkJS), contractCode);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue