Repository navigation
Expand file tree
/
Copy pathserver.js.snippet
More file actions
104 lines (96 loc) · 4.16 KB
/
Copy pathserver.js.snippet
File metadata and controls
104 lines (96 loc) · 4.16 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
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
// 获取账户余额 警告 要大于 0.001Eth
// const getBalance = (callback) => {
// web3.eth.getBalance(web3.eth.defaultAccount, (error, balance) => {
// if (error) {
// dataObject.res.end(JSON.stringify(responceData.evmError));
// // 保存log
// // log.saveLog(operation[2], new Date().toLocaleString(), qs.withdrawAddress, 0, 0, responceData.evmError);
// return;
// }
// console.log('balance =>', balance);
// if (balance && web3.utils.fromWei(balance, "ether") < 0.001) {
// // 返回failed 附带message
// dataObject.res.end(JSON.stringify(responceData.lowBalance));
// // 保存log
// // log.saveLog(operation[2], new Date().toLocaleString(), qs.withdrawAddress, 0, 0, responceData.lowBalance);
// return;
// }
// callback();
// });
// }
// // 获取data部分的nonce
// const getNonce = () => {
// return new Promise((resolve, reject) => {
// web3.eth.getTransactionCount(web3.eth.defaultAccount, (error, result) => {
// if (error) reject(error);
// resolve(web3.utils.toHex(result));
// });
// });
// }
// // 获取data部分的gasPrice
// const getGasPrice = () => {
// return new Promise((resolve, reject) => {
// web3.eth.getGasPrice((error, result) => {
// if (error) reject(error);
// //resolve(web3.utils.toHex(result));
// gasPrice = web3.utils.fromWei(result, "gwei");
// console.log('gasPrice ', gasPrice + 'gwei');
// if (gasPrice >= 3) result *= 1.25;
// else if (gasPrice >= 2) result *= 1.5;
// else result *= 2;
// resolve(web3.utils.toHex(result));
// });
// });
// }
// // 给tx签名,并且发送上链
// const sendTransaction = (rawTx) => {
// return new Promise((resolve, reject) => {
// let tx = new Tx(rawTx);
// // 解决 RangeError: private key length is invalid
// tx.sign(new Buffer(account.privateKey.slice(2), 'hex'));
// let serializedTx = tx.serialize();
// // 签好的tx发送到链上
// web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
// .on('transactionHash', (hash) => {
// console.log(hash);
// // resolve(hash);
// })
// .on('receipt', (receipt) => {
// console.log(receipt);
// resolve(receipt);
// })
// .on('confirmation', (confirmationNumber, receipt) => {
// });
// });
// }
// getBalance(() => {
// Promise.all([getNonce(), getGasPrice()])
// .then(values => {
// let rawTx = {
// nonce: values[0],
// to: contractAT,
// gasPrice: values[1],
// gasLimit: web3.utils.toHex(GAS_LIMIT),
// data: encodeData
// };
// gasPrice = web3.utils.fromWei(values[1], "gwei");
// return rawTx;
// })
// .then((rwaTx) => {
// return sendTransaction(rwaTx);
// })
// .then((result) => {
// returnResult(result);
// })
// .catch(e => {
// if (e) {
// console.log('evm error', e);
// dataObject.res.end(JSON.stringify(responceData.evmError));
// // 重置
// returnObject = {};
// // 保存log
// // log.saveLog(operation[2], new Date().toLocaleString(), qs.withdrawAddress, gasPrice, 0, responceData.evmError);
// return;
// }
// });
// });