Skip to content

Commit

Permalink
fix: support dynamic solc for genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
DhairyaSethi committed Aug 27, 2024
1 parent bec2985 commit 46311f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ jobs:
- uses: actions/checkout@v3
- name: Update Path
run: echo "$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)" >> $GITHUB_PATH # Make it accessible from runner
- name: Install solc
- name: Install svm
run: |
set -x
wget -c https://github.com/ethereum/solidity/releases/download/v0.5.17/solc-static-linux
mv solc-static-linux solc
chmod +x solc
solc --version
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cargo install svm-rs
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
Expand Down
65 changes: 34 additions & 31 deletions generate-genesis.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,12 @@ program.option(
program.parse(process.argv)

// compile contract
function compileContract(key, contractFile, contractName) {
async function compileContract(key, contractFile, contractName, solcVersion) {
return new Promise((resolve, reject) => {
const ls = spawn("solc", [
"--bin-runtime",
"openzeppelin-solidity/=node_modules/openzeppelin-solidity/",
"solidity-rlp/=node_modules/solidity-rlp/",
"/=/",
// "--optimize",
// "--optimize-runs",
// "200",
contractFile
])
const ls = spawn(
`svm use ${solcVersion} && solc --bin-runtime openzeppelin-solidity/=node_modules/openzeppelin-solidity/ solidity-rlp/=node_modules/solidity-rlp/ /=/ ${contractFile}`,
{ shell: true }
)

const result = []
ls.stdout.on("data", data => {
Expand All @@ -64,25 +58,32 @@ function compileContract(key, contractFile, contractName) {
})
}

// compile files
Promise.all([
compileContract(
"borValidatorSetContract",
"contracts/BorValidatorSet.sol",
"BorValidatorSet"
),
compileContract(
"borStateReceiverContract",
"contracts/StateReceiver.sol",
"StateReceiver"
),
compileContract(
"maticChildERC20Contract",
"matic-contracts/contracts/child/MRC20.sol",
"MRC20"
)
]).then(result => {
const totalMaticSupply = web3.utils.toBN("10000000000")
// compile files sequentially
async function main() {
const result = []
for (const file of [
[
"borValidatorSetContract",
"contracts/BorValidatorSet.sol",
"BorValidatorSet",
"0.5.17"
],
[
"borStateReceiverContract",
"contracts/StateReceiver.sol",
"StateReceiver",
"0.6.12"
],
[
"maticChildERC20Contract",
"matic-contracts/contracts/child/MRC20.sol",
"MRC20",
"0.5.17"
]
]) {
result.push(await compileContract(...file))
}
const totalMaticSupply = web3.utils.toBN('10000000000')

var validatorsBalance = web3.utils.toBN(0)
validators.forEach(v => {
Expand All @@ -108,7 +109,9 @@ Promise.all([
const templateString = fs.readFileSync(program.template).toString()
const resultString = nunjucks.renderString(templateString, data)
fs.writeFileSync(program.output, resultString)
}).catch(err => {
}

main().catch(err => {
console.log(err)
process.exit(1)
})

0 comments on commit 46311f3

Please sign in to comment.