Skip to content

Commit

Permalink
Merge pull request #1128 from poanetwork/issue#1124
Browse files Browse the repository at this point in the history
(Feature) automatically define compiler optimization flag from related sumodule
  • Loading branch information
fernandomg committed Sep 12, 2018
2 parents dc4e607 + 4cc3a13 commit 1a7563c
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ debug.log*

.idea
travis.sh
public/contracts/DutchProxy*
public/contracts/MintedCappedProxy*
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ before_script:
- git submodule update --init --recursive --remote
- npm run installWeb3
- bash ./scripts/generateProxyContracts.sh
- npm run moveTruffleConfigPublic
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3
Expand Down
98 changes: 93 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ module.exports = {
ncp('./build/index.html ./build/crowdsale.html'),
ncp('./build/index.html ./build/manage.html'),
ncp('./build/index.html ./build/stats.html'),
'bash ./scripts/generateProxyContracts.sh'
'bash ./scripts/generateProxyContracts.sh',
'npm run moveTruffleConfigBuild'
)
},
dev: {
default: series(
'git submodule update --init --recursive --remote',
'npm run installWeb3',
'bash ./scripts/generateProxyContracts.sh'
'bash ./scripts/generateProxyContracts.sh',
'npm run moveTruffleConfigPublic'
),
Minted: {
default: series(
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,13 @@
},
"scripts": {
"installWeb3": "cd submodules/poa-web3-1.0 && npm install && cd ../../ && npm install --no-save submodules/poa-web3-1.0/packages/web3",
"start": "npm run installWeb3 && bash ./scripts/generateProxyContracts.sh && node scripts/start.js",
"start": "npm run installWeb3 && bash ./scripts/generateProxyContracts.sh && npm run moveTruffleConfigPublic && node scripts/start.js",
"dev": "nps dev",
"dev:minted": "nps dev.Minted",
"dev:dutch": "nps dev.Dutch",
"deployRegistry": "node scripts/deployRegistry.js",
"moveTruffleConfigBuild": "node scripts/moveTruffleConfig.js build",
"moveTruffleConfigPublic": "node scripts/moveTruffleConfig.js public",
"build": "nps build",
"sass:watch": "gulp watch",
"sass:update": "gulp sass",
Expand Down
2 changes: 2 additions & 0 deletions public/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Empty file removed public/contracts/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions public/metadata/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
52 changes: 52 additions & 0 deletions scripts/moveTruffleConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const fs = require('fs')

const directory = process.argv.slice(2)[0]

const copyFile = (source, target, cb) => {
let cbCalled = false

let rd = fs.createReadStream(source)
rd.on('error', function(err) {
done(err)
})
let wr = fs.createWriteStream(target)
wr.on('error', err => {
done(err)
})
wr.on('close', ex => {
done()
})
rd.pipe(wr)

function done(err) {
if (!cbCalled) {
cb(err)
cbCalled = true
}
}
}

const copyStrategy = strategy => {
try {
const strategiesAllowed = ['Dutch', 'MintedCapped']
if (!strategiesAllowed.includes(strategy)) {
throw new Error('Strategy doesnt exist')
}
const originPath = `${__dirname}/../submodules/auth-os-applications/TokenWizard/crowdsale/${strategy}Crowdsale/truffle.js`
const destinyPath = `${__dirname}/../${directory}/metadata/${strategy}CrowdsaleTruffle.js`

copyFile(originPath, destinyPath, err => {
if (err) {
console.log(`Error moving files`, err)
}
})
} catch (e) {
console.log(e)
}
}

const strategiesToMove = ['Dutch', 'MintedCapped']

for (let strategy of strategiesToMove) {
copyStrategy(strategy)
}
1 change: 0 additions & 1 deletion src/components/stepFour/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ export const TX_STEP_DESCRIPTION = {
}

export const CONTRACT_SETTINGS = {
OPTIMIZATION: 'Yes',
COMPILER_VERSION: '0.4.24'
}
8 changes: 5 additions & 3 deletions src/components/stepFour/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
handleContractsForFile,
handlerForFile,
scrollToBottom,
summaryFileContents
summaryFileContents,
getOptimizationFlagByStore
} from './utils'
import { noContractDataAlert, successfulDeployment, skippingTransaction, deployHasEnded } from '../../utils/alerts'
import {
Expand Down Expand Up @@ -381,7 +382,8 @@ export class stepFour extends Component {
CONTRACT_NAME: PD_CONTRACT_NAME,
COMPILING_OPTIMIZATION: PD_COMPILING_OPTIMIZATION
} = PUBLISH_DESCRIPTION
const { OPTIMIZATION, COMPILER_VERSION: PRAGMA } = CONTRACT_SETTINGS
const { COMPILER_VERSION: PRAGMA } = CONTRACT_SETTINGS
const optimizationFlag = getOptimizationFlagByStore(crowdsaleStore)
return (
<div className="hidden">
<DisplayField side="left" title={COMPILER_VERSION} value={PRAGMA} description={PD_COMPILER_VERSION} />
Expand All @@ -394,7 +396,7 @@ export class stepFour extends Component {
<DisplayField
side="left"
title={COMPILING_OPTIMIZATION}
value={OPTIMIZATION}
value={optimizationFlag}
description={PD_COMPILING_OPTIMIZATION}
/>
</div>
Expand Down
53 changes: 51 additions & 2 deletions src/components/stepFour/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,9 @@ export const summaryFileContents = networkID => {
}

const { abiEncoded } = contractStore[crowdsaleStore.proxyName]
const { OPTIMIZATION, COMPILER_VERSION } = CONTRACT_SETTINGS
const { COMPILER_VERSION } = CONTRACT_SETTINGS
const optimizationFlag = getOptimizationFlagByStore(crowdsaleStore)

return {
common: [
...bigHeaderElements('*********TOKEN SETUP*********'),
Expand All @@ -1097,7 +1099,7 @@ export const summaryFileContents = networkID => {
...bigHeaderElements('**********METADATA***********'),
{ field: 'proxyName', value: 'Contract name: ', parent: 'crowdsaleStore' },
{ value: 'Compiler version: ', parent: 'none', fileValue: COMPILER_VERSION },
{ value: 'Optimized: ', parent: 'none', fileValue: OPTIMIZATION },
{ value: 'Optimized: ', parent: 'none', fileValue: optimizationFlag },
{ value: 'Encoded ABI parameters: ', parent: 'none', fileValue: abiEncoded },
...footerElemets
],
Expand Down Expand Up @@ -1136,3 +1138,50 @@ export const summaryFileContents = networkID => {
}
}
}

export const getStrategies = () => {
return ['Dutch', 'MintedCapped']
}

export const getPragmaVersion = async strategy => {
const strategiesAllowed = getStrategies()
if (!strategiesAllowed.includes(strategy)) {
throw new Error('Strategy not exist')
}
const contractFile = await (await fetch(`./contracts/${strategy}Proxy.sol`)).text()
const firstLine = contractFile.split('\n')[0]
return firstLine.match(/(?:\^0|\d*)\.(?:0|\d*)\.(?:0|\d*)/gi) || '0.4.24'
}

export const getOptimizationFlagByStrategy = strategy => {
const strategiesAllowed = getStrategies()
if (!strategiesAllowed.includes(strategy)) {
throw new Error('Strategy not exist')
}

//Check path by enviroment variable
let constants
try {
if (['development', 'test'].includes(process.env.NODE_ENV)) {
constants = require(`../../../public/metadata/${strategy}CrowdsaleTruffle.js`)
} else {
constants = require(`../../../build/metadata/${strategy}CrowdsaleTruffle.js`)
}
} catch (err) {
logger.log('Error require truffle config', err)
}
const { solc } = constants

return solc && solc.optimizer && solc.optimizer.enabled ? 'Yes' : 'No'
}

export const getOptimizationFlagByStore = crowdsaleStore => {
let strategy
if (crowdsaleStore.isDutchAuction) {
strategy = 'Dutch'
}
if (crowdsaleStore.isMintedCappedCrowdsale) {
strategy = 'MintedCapped'
}
return getOptimizationFlagByStrategy(strategy)
}

0 comments on commit 1a7563c

Please sign in to comment.