-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.js
More file actions
54 lines (49 loc) · 1.57 KB
/
app.js
File metadata and controls
54 lines (49 loc) · 1.57 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
var web3 = require('web3');
var request = require('request');
var express = require('express');
var bodyParser = require('body-parser');
var fs = require('fs');
var Tx = require('ethereumjs-tx');
var app = express();
var hostname = "http://127.0.0.1";
var web3 = new web3(new web3.providers.HttpProvider('http://localhost:8545'));
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/',function(req,res){
fs.readFile('index.html',function(error,data){
res.writeHead(200,{'Content-Type':'text/html'});
res.end(data);
});
});
app.post("/action", function(req, res) {
var article = fs.readFileSync("./hello.txt");
lineArray = article.toString();
var secret = 'abcdefg';
var hash = crypto.createHmac('sha256', secret).update(lineArray).digest('hex');
web3.eth.signTransaction({
from: "0x4d742c10916d042b923ce800608da5208389dd7b",
gas: 392972,
gasPrice: 18000000000,
data: '0x'+hash,
nonce: web3.eth.getTransactionCount("0x4d742c10916d042b923ce800608da5208389dd7b")
}, function(error, result){
if (!error)
{
var rawTx = result.raw;
web3.eth.sendRawTransaction(rawTx, function(error, result2){
if(error){
res.send("다른 문서의 저장이 이루어지고 있습니다. 잠시 후 다시 시도해주세요.");
}
else {
res.send("문서가 블록체인에 정상적으로 저장되었습니다. 당신의 문서 번호는 " + result2 + "입니다.");
}
})
}
else
{
res.send("계정 잠금 해제 필요");
}
})
});
app.listen(8080, function() {
console.log('Server running at ' + hostname + ":8080");
});