Skip to content

Commit b7eb508

Browse files
deploy
1 parent 04a392e commit b7eb508

File tree

3 files changed

+142
-12
lines changed

3 files changed

+142
-12
lines changed

build_contract.js

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
//TODO import all import "./zeppelin-solidity/ownership/Ownable.sol";
2+
//TODO change all pragma solidity ^0.4.11; to pragma solidity ^0.4.17;
3+
//TODO compile
4+
//TODO deploy
5+
//TODO verification
6+
//
7+
// if (process.argv.length < 3) {
8+
// console.log('Usage: node ' + process.argv[1] + ' FILENAME -i -p=0.4.17');
9+
// process.exit(1);
10+
// }
11+
12+
13+
const inputFileName = './contracts/contracts/Abab.sol';
14+
const pragma = '^0.4.11';
15+
const account_address = '0xa1b1d9551211755165a677c5e9d4b1041f4b5fd6';
16+
const account_private = 'df03891cdfb422bf856717211fb09733962e8feff9e7284e1304e1b1f2d55082';
17+
18+
global._path_root = __dirname + '/';
19+
20+
const config = require('./app/modules/config');
21+
const sol_config = require('./config.sol');
22+
const Web3 = require('web3');
23+
const web3 = new Web3();
24+
web3.setProvider(new web3.providers.HttpProvider(config.get('geth:host')));
25+
const util = require('ethereumjs-util');
26+
const Tx = require('ethereumjs-tx');
27+
28+
const fs = require('fs');
29+
const path = require('path');
30+
var solc = require('solc');
31+
var argv = require('minimist')(process.argv.slice(2));
32+
const importFile = [];
33+
function readFile(fileName) {
34+
console.log('Import: ' + fileName,);
35+
if (importFile.indexOf(fileName) !== -1) {
36+
return ''
37+
}
38+
39+
importFile.push(fileName);
40+
let dirname__ = path.dirname(fileName);
41+
let inputFile = fs.readFileSync(fileName, 'utf8');
42+
let result = '';
43+
let inputFileArr = inputFile.split(/\r?\n/);
44+
for (let i in inputFileArr) {
45+
let inputLine = inputFileArr[i];
46+
let resultLine = inputLine;
47+
let prepareLine = inputLine.trim().replace(new RegExp(" +", 'g'), " ");
48+
// console.log(line);
49+
if (resultLine.startsWith('import')) {
50+
let modulerel = resultLine.trim().split('"')[1] || resultLine.trim().split("'")[1];
51+
let modulePath = path.resolve(dirname__, modulerel);
52+
resultLine = readFile(modulePath);//Проверить, что файл с таким именем ещё не импортировался
53+
}
54+
if (resultLine.startsWith('pragma')) {
55+
resultLine = '';
56+
}
57+
result += resultLine + '\n';
58+
}
59+
60+
return result;
61+
62+
63+
}
64+
function compile(pragma, inputFileName) {
65+
let source = '';
66+
source += 'pragma solidity '+pragma+';';
67+
source += readFile(inputFileName);
68+
return source;
69+
}
70+
71+
72+
var source = compile(pragma, inputFileName);
73+
function deploy(source, cb) {
74+
75+
solc.loadRemoteVersion('latest', function (err, solcSnapshot) {
76+
console.log('Your current Solidity version is:\n\t', solcSnapshot.version());
77+
var output = solcSnapshot.compile(source, 1);
78+
79+
var browser_untitled_sol_ababContract = web3.eth.contract(JSON.parse(output.contracts[':Abab'].interface));
80+
console.log(source);
81+
82+
console.log(output.contracts[':Abab'].bytecode);
83+
// var browser_untitled_sol_abab = browser_untitled_sol_ababContract.new(
84+
// {
85+
// from: web3.eth.accounts[0] || account_address,
86+
// data: '0x' + output.contracts[':Abab'].bytecode,
87+
// gas: '4300000'
88+
// }, function (e, contract) {
89+
// console.log(e, contract);
90+
// if (typeof contract.address !== 'undefined') {
91+
// console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
92+
// }
93+
// });
94+
95+
let nonce = web3.eth.getTransactionCount(account_address);
96+
let privateKey = new Buffer(account_private, 'hex');
97+
let payloadData = '0x' + output.contracts[':Abab'].bytecode;
98+
99+
100+
let gasPriceHex = util.bufferToHex(21000000000);
101+
let gasLimitHex = util.bufferToHex(4000000);
102+
let nonceHex = util.bufferToHex(nonce);
103+
let tx = new Tx({
104+
nonce: nonceHex,
105+
gasPrice: gasPriceHex,
106+
gasLimit: gasLimitHex,
107+
to: '',
108+
from: account_address,
109+
value: '0x00',
110+
data: payloadData,
111+
chainId: 3 // 3 == testnet ropsten ,1 == original
112+
113+
});
114+
tx.sign(privateKey);
115+
let serializedTx = tx.serialize();
116+
117+
web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function (err, hash) {
118+
console.log('Contract send tx:' + hash);
119+
console.log('Wait confirm transaction... (1 - 5 min)');
120+
let checkTx = setInterval(function () {
121+
let txData = web3.eth.getTransactionReceipt(hash);
122+
if (!txData) {
123+
console.log('Tx check.');
124+
return false;
125+
}
126+
cb && cb(txData);
127+
clearInterval(checkTx);
128+
129+
130+
}, 10000);
131+
132+
});
133+
});
134+
}
135+
deploy(source, function (tx) {
136+
console.log('Deploy Contract Success:\n\tAddress: ' + tx.contractAddress + '\n\tBlockHash: '+ tx.blockHash + '\n\tblockNumber: '+ tx.blockNumber )
137+
});
138+
// console.log(output.contracts[':Abab'].bytecode);
139+
// console.log(output.contracts[':Abab'].interface);
140+

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"request": "^2.81.0",
6060
"s3-image-uploader": "^1.0.7",
6161
"shelljs": "^0.7.8",
62+
"solc": "^0.4.16",
6263
"tabgeo": "^0.1.0",
6364
"web3": "^0.19.1",
6465
"winston": "^2.3.1"

web/src/js/ABAB.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,7 @@ function initMap() {
242242

243243
}
244244
var ABAB = {
245-
map:{
246-
init:false,
247-
cb_function_arr: [],
248-
call_wait_auth: function (fn) {
249-
if (!ABAB.map.init) {
250-
ABAB.map.cb_function_arr.push(fn);
251-
} else {
252-
fn();
253-
}
254-
},
255-
fn:function(){}
256-
},
245+
257246
event: {},
258247
page: null,
259248
pageObj: {

0 commit comments

Comments
 (0)