Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Feature) Extract the version of solc compiler from Truffle #1141

Merged
merged 5 commits into from Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -27,6 +27,7 @@ before_script:
- npm run installWeb3
- bash ./scripts/generateProxyContracts.sh
- npm run moveTruffleConfigPublic
- npm run moveSolcVersionOutputPublic
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3
Expand Down
6 changes: 4 additions & 2 deletions package-scripts.js
Expand Up @@ -19,15 +19,17 @@ module.exports = {
ncp('./build/index.html ./build/manage.html'),
ncp('./build/index.html ./build/stats.html'),
'bash ./scripts/generateProxyContracts.sh',
'npm run moveTruffleConfigBuild'
'npm run moveTruffleConfigBuild',
'npm run moveSolcVersionOutputBuild'
)
},
dev: {
default: series(
'git submodule update --init --recursive --remote',
'npm run installWeb3',
'bash ./scripts/generateProxyContracts.sh',
'npm run moveTruffleConfigPublic'
'npm run moveTruffleConfigPublic',
'npm run moveSolcVersionOutputPublic'
),
Minted: {
default: series(
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -82,6 +82,7 @@
"immutability-helper": "^2.5.0",
"jest": "20.0.4",
"jquery": "^3.2.1",
"json-loader": "^0.5.7",
"jszip": "^3.1.4",
"logdown": "^3.2.3",
"mobx": "^3.3.0",
Expand Down Expand Up @@ -125,13 +126,15 @@
},
"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 && npm run moveTruffleConfigPublic && node scripts/start.js",
"start": "npm run installWeb3 && bash ./scripts/generateProxyContracts.sh && npm run moveTruffleConfigPublic && npm run moveSolcVersionOutputPublic && 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",
"moveSolcVersionOutputBuild": "node scripts/moveSolcVersionOutput.js build",
"moveSolcVersionOutputPublic": "node scripts/moveSolcVersionOutput.js public",
"build": "nps build",
"sass:watch": "gulp watch",
"sass:update": "gulp sass",
Expand Down
5 changes: 5 additions & 0 deletions scripts/getDutchSolcVersion.sh
@@ -0,0 +1,5 @@
#!/bin/bash
dutchPath=submodules/auth-os-applications/TokenWizard/crowdsale/DutchCrowdsale
cd $dutchPath
npm i
./node_modules/.bin/truffle version
5 changes: 5 additions & 0 deletions scripts/getMintedCappedSolcVersion.sh
@@ -0,0 +1,5 @@
#!/bin/bash
mintedPath=submodules/auth-os-applications/TokenWizard/crowdsale/MintedCappedCrowdsale
cd $mintedPath
npm i
./node_modules/.bin/truffle version
20 changes: 8 additions & 12 deletions scripts/helpers/deployContract.js
@@ -1,15 +1,11 @@
module.exports = deployContract

function deployContract(web3, abi, bin, from, gas = 1500000, gasPrice = '5000000000') {
module.exports.deployContract = (web3, abi, bin, from, gas = 1500000, gasPrice = '5000000000') => {
const Contract = new web3.eth.Contract(abi, { from })

return Contract
.deploy({
data: bin
})
.send({
from,
gas,
gasPrice
})
return Contract.deploy({
data: bin
}).send({
from,
gas,
gasPrice
})
}
64 changes: 64 additions & 0 deletions scripts/helpers/utils.js
@@ -0,0 +1,64 @@
const fs = require('fs')

/**
* Copy file from source to target
* @param source
* @param target
* @param cb
*/
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
}
}
}

/**
* Write a file with a given content
* @param target
* @param content
* @param cb
*/
const writeFile = (target, content, cb) => {
let cbCalled = false

let wr = fs.createWriteStream(target, { autoClose: true, flags: 'w', encoding: 'utf-8', mode: '0666' })
wr.on('error', err => {
done(err)
})
wr.on('finish', ex => {
done()
})

let newContent = JSON.stringify(content, null, 2)
wr.write((newContent += '\r\n'))

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

module.exports = {
copyFile: copyFile,
writeFile: writeFile
}
50 changes: 50 additions & 0 deletions scripts/moveSolcVersionOutput.js
@@ -0,0 +1,50 @@
/**
* Script that create a json file with the truffle version in a public folder
*/

const shell = require('shelljs')
const { writeFile } = require('./helpers/utils')

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

const getObjectVersion = strategy => {
const pathToBin = `./scripts/get${strategy}SolcVersion.sh`
const { stdout, code } = shell.exec(pathToBin, { silent: true })

if (code !== 0) {
throw new Error('There is a problem obtaining the solc version')
}

const version = stdout.match(/(?:\^0|\d*)\.(?:0|\d*)\.(?:0|\d*)/gi) || ['4.1.14', '4.1.14', '0.4.24']

return {
truffleVersion: version[0],
truffleCoreVersion: version[1],
solcVersion: version[2]
}
}

const createObjectVersion = (strategy, content) => {
try {
const strategiesAllowed = ['Dutch', 'MintedCapped']
if (!strategiesAllowed.includes(strategy)) {
throw new Error('Strategy doesnt exist')
}
const destinyPath = `${__dirname}/../${directory}/metadata/${strategy}TruffleVersions.json`

writeFile(destinyPath, content, err => {
if (err) {
console.log(`Error creating version file`, err)
}
})
} catch (e) {
console.log(e)
}
}

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

for (let strategy of strategiesToMove) {
const objectVersion = getObjectVersion(strategy)
createObjectVersion(strategy, objectVersion)
}
30 changes: 5 additions & 25 deletions scripts/moveTruffleConfig.js
@@ -1,30 +1,10 @@
const fs = require('fs')
/**
* Script that move truffle config to a public folder
*/

const directory = process.argv.slice(2)[0]
const { copyFile } = require('./helpers/utils')

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 directory = process.argv.slice(2)[0] || 'public'

const copyStrategy = strategy => {
try {
Expand Down
4 changes: 0 additions & 4 deletions src/components/stepFour/constants.js
Expand Up @@ -19,7 +19,3 @@ export const TX_STEP_DESCRIPTION = {
crowdsaleInit: 'Initialize Crowdsale',
trackProxy: 'Add Proxy contract to registry'
}

export const CONTRACT_SETTINGS = {
COMPILER_VERSION: '0.4.24'
}
10 changes: 6 additions & 4 deletions src/components/stepFour/index.js
Expand Up @@ -9,7 +9,8 @@ import {
handlerForFile,
scrollToBottom,
summaryFileContents,
getOptimizationFlagByStore
getOptimizationFlagByStore,
getVersionFlagByStore
} from './utils'
import { noContractDataAlert, successfulDeployment, skippingTransaction, deployHasEnded } from '../../utils/alerts'
import {
Expand All @@ -21,7 +22,7 @@ import {
PUBLISH_DESCRIPTION,
CROWDSALE_STRATEGIES
} from '../../utils/constants'
import { CONTRACT_SETTINGS, DOWNLOAD_TYPE } from './constants'
import { DOWNLOAD_TYPE } from './constants'
import { getNetworkID, toast } from '../../utils/utils'
import { StepNavigation } from '../Common/StepNavigation'
import { DisplayField } from '../Common/DisplayField'
Expand Down Expand Up @@ -382,11 +383,12 @@ export class stepFour extends Component {
CONTRACT_NAME: PD_CONTRACT_NAME,
COMPILING_OPTIMIZATION: PD_COMPILING_OPTIMIZATION
} = PUBLISH_DESCRIPTION
const { COMPILER_VERSION: PRAGMA } = CONTRACT_SETTINGS
const optimizationFlag = getOptimizationFlagByStore(crowdsaleStore)
const versionFlag = getVersionFlagByStore(crowdsaleStore)

return (
<div className="hidden">
<DisplayField side="left" title={COMPILER_VERSION} value={PRAGMA} description={PD_COMPILER_VERSION} />
<DisplayField side="left" title={COMPILER_VERSION} value={versionFlag} description={PD_COMPILER_VERSION} />
<DisplayField
side="right"
title={CONTRACT_NAME}
Expand Down
39 changes: 36 additions & 3 deletions src/components/stepFour/utils.js
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../utils/blockchainHelpers'
import { countDecimalPlaces, toBigNumber, toFixed } from '../../utils/utils'
import { CROWDSALE_STRATEGIES } from '../../utils/constants'
import { DOWNLOAD_NAME, MINTED_PREFIX, DUTCH_PREFIX, ADDR_BOX_LEN, CONTRACT_SETTINGS } from './constants'
import { DOWNLOAD_NAME, MINTED_PREFIX, DUTCH_PREFIX, ADDR_BOX_LEN } from './constants'
import { REACT_PREFIX } from '../../utils/constants'
import { isObservableArray } from 'mobx'
import {
Expand Down Expand Up @@ -1072,7 +1072,7 @@ export const summaryFileContents = networkID => {
}

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

return {
Expand All @@ -1098,7 +1098,7 @@ export const summaryFileContents = networkID => {
'\n',
...bigHeaderElements('**********METADATA***********'),
{ field: 'proxyName', value: 'Contract name: ', parent: 'crowdsaleStore' },
{ value: 'Compiler version: ', parent: 'none', fileValue: COMPILER_VERSION },
{ value: 'Compiler version: ', parent: 'none', fileValue: versionFlag },
{ value: 'Optimized: ', parent: 'none', fileValue: optimizationFlag },
{ value: 'Encoded ABI parameters: ', parent: 'none', fileValue: abiEncoded },
...footerElemets
Expand Down Expand Up @@ -1153,6 +1153,28 @@ export const getPragmaVersion = async strategy => {
return firstLine.match(/(?:\^0|\d*)\.(?:0|\d*)\.(?:0|\d*)/gi) || '0.4.24'
}

export const getVersionFlagByStrategy = 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(`json-loader!../../../public/metadata/${strategy}TruffleVersions.json`)
} else {
constants = require(`json-loader!../../../build/metadata/${strategy}TruffleVersions.json`)
}
} catch (err) {
logger.log('Error require truffle version', err)
}
const { solcVersion = '0.4.24' } = constants

return solcVersion
}

export const getOptimizationFlagByStrategy = strategy => {
const strategiesAllowed = getStrategies()
if (!strategiesAllowed.includes(strategy)) {
Expand Down Expand Up @@ -1185,3 +1207,14 @@ export const getOptimizationFlagByStore = crowdsaleStore => {
}
return getOptimizationFlagByStrategy(strategy)
}

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