-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
156 lines (104 loc) · 3.78 KB
/
server.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const express = require('express')
const shell = require('shelljs')
const path1 = require('path');
const app = express()
const exec = require('child_process').exec;
require('dotenv').config()
const port = process.env.port;
var bodyParser = require('body-parser');
//app.use(express.static(__dirname));
app.use(express.static(path1.join(__dirname, "public")));
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
var password = process.env.Walletkey;
var path = process.env.path;
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/index.html');
})
app.post('/table', function(req, res) {
var type = "table";
var contract = req.body.contractT;
var scope = req.body.scopeT;
var tablename = req.body.tablenameT;
var yourscript = exec('sh dplyr.sh '+password +" "+type+" "+contract + " "+scope+" "+tablename,
(error, stdout, stderr) => {
var objOut = {
"stdout":`${stdout}`,
"stderr":`${stderr}`,
"error":`${error}`
}
res.send(objOut);
});
});
app.post('/compile', function(req, res) {
var type = "compile";
var contractName = req.body.accountname;
var yourscript = exec('sh dplyr.sh '+password +" "+type+" "+path + " "+contractName,
(error, stdout, stderr) => {
var objOut = {
"stdout":`${stdout}`,
"stderr":`${stderr}`,
"error":`${error}`
}
res.send(objOut);
});
});
app.post('/push', function(req, res) {
var type = "push";
var contractName = req.body.accountname;
var action = req.body.action;
var data = req.body.Pushdata;
var authorizeAccount = req.body.authorizeAccount;
//cleos push action addressbook upsert '["a", "alicew", "liddell", "123 drinwwk me way", "wonderland", "amsterdam"]' -p a@active
var yourscript = exec('sh dplyr.sh '+password +" "+type+" "+contractName+" "+ action +" "+data+" "+authorizeAccount ,
(error, stdout, stderr) => {
console.log( `${stdout}:${stderr}:${error}` );
var objOut = {
"stdout":`${stdout}`,
"stderr":`${stderr}`,
"error":`${error}`
}
res.send( objOut );
});
});
app.post('/createA', function(req, res) {
var type = "create";
var contractFileName = req.body.accountname;
var contractName = req.body.accountname;
if(contractName.includes(".")){
console.log("##### has . ####");
contractName = contractName.split(".")[1];
}
var ownerkey =process.env.Developmentkey;
var isContract = req.body.chk;
//dplyr.sh is a bash file where cleos exists
var deployscript = exec('sh dplyr.sh '+password +" "+type+" "+path + " "+contractFileName+" "+ownerkey +" "+isContract+" "+contractName,
(error, stdout, stderr) => {
var objOut = {
"stdout":`${stdout}`,
"stderr":`${stderr}`,
"error":`${error}`
}
res.send( objOut);
});
});
app.post('/create', function(req, res) {
var type = "create";
var contractName = req.body.accountname;
var isContract = req.body.chk;
var ownerkey =process.env.Developmentkey;
//dplyr.sh is a bash file where cleos exists
var deployscript = exec('sh dplyr.sh '+password +" "+type+" "+path + " "+contractName +" "+ownerkey +" "+isContract,
(error, stdout, stderr) => {
var objOut = {
"stdout":`${stdout}`,
"stderr":`${stderr}`,
"error":`${error}`
}
res.send( objOut );
});
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}!`)})
//eosio-cpp -o abcounter.wasm abcounter.cpp --abigen
//cleos set contract abcounter /home/hasura/Music/contracts/abcounter/