Commit 09690338 authored by Alex Beregszaszi's avatar Alex Beregszaszi

Merge pull request #68 from ethereum/codestyle-formatting

Codestyle formatting (Part 1)
parents e382840f 504e6d78
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
var multi = function(func) { return func.toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1]; } var multi = function (func) { return func.toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1]; };
var BALLOT_EXAMPLE = multi(function(){/*contract Ballot { var BALLOT_EXAMPLE = multi(function () { /*contract Ballot {
struct Voter { struct Voter {
uint weight; uint weight;
......
chrome.browserAction.onClicked.addListener(function (tab) { /* global chrome */
chrome.storage.sync.set({ 'chrome-app-sync' : true });
chrome.browserAction.onClicked.addListener(function (tab) {
chrome.storage.sync.set({ 'chrome-app-sync': true });
chrome.tabs.create({ 'url': chrome.extension.getURL('index.html') }, function (tab) { chrome.tabs.create({ 'url': chrome.extension.getURL('index.html') }, function (tab) {
// tab opened // tab opened
}); });
}); });
This diff is collapsed.
var version = function() { return '(loading)'; } var version = function () { return '(loading)'; };
var compileJSON = function() { return ''; } var compileJSON = function () { return ''; };
var missingInputs = []; var missingInputs = [];
module.exports = function (self) { module.exports = function (self) {
self.addEventListener('message', function(e) { self.addEventListener('message', function (e) {
var data = e.data; var data = e.data;
switch (data.cmd) { switch (data.cmd) {
case 'loadVersion': case 'loadVersion':
delete Module; delete Module;
version = null; version = null;
compileJSON = null; compileJSON = null;
importScripts(data.data); importScripts(data.data);
version = Module.cwrap("version", "string", []); version = Module.cwrap('version', 'string', []);
if ('_compileJSONCallback' in Module) if ('_compileJSONCallback' in Module) {
{ var compileJSONInternal = Module.cwrap('compileJSONCallback', 'string', ['string', 'number', 'number']);
compileJSONInternal = Module.cwrap("compileJSONCallback", "string", ["string", "number", "number"]); var missingInputCallback = Module.Runtime.addFunction(function (path) {
var missingInputCallback = Module.Runtime.addFunction(function(path) { missingInputs.push(Module.Pointer_stringify(path));
missingInputs.push(Module.Pointer_stringify(path)); });
}); compileJSON = function (input, optimize) {
compileJSON = function(input, optimize) { return compileJSONInternal(input, optimize, missingInputCallback);
return compileJSONInternal(input, optimize, missingInputCallback); };
}; } else if ('_compileJSONMulti' in Module) {
} compileJSON = Module.cwrap('compileJSONMulti', 'string', ['string', 'number']);
else if ('_compileJSONMulti' in Module) } else {
compileJSON = Module.cwrap("compileJSONMulti", "string", ["string", "number"]); compileJSON = Module.cwrap('compileJSON', 'string', ['string', 'number']);
else }
compileJSON = Module.cwrap("compileJSON", "string", ["string", "number"]); postMessage({
postMessage({ cmd: 'versionLoaded',
cmd: 'versionLoaded', data: version(),
data: version(), acceptsMultipleFiles: ('_compileJSONMulti' in Module)
acceptsMultipleFiles: ('_compileJSONMulti' in Module) });
}); break;
break; case 'compile':
case 'compile': missingInputs.length = 0;
missingInputs.length = 0; postMessage({cmd: 'compiled', data: compileJSON(data.source, data.optimize), missingInputs: missingInputs});
postMessage({cmd: 'compiled', data: compileJSON(data.source, data.optimize), missingInputs: missingInputs}); break;
break; }
} }, false);
}, false); };
}
...@@ -42,7 +42,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles ...@@ -42,7 +42,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
sourceAnnotations = []; sourceAnnotations = [];
outputField.empty(); outputField.empty();
var input = editor.getValue(); var input = editor.getValue();
editor.setCacheFileContent(input) editor.setCacheFileContent(input);
var files = {}; var files = {};
files[editor.getCacheFile()] = input; files[editor.getCacheFile()] = input;
...@@ -148,7 +148,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles ...@@ -148,7 +148,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
function loadInternal (url, setVersionText) { function loadInternal (url, setVersionText) {
Module = null; Module = null;
// Set a safe fallback until the new one is loaded // Set a safe fallback until the new one is loaded
compileJSON = function(source, optimize) { compilationFinished('{}'); }; compileJSON = function (source, optimize) { compilationFinished('{}'); };
var newScript = document.createElement('script'); var newScript = document.createElement('script');
newScript.type = 'text/javascript'; newScript.type = 'text/javascript';
...@@ -171,14 +171,14 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles ...@@ -171,14 +171,14 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
worker.addEventListener('message', function (msg) { worker.addEventListener('message', function (msg) {
var data = msg.data; var data = msg.data;
switch (data.cmd) { switch (data.cmd) {
case 'versionLoaded': case 'versionLoaded':
compilerAcceptsMultipleFiles = !!data.acceptsMultipleFiles; compilerAcceptsMultipleFiles = !!data.acceptsMultipleFiles;
onCompilerLoaded(setVersionText, data.data); onCompilerLoaded(setVersionText, data.data);
break; break;
case 'compiled': case 'compiled':
compilationFinished(data.data, data.missingInputs); compilationFinished(data.data, data.missingInputs);
break; break;
}; }
}); });
worker.onerror = function (msg) { console.log(msg.data); }; worker.onerror = function (msg) { console.log(msg.data); };
worker.addEventListener('error', function (msg) { console.log(msg.data); }); worker.addEventListener('error', function (msg) { console.log(msg.data); });
...@@ -186,7 +186,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles ...@@ -186,7 +186,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
worker.postMessage({cmd: 'compile', source: source, optimize: optimize}); worker.postMessage({cmd: 'compile', source: source, optimize: optimize});
}; };
worker.postMessage({cmd: 'loadVersion', data: url}); worker.postMessage({cmd: 'loadVersion', data: url});
}; }
function gatherImports (files, importHints, cb) { function gatherImports (files, importHints, cb) {
importHints = importHints || []; importHints = importHints || [];
...@@ -201,7 +201,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles ...@@ -201,7 +201,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
reloop = false; reloop = false;
for (var fileName in files) { for (var fileName in files) {
var match; var match;
while (match = importRegex.exec(files[fileName])) { while ((match = importRegex.exec(files[fileName]))) {
importHints.push(match[1]); importHints.push(match[1]);
} }
} }
...@@ -219,7 +219,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles ...@@ -219,7 +219,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
} else if (m in cachedRemoteFiles) { } else if (m in cachedRemoteFiles) {
files[m] = cachedRemoteFiles[m]; files[m] = cachedRemoteFiles[m];
reloop = true; reloop = true;
} else if (githubMatch = /^(https?:\/\/)?(www.)?github.com\/([^\/]*\/[^\/]*)\/(.*)/.exec(m)) { } else if ((githubMatch = /^(https?:\/\/)?(www.)?github.com\/([^\/]*\/[^\/]*)\/(.*)/.exec(m))) {
handleGithubCall(githubMatch[3], githubMatch[4], function (result) { handleGithubCall(githubMatch[3], githubMatch[4], function (result) {
if ('content' in result) { if ('content' in result) {
var content = Base64.decode(result.content); var content = Base64.decode(result.content);
...@@ -243,4 +243,4 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles ...@@ -243,4 +243,4 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
} }
} }
module.exports = Compiler module.exports = Compiler;
/* global BALLOT_EXAMPLE, FileReader */
var utils = require('./utils'); var utils = require('./utils');
var ace = require('brace'); var ace = require('brace');
......
/* global confirm */
var $ = require('jquery'); var $ = require('jquery');
var Web3 = require('web3'); var Web3 = require('web3');
......
/* global prompt */
var queryParams = require('./query-params'); var queryParams = require('./query-params');
function handleLoad (cb) { function handleLoad (cb) {
......
...@@ -34,5 +34,5 @@ function updateQueryParams (params) { ...@@ -34,5 +34,5 @@ function updateQueryParams (params) {
module.exports = { module.exports = {
get: getQueryParams, get: getQueryParams,
update: updateQueryParams, update: updateQueryParams
}; };
\ No newline at end of file
...@@ -6,7 +6,6 @@ var utils = require('./utils'); ...@@ -6,7 +6,6 @@ var utils = require('./utils');
var ExecutionContext = require('./execution-context'); var ExecutionContext = require('./execution-context');
function Renderer (editor, compiler, updateFiles) { function Renderer (editor, compiler, updateFiles) {
var detailsOpen = {}; var detailsOpen = {};
var executionContext = new ExecutionContext(compiler); var executionContext = new ExecutionContext(compiler);
...@@ -33,7 +32,7 @@ function Renderer (editor, compiler, updateFiles) { ...@@ -33,7 +32,7 @@ function Renderer (editor, compiler, updateFiles) {
// Switch to file // Switch to file
editor.setCacheFile(errFile); editor.setCacheFile(errFile);
updateFiles(); updateFiles();
// @TODO could show some error icon in files with errors // @TODO could show some error icon in files with errors
} }
editor.handleErrorClick(errLine, errCol); editor.handleErrorClick(errLine, errCol);
}); });
...@@ -43,7 +42,7 @@ function Renderer (editor, compiler, updateFiles) { ...@@ -43,7 +42,7 @@ function Renderer (editor, compiler, updateFiles) {
return false; return false;
}); });
} }
}; }
this.error = renderError; this.error = renderError;
var combined = function (contractName, jsonInterface, bytecode) { var combined = function (contractName, jsonInterface, bytecode) {
...@@ -51,7 +50,6 @@ function Renderer (editor, compiler, updateFiles) { ...@@ -51,7 +50,6 @@ function Renderer (editor, compiler, updateFiles) {
}; };
function renderContracts (data, source) { function renderContracts (data, source) {
var udappContracts = []; var udappContracts = [];
for (var contractName in data.contracts) { for (var contractName in data.contracts) {
var contract = data.contracts[contractName]; var contract = data.contracts[contractName];
...@@ -105,7 +103,7 @@ function Renderer (editor, compiler, updateFiles) { ...@@ -105,7 +103,7 @@ function Renderer (editor, compiler, updateFiles) {
$contractOutput.find('.title').click(function (ev) { $(this).closest('.contract').toggleClass('hide'); }); $contractOutput.find('.title').click(function (ev) { $(this).closest('.contract').toggleClass('hide'); });
$('#output').append($contractOutput); $('#output').append($contractOutput);
$('.col2 input,textarea').click(function () { this.select(); }); $('.col2 input,textarea').click(function () { this.select(); });
}; }
this.contracts = renderContracts; this.contracts = renderContracts;
var tableRowItems = function (first, second, cls) { var tableRowItems = function (first, second, cls) {
...@@ -132,8 +130,9 @@ function Renderer (editor, compiler, updateFiles) { ...@@ -132,8 +130,9 @@ function Renderer (editor, compiler, updateFiles) {
.append(tableRow('Solidity Interface', contract.solidity_interface)) .append(tableRow('Solidity Interface', contract.solidity_interface))
.append(tableRow('Opcodes', contract.opcodes)); .append(tableRow('Opcodes', contract.opcodes));
var funHashes = ''; var funHashes = '';
for (var fun in contract.functionHashes) for (var fun in contract.functionHashes) {
funHashes += contract.functionHashes[fun] + ' ' + fun + '\n'; funHashes += contract.functionHashes[fun] + ' ' + fun + '\n';
}
details.append($('<span class="col1">Functions</span>')); details.append($('<span class="col1">Functions</span>'));
details.append($('<pre/>').text(funHashes)); details.append($('<pre/>').text(funHashes));
details.append($('<span class="col1">Gas Estimates</span>')); details.append($('<span class="col1">Gas Estimates</span>'));
...@@ -154,7 +153,7 @@ function Renderer (editor, compiler, updateFiles) { ...@@ -154,7 +153,7 @@ function Renderer (editor, compiler, updateFiles) {
}; };
var formatGasEstimates = function (data) { var formatGasEstimates = function (data) {
var gasToText = function (g) { return g === null ? 'unknown' : g; } var gasToText = function (g) { return g === null ? 'unknown' : g; };
var text = ''; var text = '';
var fun; var fun;
if ('creation' in data) { if ('creation' in data) {
...@@ -217,16 +216,15 @@ function Renderer (editor, compiler, updateFiles) { ...@@ -217,16 +216,15 @@ function Renderer (editor, compiler, updateFiles) {
}); });
code += '\n {' + code += '\n {' +
'\n from: web3.eth.accounts[0], ' + '\n from: web3.eth.accounts[0], ' +
'\n data: \'' + bytecode + '\', ' + '\n data: \'' + bytecode + '\', ' +
'\n gas: 3000000' + '\n gas: 3000000' +
'\n }, function (e, contract){' + '\n }, function (e, contract){' +
'\n console.log(e, contract);' + '\n console.log(e, contract);' +
'\n if (typeof contract.address !== \'undefined\') {' + '\n if (typeof contract.address !== \'undefined\') {' +
'\n console.log(\'Contract mined! address: \' + contract.address + \' transactionHash: \' + contract.transactionHash);' + '\n console.log(\'Contract mined! address: \' + contract.address + \' transactionHash: \' + contract.transactionHash);' +
'\n }' + '\n }' +
'\n })'; '\n })';
return code; return code;
} }
...@@ -241,7 +239,6 @@ function Renderer (editor, compiler, updateFiles) { ...@@ -241,7 +239,6 @@ function Renderer (editor, compiler, updateFiles) {
} }
return funABI; return funABI;
} }
} }
module.exports = Renderer; module.exports = Renderer;
/* global chrome, confirm, localStorage */
var utils = require('./utils'); var utils = require('./utils');
function StorageHandler (updateFiles) { function StorageHandler (updateFiles) {
this.sync = function () { this.sync = function () {
if (typeof chrome === 'undefined' || !chrome || !chrome.storage || !chrome.storage.sync) { if (typeof chrome === 'undefined' || !chrome || !chrome.storage || !chrome.storage.sync) {
return; return;
} }
var obj = {}; var obj = {};
var done = false; var done = false;
var count = 0 var count = 0;
var dont = 0;
function check (key) { function check (key) {
chrome.storage.sync.get(key, function (resp) { chrome.storage.sync.get(key, function (resp) {
...@@ -28,9 +27,9 @@ function StorageHandler (updateFiles) { ...@@ -28,9 +27,9 @@ function StorageHandler (updateFiles) {
if (done >= count) { if (done >= count) {
chrome.storage.sync.set(obj, function () { chrome.storage.sync.set(obj, function () {
console.log('updated cloud files with: ', obj, this, arguments); console.log('updated cloud files with: ', obj, this, arguments);
}) });
} }
}) });
} }
for (var y in window.localStorage) { for (var y in window.localStorage) {
......
...@@ -2,4 +2,4 @@ require('es6-shim'); ...@@ -2,4 +2,4 @@ require('es6-shim');
var app = require('./app.js'); var app = require('./app.js');
var $ = require('jquery'); var $ = require('jquery');
$(document).ready(function () { app.run(); }); $(document).ready(function () { app.run(); });
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment