Merge pull request #68 from ethereum/codestyle-formatting

Codestyle formatting (Part 1)
pull/1/head
Alex Beregszaszi 9 years ago
commit 09690338a6
  1. 2
      assets/js/ballot.sol.js
  2. 5
      background.js
  3. 27
      src/app.js
  4. 21
      src/app/compiler-worker.js
  5. 12
      src/app/compiler.js
  6. 2
      src/app/editor.js
  7. 2
      src/app/execution-context.js
  8. 2
      src/app/gist-handler.js
  9. 2
      src/app/query-params.js
  10. 13
      src/app/renderer.js
  11. 11
      src/app/storage-handler.js
  12. 18
      src/universal-dapp.js

@ -22,7 +22,7 @@
* 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 {

@ -1,10 +1,9 @@
chrome.browserAction.onClicked.addListener(function (tab) {
/* global chrome */
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) {
// tab opened
});
});

@ -1,3 +1,5 @@
/* global alert, confirm, prompt, Option, Worker, soljsonSources */
var $ = require('jquery');
var utils = require('./app/utils');
@ -19,14 +21,12 @@ window.addEventListener('message', function (ev) {
}, false);
var run = function () {
function loadFiles (files) {
for (var f in files) {
var key = utils.fileKey(f);
var content = files[f].content;
if (key in window.localStorage && window.localStorage[key] !== content) {
var count = '';
var otherKey = key + count;
while ((key + count) in window.localStorage) count = count - 1;
window.localStorage[key + count] = window.localStorage[key];
}
@ -44,7 +44,6 @@ var run = function () {
loadFiles(filesToLoad);
}
// ------------------ query params (hash) ----------------
function syncQueryParams () {
@ -55,8 +54,9 @@ var run = function () {
syncQueryParams();
// -------- check file upload capabilities -------
if (!(window.File || window.FileReader || window.FileList || window.Blob)) {
$(".uploadFile").remove();
$('.uploadFile').remove();
}
// ------------------ gist load ----------------
@ -78,19 +78,16 @@ var run = function () {
});
});
// ----------------- storage --------------------
var storageHandler = new StorageHandler(updateFiles);
window.syncStorage = storageHandler.sync;
storageHandler.sync();
// ----------------- editor ----------------------
var editor = new Editor(loadingFromGist);
// ----------------- tabbed menu -------------------
$('#options li').click(function (ev) {
@ -108,12 +105,10 @@ var run = function () {
}
});
// ------------------ gist publish --------------
$('#gist').click(function () {
if (confirm('Are you sure you want to publish all your files anonymously as a public gist on github.com?')) {
var files = editor.packageFiles();
var description = 'Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=' + queryParams.get().version + '&optimize=' + queryParams.get().optimize + '&gist=';
@ -142,7 +137,7 @@ var run = function () {
return;
}
var files = editor.packageFiles();
var iframe = $('<iframe/>', {src: target, style: 'display:none;', load: function () {
$('<iframe/>', {src: target, style: 'display:none;', load: function () {
this.contentWindow.postMessage(['loadFiles', files], '*');
}}).appendTo('body');
});
@ -237,7 +232,6 @@ var run = function () {
return $('#files .file').filter(function () { return $(this).find('.name').text() === name; });
}
function updateFiles () {
var $filesEl = $('#files');
var files = editor.getFiles();
@ -276,9 +270,9 @@ var run = function () {
return itemsWidth;
}
function widthOfHidden () {
return ($filesWrapper.outerWidth() - widthOfList() - getLeftPosi());
}
// function widthOfHidden () {
// return ($filesWrapper.outerWidth() - widthOfList() - getLeftPosi());
// }
function widthOfVisible () {
return $filesWrapper.outerWidth();
@ -295,7 +289,7 @@ var run = function () {
}
function reAdjust () {
if (widthOfList() + getLeftPosi() > + widthOfVisible()) {
if (widthOfList() + getLeftPosi() > widthOfVisible()) {
$scrollerRight.fadeIn('fast');
} else {
$scrollerRight.fadeOut('fast');
@ -390,7 +384,6 @@ var run = function () {
if (cachedSize) setEditorSize(cachedSize);
else getEditorSize();
// ----------------- toggle right hand panel -----------------
var hidingRHP = false;
@ -416,12 +409,10 @@ var run = function () {
document.querySelector('#editor').addEventListener('change', onResize);
document.querySelector('#editorWrap').addEventListener('change', onResize);
// ----------------- compiler output renderer ----------------------
$('.asmOutput button').click(function () { $(this).parent().find('pre').toggle(); });
// ----------------- compiler ----------------------
function handleGithubCall (root, path, cb) {

@ -1,5 +1,5 @@
var version = function() { return '(loading)'; }
var compileJSON = function() { return ''; }
var version = function () { return '(loading)'; };
var compileJSON = function () { return ''; };
var missingInputs = [];
module.exports = function (self) {
@ -12,21 +12,20 @@ module.exports = function (self) {
compileJSON = null;
importScripts(data.data);
version = Module.cwrap("version", "string", []);
if ('_compileJSONCallback' in Module)
{
compileJSONInternal = Module.cwrap("compileJSONCallback", "string", ["string", "number", "number"]);
version = Module.cwrap('version', 'string', []);
if ('_compileJSONCallback' in Module) {
var compileJSONInternal = Module.cwrap('compileJSONCallback', 'string', ['string', 'number', 'number']);
var missingInputCallback = Module.Runtime.addFunction(function (path) {
missingInputs.push(Module.Pointer_stringify(path));
});
compileJSON = function (input, optimize) {
return compileJSONInternal(input, optimize, missingInputCallback);
};
} else if ('_compileJSONMulti' in Module) {
compileJSON = Module.cwrap('compileJSONMulti', 'string', ['string', 'number']);
} else {
compileJSON = Module.cwrap('compileJSON', 'string', ['string', 'number']);
}
else if ('_compileJSONMulti' in Module)
compileJSON = Module.cwrap("compileJSONMulti", "string", ["string", "number"]);
else
compileJSON = Module.cwrap("compileJSON", "string", ["string", "number"]);
postMessage({
cmd: 'versionLoaded',
data: version(),
@ -39,4 +38,4 @@ module.exports = function (self) {
break;
}
}, false);
}
};

@ -42,7 +42,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
sourceAnnotations = [];
outputField.empty();
var input = editor.getValue();
editor.setCacheFileContent(input)
editor.setCacheFileContent(input);
var files = {};
files[editor.getCacheFile()] = input;
@ -178,7 +178,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
case 'compiled':
compilationFinished(data.data, data.missingInputs);
break;
};
}
});
worker.onerror = 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
worker.postMessage({cmd: 'compile', source: source, optimize: optimize});
};
worker.postMessage({cmd: 'loadVersion', data: url});
};
}
function gatherImports (files, importHints, cb) {
importHints = importHints || [];
@ -201,7 +201,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
reloop = false;
for (var fileName in files) {
var match;
while (match = importRegex.exec(files[fileName])) {
while ((match = importRegex.exec(files[fileName]))) {
importHints.push(match[1]);
}
}
@ -219,7 +219,7 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
} else if (m in cachedRemoteFiles) {
files[m] = cachedRemoteFiles[m];
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) {
if ('content' in result) {
var content = Base64.decode(result.content);
@ -243,4 +243,4 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
}
}
module.exports = Compiler
module.exports = Compiler;

@ -1,3 +1,5 @@
/* global BALLOT_EXAMPLE, FileReader */
var utils = require('./utils');
var ace = require('brace');

@ -1,3 +1,5 @@
/* global confirm */
var $ = require('jquery');
var Web3 = require('web3');

@ -1,3 +1,5 @@
/* global prompt */
var queryParams = require('./query-params');
function handleLoad (cb) {

@ -34,5 +34,5 @@ function updateQueryParams (params) {
module.exports = {
get: getQueryParams,
update: updateQueryParams,
update: updateQueryParams
};

@ -6,7 +6,6 @@ var utils = require('./utils');
var ExecutionContext = require('./execution-context');
function Renderer (editor, compiler, updateFiles) {
var detailsOpen = {};
var executionContext = new ExecutionContext(compiler);
@ -43,7 +42,7 @@ function Renderer (editor, compiler, updateFiles) {
return false;
});
}
};
}
this.error = renderError;
var combined = function (contractName, jsonInterface, bytecode) {
@ -51,7 +50,6 @@ function Renderer (editor, compiler, updateFiles) {
};
function renderContracts (data, source) {
var udappContracts = [];
for (var contractName in data.contracts) {
var contract = data.contracts[contractName];
@ -105,7 +103,7 @@ function Renderer (editor, compiler, updateFiles) {
$contractOutput.find('.title').click(function (ev) { $(this).closest('.contract').toggleClass('hide'); });
$('#output').append($contractOutput);
$('.col2 input,textarea').click(function () { this.select(); });
};
}
this.contracts = renderContracts;
var tableRowItems = function (first, second, cls) {
@ -132,8 +130,9 @@ function Renderer (editor, compiler, updateFiles) {
.append(tableRow('Solidity Interface', contract.solidity_interface))
.append(tableRow('Opcodes', contract.opcodes));
var funHashes = '';
for (var fun in contract.functionHashes)
for (var fun in contract.functionHashes) {
funHashes += contract.functionHashes[fun] + ' ' + fun + '\n';
}
details.append($('<span class="col1">Functions</span>'));
details.append($('<pre/>').text(funHashes));
details.append($('<span class="col1">Gas Estimates</span>'));
@ -154,7 +153,7 @@ function Renderer (editor, compiler, updateFiles) {
};
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 fun;
if ('creation' in data) {
@ -227,7 +226,6 @@ function Renderer (editor, compiler, updateFiles) {
'\n }' +
'\n })';
return code;
}
@ -241,7 +239,6 @@ function Renderer (editor, compiler, updateFiles) {
}
return funABI;
}
}
module.exports = Renderer;

@ -1,17 +1,16 @@
/* global chrome, confirm, localStorage */
var utils = require('./utils');
function StorageHandler (updateFiles) {
this.sync = function () {
if (typeof chrome === 'undefined' || !chrome || !chrome.storage || !chrome.storage.sync) {
return;
}
var obj = {};
var done = false;
var count = 0
var dont = 0;
var count = 0;
function check (key) {
chrome.storage.sync.get(key, function (resp) {
@ -28,9 +27,9 @@ function StorageHandler (updateFiles) {
if (done >= count) {
chrome.storage.sync.set(obj, function () {
console.log('updated cloud files with: ', obj, this, arguments);
})
});
}
})
});
}
for (var y in window.localStorage) {

@ -1,3 +1,5 @@
/* global prompt */
var $ = require('jquery');
var EthJSVM = require('ethereumjs-vm');
var ethJSUtil = require('ethereumjs-util');
@ -83,7 +85,6 @@ UniversalDApp.prototype.render = function () {
if (this.contracts.length === 0) {
this.$el.append(this.getABIInputForm());
} else {
for (var c in this.contracts) {
var $contractEl = $('<div class="contract"/>');
@ -145,7 +146,6 @@ UniversalDApp.prototype.getABIInputForm = function (cb) {
return $el;
};
UniversalDApp.prototype.getCreateInterface = function ($container, contract) {
var self = this;
var $createInterface = $('<div class="create"/>');
@ -179,7 +179,6 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar
var $createInterface = $('<div class="createContract"/>');
var appendFunctions = function (address, $el) {
var $instance = $('<div class="instance"/>');
if (self.options.removable_instances) {
var $close = $('<div class="udapp-close" />');
@ -343,13 +342,14 @@ UniversalDApp.prototype.getCallButton = function (args) {
var getGasUsedOutput = function (result, vmResult) {
var $gasUsed = $('<div class="gasUsed">');
var caveat = lookupOnly ? '<em>(<span class="caveat" title="Cost only applies when called by a contract">caveat</span>)</em>' : '';
var gas;
if (result.gasUsed) {
var gas = result.gasUsed.toString(10);
gas = result.gasUsed.toString(10);
$gasUsed.html('<strong>Transaction cost:</strong> ' + gas + ' gas. ' + caveat);
}
if (vmResult.gasUsed) {
var $callGasUsed = $('<div class="gasUsed">');
var gas = vmResult.gasUsed.toString(10);
gas = vmResult.gasUsed.toString(10);
$callGasUsed.append('<strong>Execution cost:</strong> ' + gas + ' gas.');
$gasUsed.append($callGasUsed);
}
@ -454,8 +454,10 @@ UniversalDApp.prototype.getCallButton = function (args) {
// Only decode if there supposed to be fields
if (args.abi.outputs.length > 0) {
try {
var i;
var outputTypes = [];
for (var i = 0; i < args.abi.outputs.length; i++) {
for (i = 0; i < args.abi.outputs.length; i++) {
outputTypes.push(args.abi.outputs[i].type);
}
@ -464,7 +466,7 @@ UniversalDApp.prototype.getCallButton = function (args) {
// format decoded data
decodedObj = ethJSABI.stringify(outputTypes, decodedObj);
for (var i = 0; i < outputTypes.length; i++) {
for (i = 0; i < outputTypes.length; i++) {
var name = args.abi.outputs[i].name;
if (name.length > 0) {
decodedObj[i] = outputTypes[i] + ' ' + name + ': ' + decodedObj[i];
@ -492,7 +494,6 @@ UniversalDApp.prototype.getCallButton = function (args) {
$result.append(getReturnOutput(result)).append(getGasUsedOutput(result));
}
});
}
});
};
@ -663,7 +664,6 @@ function tryTillResponse (web3, txhash, done) {
done(err, address);
}
}
}
module.exports = UniversalDApp;

Loading…
Cancel
Save