From b5ac39fb74cfb32d3faf8cd2f3b7c2db963091b6 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 14 Nov 2016 20:00:13 +0000 Subject: [PATCH 01/13] compiler: add constructor/fallback to the ABI if using an old compiler --- src/app/compiler.js | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/app/compiler.js b/src/app/compiler.js index 46fb6ba427..aa80f95683 100644 --- a/src/app/compiler.js +++ b/src/app/compiler.js @@ -123,6 +123,8 @@ function Compiler (editor, handleGithubCall) { // try compiling again with the new set of inputs internalCompile(source.sources, missingInputs) } else { + data = updateInterface(data) + self.lastCompilationResult = { data: data, source: source @@ -270,6 +272,55 @@ function Compiler (editor, handleGithubCall) { } while (reloop) cb(null, { 'sources': files }) } + + function updateInterface (data) { + console.log(data) + + for (var contract in data.contracts) { + var abi = JSON.parse(data.contracts[contract].interface) + console.log(abi) + + var hasConstructor = false + var hasFallback = false + + for (var i = 0; i < abi.length; i++) { + var item = abi[i] + + if (item.type === "constructor") { + hasConstructor = true + } else if (item.type === "fallback") { + hasFallback = true + } + + // add "payable" to everything + // FIXME: only for compiler <0.4.0 + item.payable = true + } + + // FIXME: only for compiler <0.x.y + if (!hasConstructor) { + abi.push({ + type: 'constructor', + payable: true, + inputs: [] + }) + } + + // FIXME: only for compiler <0.4.0 + if (!hasFallback) { + abi.push({ + type: 'fallback', + payable: true + }) + } + + console.log(abi) + + data.contracts[contract].interface = JSON.stringify(abi) + } + + return data + } } module.exports = Compiler From f6cf244d8376fd51e8e115d33896331adbdbfc5b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 14 Nov 2016 20:05:50 +0000 Subject: [PATCH 02/13] Udapp: rely on constructor ABI to be supplied --- src/universal-dapp.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index bb9362745c..e6faf12418 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -196,6 +196,10 @@ UniversalDApp.prototype.getCreateInterface = function ($container, contract) { $createInterface.append($atButton) var $newButton = self.getInstanceInterface(contract) + if (!$newButton) { + return $createInterface + } + $createInterface.append($newButton) // Only display creation interface for non-abstract contracts. @@ -228,7 +232,12 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar return 1 } }) + var funABI = self.getConstructorInterface(abi) + if (!funABI) { + return + } + var $createInterface = $('
') var appendFunctions = function (address, $el) { @@ -362,16 +371,12 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar return $createInterface } -// either return the supplied constructor or a mockup (we assume everything can be instantiated) UniversalDApp.prototype.getConstructorInterface = function (abi) { - var funABI = { 'name': '', 'inputs': [], 'type': 'constructor', 'outputs': [] } for (var i = 0; i < abi.length; i++) { if (abi[i].type === 'constructor') { - funABI.inputs = abi[i].inputs || [] - break + return abi[i] } } - return funABI } UniversalDApp.prototype.getCallButton = function (args) { From 78bb4e0f76082f590edffad5d9e37447098cf331 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 14 Nov 2016 20:09:00 +0000 Subject: [PATCH 03/13] Udapp: show fallback button only if its in the ABI --- src/universal-dapp.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index e6faf12418..0acf15e386 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -316,13 +316,16 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar $instance.append($title) // Add the fallback function - $instance.append(self.getCallButton({ - abi: { constant: false, inputs: [], name: '(fallback)', outputs: [], type: 'function' }, - encode: function (args) { - return '' - }, - address: address - })) + var fallback = self.getFallbackInterface(abi) + if (fallback) { + $instance.append(self.getCallButton({ + abi: { constant: false, inputs: [], name: '(fallback)', outputs: [], type: 'function' }, + encode: function (args) { + return '' + }, + address: address + })) + } $.each(abi, function (i, funABI) { if (funABI.type !== 'function') { @@ -379,6 +382,14 @@ UniversalDApp.prototype.getConstructorInterface = function (abi) { } } +UniversalDApp.prototype.getFallbackInterface = function (abi) { + for (var i = 0; i < abi.length; i++) { + if (abi[i].type === 'fallback') { + return abi[i] + } + } +} + UniversalDApp.prototype.getCallButton = function (args) { var self = this // args.abi, args.encode, args.bytecode [constr only], args.address [fun only] From 8229fc358ae448f24f816f03970496a44d730e4a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 14 Nov 2016 20:32:05 +0000 Subject: [PATCH 04/13] Use semver to turn on interface features --- package.json | 1 + src/app/compiler.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2e98b348bb..6078b4e61b 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "jquery": "^2.2.0", "js-base64": "^2.1.9", "nightwatch": "^0.9.3", + "semver": "^5.3.0", "solc": "https://github.com/ethereum/solc-js", "standard": "^8.5.0", "tape": "^4.5.1", diff --git a/src/app/compiler.js b/src/app/compiler.js index aa80f95683..384205e0c3 100644 --- a/src/app/compiler.js +++ b/src/app/compiler.js @@ -2,6 +2,7 @@ var solc = require('solc/wrapper') +var semver = require('semver') var webworkify = require('webworkify') var utils = require('./utils') @@ -20,6 +21,8 @@ function Compiler (editor, handleGithubCall) { var cachedRemoteFiles = {} var worker = null + var currentVersion + var optimize = false this.setOptimize = function (_optimize) { @@ -53,6 +56,7 @@ function Compiler (editor, handleGithubCall) { this.setCompileJSON = setCompileJSON // this is exposed for testing function onCompilerLoaded (version) { + currentVersion = version self.event.trigger('compilerLoaded', [version]) } @@ -294,11 +298,14 @@ function Compiler (editor, handleGithubCall) { // add "payable" to everything // FIXME: only for compiler <0.4.0 - item.payable = true + if (semver.lt(currentVersion, '0.4.0')) { + item.payable = true + } } // FIXME: only for compiler <0.x.y - if (!hasConstructor) { + // 0.1.2 from Aug 2015 had it. The code has it since May 2015 (e7931ade) + if (!hasConstructor && semver.lt(currentVersion, '0.1.2')) { abi.push({ type: 'constructor', payable: true, @@ -307,7 +314,7 @@ function Compiler (editor, handleGithubCall) { } // FIXME: only for compiler <0.4.0 - if (!hasFallback) { + if (!hasFallback && semver.lt(currentVersion, '0.4.0')) { abi.push({ type: 'fallback', payable: true From 7bcceae9ff911d7fed63a3009cc42f9f05d5935a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 5 Dec 2016 11:35:27 +0000 Subject: [PATCH 05/13] Use solc/abi --- package.json | 1 - src/app/compiler.js | 46 ++------------------------------------------- 2 files changed, 2 insertions(+), 45 deletions(-) diff --git a/package.json b/package.json index 6078b4e61b..2e98b348bb 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "jquery": "^2.2.0", "js-base64": "^2.1.9", "nightwatch": "^0.9.3", - "semver": "^5.3.0", "solc": "https://github.com/ethereum/solc-js", "standard": "^8.5.0", "tape": "^4.5.1", diff --git a/src/app/compiler.js b/src/app/compiler.js index 384205e0c3..b0d7d6a6e5 100644 --- a/src/app/compiler.js +++ b/src/app/compiler.js @@ -1,8 +1,8 @@ 'use strict' var solc = require('solc/wrapper') +var solcABI = require('solc/abi') -var semver = require('semver') var webworkify = require('webworkify') var utils = require('./utils') @@ -278,51 +278,9 @@ function Compiler (editor, handleGithubCall) { } function updateInterface (data) { - console.log(data) - for (var contract in data.contracts) { var abi = JSON.parse(data.contracts[contract].interface) - console.log(abi) - - var hasConstructor = false - var hasFallback = false - - for (var i = 0; i < abi.length; i++) { - var item = abi[i] - - if (item.type === "constructor") { - hasConstructor = true - } else if (item.type === "fallback") { - hasFallback = true - } - - // add "payable" to everything - // FIXME: only for compiler <0.4.0 - if (semver.lt(currentVersion, '0.4.0')) { - item.payable = true - } - } - - // FIXME: only for compiler <0.x.y - // 0.1.2 from Aug 2015 had it. The code has it since May 2015 (e7931ade) - if (!hasConstructor && semver.lt(currentVersion, '0.1.2')) { - abi.push({ - type: 'constructor', - payable: true, - inputs: [] - }) - } - - // FIXME: only for compiler <0.4.0 - if (!hasFallback && semver.lt(currentVersion, '0.4.0')) { - abi.push({ - type: 'fallback', - payable: true - }) - } - - console.log(abi) - + abi = solcABI.update(currentVersion, abi) data.contracts[contract].interface = JSON.stringify(abi) } From d344b4b8cf8df1c67f09e069a267b5240e80d420 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 5 Dec 2016 12:13:37 +0000 Subject: [PATCH 06/13] udapp: if there is no constructor defined, we consider a non-payable constructor by default --- src/universal-dapp.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 0acf15e386..61ba877bef 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -380,6 +380,8 @@ UniversalDApp.prototype.getConstructorInterface = function (abi) { return abi[i] } } + + return { 'type': 'constructor', 'payable': false, 'inputs': [] } } UniversalDApp.prototype.getFallbackInterface = function (abi) { From 03caa281d4e42cb6bf28dbdbdbcc33b09b0db8f6 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 5 Dec 2016 12:30:42 +0000 Subject: [PATCH 07/13] Udapp: make buttons consistent --- src/universal-dapp.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 61ba877bef..99bfb8d26c 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -616,10 +616,17 @@ UniversalDApp.prototype.getCallButton = function (args) { }) } + var title + if (isConstructor) { + title = 'Create' + } else { + title = args.abi.name + } + var button = $('