-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsendTransactionToNode.js
More file actions
67 lines (60 loc) · 1.66 KB
/
sendTransactionToNode.js
File metadata and controls
67 lines (60 loc) · 1.66 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
"use strict";
var webHelper = require('./webhelper.js');
var request = require('request');
/**
* 向中继广播消息, 将由用户选择哪个中继发起跨链交易 重复三次失败就抛出错误
*/
function sendTransaction(httpType, url, header, data, callback) {
//var whileCase = true;
// var i = 0;
// while (i < 3){
if (httpType.toLowerCase() == 'post') {
webHelper.httpPost(url, header, data).then(function (res) {
callback(null, res);
}).then(function (err) {
callback(err, null);
}).catch(function (err) {
console.log(err);
callback(err, null);
});
//console.log(result);
} else {
webHelper.httpGet(url, header).then(function (err, res) {
callback(null, res);
return;
}).then(function (err) {
callback(err);
return;
}).catch(function (err) {
callback(err, null);
});
}
}
function get(url, data, callback) {
// const options = {
// url: url,
// headers: {
// "Content-Type": "application/json",
// },
// method: 'GET',
// json: true
// };
// request(options, callback);
webHelper.httpGet(url, null, callback);
}
function post(url, data, header, callback) {
var options = {
url: url,
headers: {
"Content-Type": "application/json;"
},
body: data,
method: 'POST',
json: true,
timeout: 1500
};
request(options, callback);
}
module.exports.sendTransaction = sendTransaction;
module.exports.get = get;
module.exports.post = post;