forked from summa-tx/bitcoin-spv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.js
42 lines (35 loc) · 1.42 KB
/
compile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const path = require('path')
const solc = require('solc')
const fs = require('fs-extra')
// Path to compiled json contracts
const buildPath = path.resolve(__dirname, 'build')
fs.removeSync(buildPath)
fs.ensureDirSync(buildPath)
// Paths to solidity contracts
const SPVStorePath = path.resolve(__dirname, 'contracts', 'SPVStore.sol')
const BTCUtilsPath = path.resolve(__dirname, 'contracts', 'BTCUtils.sol')
const ValidateSPVPath = path.resolve(__dirname, 'contracts', 'ValidateSPV.sol')
const BytesPath = path.resolve(__dirname, 'contracts', 'BytesLib.sol')
const SafeMathPath = path.resolve(__dirname, 'contracts', 'SafeMath.sol')
const SigCheckPath = path.resolve(__dirname, 'contracts', 'SigCheck.sol')
let input = {
'SPVStore.sol': fs.readFileSync(SPVStorePath, 'utf8'),
'BTCUtils.sol': fs.readFileSync(BTCUtilsPath, 'utf8'),
'ValidateSPV.sol': fs.readFileSync(ValidateSPVPath, 'utf8'),
'BytesLib.sol': fs.readFileSync(BytesPath, 'utf8'),
'SafeMath.sol': fs.readFileSync(SafeMathPath, 'utf8'),
'SigCheck.sol': fs.readFileSync(SigCheckPath, 'utf8')
}
const output = solc.compile({sources: input}, 1);
// log errors
if (output.errors) {
console.log(output.errors);
}
// Save compiled contracts to json files
for (let contract in output.contracts) {
contract_name = contract.split(':');
fs.outputJsonSync(
path.resolve(buildPath, contract_name[1] + '.json'),
output.contracts[contract]
)
}