-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
41 lines (35 loc) · 1.34 KB
/
index.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
let fs = require('fs');
let solc = require('solc');
let co = require('co')
let path = require('path')
let trustcoinSourcePath = path.join(__dirname, './contracts/Trustcoin.sol')
let trustcoinDepPath = path.join(__dirname, './contracts/deps/ERC20TokenInterface.sol')
const SOLC_VERSION = 'v0.4.8+commit.60cc1668'
function getContractContents(filepath) {
let content = fs.readFileSync(filepath, 'utf8');
return content;
}
function compileSource (input, callback) {
return new Promise((resolve, reject) => {
solc.loadRemoteVersion(SOLC_VERSION, function(e, correctSolc) {
if (e) {
throw new Error('Could not load correct solc version', e)
}
let output = correctSolc.compile({sources: input}, 1)
resolve(output)
})
})
}
let main = {
getContract: co.wrap(function*() {
let compilerInput = {
'Trustcoin.sol': getContractContents(trustcoinSourcePath),
'deps/ERC20TokenInterface.sol': getContractContents(trustcoinDepPath)
}
let compiledOutput = yield compileSource(compilerInput)
let contractOutput = compiledOutput.contracts.Trustcoin
let trustcoinContractAbi = JSON.parse(contractOutput.interface);
return {abi: trustcoinContractAbi, bytecode: contractOutput.bytecode};
})
}
module.exports = main