@clonegod/ttd-core 2.1.17 → 2.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/token/cache_token_config.js +1 -1
- package/dist/util/httputil.d.ts +6 -0
- package/dist/util/httputil.js +134 -0
- package/dist/util/index.d.ts +2 -0
- package/dist/util/index.js +2 -0
- package/dist/util/ip_util.d.ts +3 -0
- package/dist/util/ip_util.js +92 -0
- package/package.json +1 -1
|
@@ -35,7 +35,7 @@ const cache_token_config = (chain_id, valid_tokens_map) => __awaiter(void 0, voi
|
|
|
35
35
|
address_hex: '',
|
|
36
36
|
decimals: token.decimals,
|
|
37
37
|
name: token.name,
|
|
38
|
-
is_token2022:
|
|
38
|
+
is_token2022: token.is_token_2022,
|
|
39
39
|
market_price: token.price,
|
|
40
40
|
update_time: (0, index_1.getCurDateTime)(),
|
|
41
41
|
alias: (0, index_1.get_token_symbol_alias)(token.address),
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
export declare function simplifyAxiosError(error: any): string;
|
|
3
|
+
export declare class HttpUtil {
|
|
4
|
+
static get(url: string, config?: AxiosRequestConfig): Promise<any>;
|
|
5
|
+
static post(url: string, data?: any, config?: AxiosRequestConfig): Promise<any>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.HttpUtil = void 0;
|
|
49
|
+
exports.simplifyAxiosError = simplifyAxiosError;
|
|
50
|
+
const axios_1 = __importDefault(require("axios"));
|
|
51
|
+
const http = __importStar(require("http"));
|
|
52
|
+
const https = __importStar(require("https"));
|
|
53
|
+
const ip_util_1 = require("./ip_util");
|
|
54
|
+
function simplifyAxiosError(error) {
|
|
55
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
56
|
+
if (error.response) {
|
|
57
|
+
return `HTTP ${error.response.status}: ${error.response.statusText || 'Unknown'}`;
|
|
58
|
+
}
|
|
59
|
+
else if (error.request) {
|
|
60
|
+
return `No response from server (timeout or network error)`;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return error.message || 'Request setup error';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (error instanceof Error) {
|
|
67
|
+
return error.message;
|
|
68
|
+
}
|
|
69
|
+
return 'Unknown error';
|
|
70
|
+
}
|
|
71
|
+
function createHttpAgent(ip) {
|
|
72
|
+
return new http.Agent({
|
|
73
|
+
family: 4,
|
|
74
|
+
localAddress: ip
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function createHttpsAgent(ip) {
|
|
78
|
+
return new https.Agent({
|
|
79
|
+
family: 4,
|
|
80
|
+
localAddress: ip
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function createAxiosInstance() {
|
|
84
|
+
const instance = axios_1.default.create();
|
|
85
|
+
instance.interceptors.request.use((config) => {
|
|
86
|
+
if (config.httpAgent || config.httpsAgent) {
|
|
87
|
+
return config;
|
|
88
|
+
}
|
|
89
|
+
const ip = (0, ip_util_1.getNextIP)();
|
|
90
|
+
if (ip) {
|
|
91
|
+
const url = config.url || '';
|
|
92
|
+
const baseURL = config.baseURL || '';
|
|
93
|
+
const fullUrl = url.startsWith('http') ? url : (baseURL + url);
|
|
94
|
+
const isHttps = fullUrl.startsWith('https:');
|
|
95
|
+
if (isHttps) {
|
|
96
|
+
config.httpsAgent = createHttpsAgent(ip);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
config.httpAgent = createHttpAgent(ip);
|
|
100
|
+
}
|
|
101
|
+
console.log(`[HttpUtil] Using IP: ${ip} for ${fullUrl}`);
|
|
102
|
+
}
|
|
103
|
+
return config;
|
|
104
|
+
});
|
|
105
|
+
instance.interceptors.response.use((response) => response, (error) => {
|
|
106
|
+
var _a;
|
|
107
|
+
const simplifiedError = simplifyAxiosError(error);
|
|
108
|
+
const url = ((_a = error.config) === null || _a === void 0 ? void 0 : _a.url) || 'unknown url';
|
|
109
|
+
console.error(`[HttpUtil] Request failed for ${url}:`, simplifiedError);
|
|
110
|
+
const simplifiedAxiosError = new Error(simplifiedError);
|
|
111
|
+
simplifiedAxiosError.isAxiosError = true;
|
|
112
|
+
simplifiedAxiosError.config = error.config;
|
|
113
|
+
simplifiedAxiosError.response = error.response;
|
|
114
|
+
simplifiedAxiosError.request = error.request;
|
|
115
|
+
return Promise.reject(simplifiedAxiosError);
|
|
116
|
+
});
|
|
117
|
+
return instance;
|
|
118
|
+
}
|
|
119
|
+
const axiosInstance = createAxiosInstance();
|
|
120
|
+
class HttpUtil {
|
|
121
|
+
static get(url, config) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
const response = yield axiosInstance.get(url, config);
|
|
124
|
+
return response.data;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
static post(url, data, config) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const response = yield axiosInstance.post(url, data, config);
|
|
130
|
+
return response.data;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.HttpUtil = HttpUtil;
|
package/dist/util/index.d.ts
CHANGED
package/dist/util/index.js
CHANGED
|
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./fileutil"), exports);
|
|
18
|
+
__exportStar(require("./httputil"), exports);
|
|
19
|
+
__exportStar(require("./ip_util"), exports);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getServerIpList = getServerIpList;
|
|
37
|
+
exports.getNextIP = getNextIP;
|
|
38
|
+
exports.getCurrentIpList = getCurrentIpList;
|
|
39
|
+
require('dotenv').config();
|
|
40
|
+
const os = __importStar(require("os"));
|
|
41
|
+
let IP_LIST = getServerIpList();
|
|
42
|
+
let ip_counter = 0;
|
|
43
|
+
function getProxyIpFromEnv() {
|
|
44
|
+
if (process.env.PROXY_IP_LIST || process.env.BIND_IP_LIST) {
|
|
45
|
+
const ipList = (process.env.PROXY_IP_LIST || process.env.BIND_IP_LIST || '').split(',')
|
|
46
|
+
.map(ip => ip.trim())
|
|
47
|
+
.filter(ip => ip.length > 0);
|
|
48
|
+
if (ipList.length > 0) {
|
|
49
|
+
return ipList;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
function getProxyIpFromLocal() {
|
|
55
|
+
const exclude_ip_prefix_arr = (process.env.IP_PREFIX_EXCLUDE || '192.168').split(',').map(p => p.trim());
|
|
56
|
+
const ips = [];
|
|
57
|
+
const interfaces = os.networkInterfaces();
|
|
58
|
+
for (const devName in interfaces) {
|
|
59
|
+
const iface = interfaces[devName] || [];
|
|
60
|
+
for (const alias of iface) {
|
|
61
|
+
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
|
|
62
|
+
const is_invalid = exclude_ip_prefix_arr.some(prefix => alias.address.startsWith(prefix));
|
|
63
|
+
if (!is_invalid) {
|
|
64
|
+
ips.push(alias.address);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return ips;
|
|
70
|
+
}
|
|
71
|
+
function getServerIpList() {
|
|
72
|
+
const envIps = getProxyIpFromEnv();
|
|
73
|
+
if (envIps.length > 0) {
|
|
74
|
+
return envIps;
|
|
75
|
+
}
|
|
76
|
+
return getProxyIpFromLocal();
|
|
77
|
+
}
|
|
78
|
+
function getNextIP() {
|
|
79
|
+
try {
|
|
80
|
+
if (IP_LIST.length === 0) {
|
|
81
|
+
IP_LIST = getServerIpList();
|
|
82
|
+
}
|
|
83
|
+
return IP_LIST[ip_counter++ % IP_LIST.length];
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
console.error('[IpUtil] getNextIP error!!!', err);
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function getCurrentIpList() {
|
|
91
|
+
return [...IP_LIST];
|
|
92
|
+
}
|