@teleportdao/bitcoin 2.0.5 → 2.0.7
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/bitcoin-interface-ordinal.d.ts +108 -108
- package/dist/bitcoin-interface-ordinal.js +140 -140
- package/dist/bitcoin-interface-teleswap.d.ts +101 -101
- package/dist/bitcoin-interface-teleswap.js +176 -176
- package/dist/bitcoin-interface-utils.d.ts +20 -20
- package/dist/bitcoin-interface-utils.js +45 -45
- package/dist/bitcoin-interface-wallet.d.ts +28 -28
- package/dist/bitcoin-interface-wallet.js +125 -125
- package/dist/bitcoin-interface.d.ts +66 -66
- package/dist/bitcoin-interface.js +119 -119
- package/dist/bitcoin-utils.d.ts +96 -96
- package/dist/bitcoin-utils.js +514 -514
- package/dist/bitcoin-wallet-base.d.ts +111 -111
- package/dist/bitcoin-wallet-base.js +258 -258
- package/dist/helper/brc20-helper.d.ts +42 -42
- package/dist/helper/brc20-helper.js +127 -127
- package/dist/helper/index.d.ts +3 -3
- package/dist/helper/index.js +29 -29
- package/dist/helper/ordinal-helper.d.ts +12 -12
- package/dist/helper/ordinal-helper.js +129 -129
- package/dist/helper/teleswap-helper.d.ts +95 -95
- package/dist/helper/teleswap-helper.js +186 -186
- package/dist/index.d.ts +12 -12
- package/dist/index.js +41 -41
- package/dist/ordinal-wallet.d.ts +495 -495
- package/dist/ordinal-wallet.js +386 -386
- package/dist/sign/index.d.ts +1 -1
- package/dist/sign/index.js +8 -8
- package/dist/sign/sign-transaction.d.ts +12 -12
- package/dist/sign/sign-transaction.js +82 -82
- package/dist/teleswap-wallet.d.ts +45 -45
- package/dist/teleswap-wallet.js +68 -68
- package/dist/transaction-builder/bitcoin-transaction-builder.d.ts +9 -9
- package/dist/transaction-builder/bitcoin-transaction-builder.js +54 -54
- package/dist/transaction-builder/index.d.ts +3 -3
- package/dist/transaction-builder/index.js +19 -19
- package/dist/transaction-builder/ordinal-transaction-builder.d.ts +63 -63
- package/dist/transaction-builder/ordinal-transaction-builder.js +125 -125
- package/dist/transaction-builder/transaction-builder.d.ts +223 -223
- package/dist/transaction-builder/transaction-builder.js +447 -447
- package/dist/type.d.ts +61 -61
- package/dist/type.js +2 -2
- package/dist/utils/networks.d.ts +5 -5
- package/dist/utils/networks.js +53 -53
- package/dist/utils/tools.d.ts +18 -18
- package/dist/utils/tools.js +74 -74
- package/package.json +4 -4
- package/src/bitcoin-interface-ordinal.ts +185 -185
- package/src/bitcoin-interface-teleswap.ts +251 -251
- package/src/bitcoin-interface-utils.ts +60 -60
- package/src/bitcoin-interface-wallet.ts +114 -114
- package/src/bitcoin-interface.ts +156 -156
- package/src/bitcoin-utils.ts +591 -591
- package/src/bitcoin-wallet-base.ts +344 -344
- package/src/helper/brc20-helper.ts +179 -179
- package/src/helper/ordinal-helper.ts +118 -118
- package/src/index.ts +15 -15
- package/src/ordinal-wallet.ts +659 -659
- package/src/sign/index.ts +1 -1
- package/src/sign/sign-transaction.ts +108 -108
- package/src/teleswap-wallet.ts +133 -133
- package/src/transaction-builder/bitcoin-transaction-builder.ts +26 -26
- package/src/transaction-builder/index.ts +3 -3
- package/src/transaction-builder/ordinal-transaction-builder.ts +139 -139
- package/src/transaction-builder/transaction-builder.ts +690 -690
- package/src/type.ts +74 -74
- package/src/utils/networks.ts +33 -33
- package/src/utils/tools.ts +92 -92
- package/tsconfig.json +9 -9
- package/webpack.config.js +16 -16
- package/.tmp/block-parser.ts +0 -58
- package/.tmp/check.ts +0 -101
- package/.tmp/ordinal-helper.ts +0 -133
- package/.tmp/ordinal.ts +0 -25
- package/.tmp/psbt/sign-transaction.ts +0 -121
- package/.tmp/rbf.ts +0 -45
package/dist/type.d.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
export type Transaction = {
|
|
2
|
-
txId: string;
|
|
3
|
-
version: number;
|
|
4
|
-
locktime: number;
|
|
5
|
-
blockNumber: number;
|
|
6
|
-
blockHash: string;
|
|
7
|
-
merkleProof?: {
|
|
8
|
-
intermediateNodes: string;
|
|
9
|
-
transactionIndex: number;
|
|
10
|
-
};
|
|
11
|
-
vout: {
|
|
12
|
-
address?: string;
|
|
13
|
-
script: string;
|
|
14
|
-
value: number;
|
|
15
|
-
}[];
|
|
16
|
-
vin: {
|
|
17
|
-
txId: string;
|
|
18
|
-
index: number;
|
|
19
|
-
address?: string;
|
|
20
|
-
script?: string;
|
|
21
|
-
value?: number;
|
|
22
|
-
}[];
|
|
23
|
-
address: string;
|
|
24
|
-
addressScript: string;
|
|
25
|
-
};
|
|
26
|
-
export type UtxoConnectionInfo = {
|
|
27
|
-
token?: string;
|
|
28
|
-
provider: "BlockStream" | "MempoolSpace" | "NowNodes" | "Unisat" | "TeleportDao";
|
|
29
|
-
};
|
|
30
|
-
export type BTCTokenConnectionInfo = {
|
|
31
|
-
token?: string;
|
|
32
|
-
provider: "Unisat" | "TeleportDao";
|
|
33
|
-
};
|
|
34
|
-
export type APIConnectionInfo = {
|
|
35
|
-
provider: "BlockStream" | "MempoolSpace";
|
|
36
|
-
};
|
|
37
|
-
export type RPCConnectionInfo = {
|
|
38
|
-
url: string;
|
|
39
|
-
headers?: {
|
|
40
|
-
[key: string]: string;
|
|
41
|
-
};
|
|
42
|
-
auth?: {
|
|
43
|
-
username: string;
|
|
44
|
-
password: string;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
export type BitcoinWalletConnectionInfo = {
|
|
48
|
-
utxo?: UtxoConnectionInfo;
|
|
49
|
-
rpc?: RPCConnectionInfo;
|
|
50
|
-
};
|
|
51
|
-
export type BitcoinWalletInterfaceConnectionInfo = {
|
|
52
|
-
api?: APIConnectionInfo;
|
|
53
|
-
utxo?: UtxoConnectionInfo;
|
|
54
|
-
};
|
|
55
|
-
export type BitcoinInterfaceConnectionInfo = BitcoinWalletInterfaceConnectionInfo & {
|
|
56
|
-
rpc?: RPCConnectionInfo;
|
|
57
|
-
};
|
|
58
|
-
export type BitcoinNodeConnectionInfo = BitcoinWalletInterfaceConnectionInfo & {
|
|
59
|
-
rpc: RPCConnectionInfo;
|
|
60
|
-
};
|
|
61
|
-
export type BitcoinTokenNodeConnectionInfo = BitcoinNodeConnectionInfo & {};
|
|
1
|
+
export type Transaction = {
|
|
2
|
+
txId: string;
|
|
3
|
+
version: number;
|
|
4
|
+
locktime: number;
|
|
5
|
+
blockNumber: number;
|
|
6
|
+
blockHash: string;
|
|
7
|
+
merkleProof?: {
|
|
8
|
+
intermediateNodes: string;
|
|
9
|
+
transactionIndex: number;
|
|
10
|
+
};
|
|
11
|
+
vout: {
|
|
12
|
+
address?: string;
|
|
13
|
+
script: string;
|
|
14
|
+
value: number;
|
|
15
|
+
}[];
|
|
16
|
+
vin: {
|
|
17
|
+
txId: string;
|
|
18
|
+
index: number;
|
|
19
|
+
address?: string;
|
|
20
|
+
script?: string;
|
|
21
|
+
value?: number;
|
|
22
|
+
}[];
|
|
23
|
+
address: string;
|
|
24
|
+
addressScript: string;
|
|
25
|
+
};
|
|
26
|
+
export type UtxoConnectionInfo = {
|
|
27
|
+
token?: string;
|
|
28
|
+
provider: "BlockStream" | "MempoolSpace" | "NowNodes" | "Unisat" | "TeleportDao";
|
|
29
|
+
};
|
|
30
|
+
export type BTCTokenConnectionInfo = {
|
|
31
|
+
token?: string;
|
|
32
|
+
provider: "Unisat" | "TeleportDao";
|
|
33
|
+
};
|
|
34
|
+
export type APIConnectionInfo = {
|
|
35
|
+
provider: "BlockStream" | "MempoolSpace";
|
|
36
|
+
};
|
|
37
|
+
export type RPCConnectionInfo = {
|
|
38
|
+
url: string;
|
|
39
|
+
headers?: {
|
|
40
|
+
[key: string]: string;
|
|
41
|
+
};
|
|
42
|
+
auth?: {
|
|
43
|
+
username: string;
|
|
44
|
+
password: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type BitcoinWalletConnectionInfo = {
|
|
48
|
+
utxo?: UtxoConnectionInfo;
|
|
49
|
+
rpc?: RPCConnectionInfo;
|
|
50
|
+
};
|
|
51
|
+
export type BitcoinWalletInterfaceConnectionInfo = {
|
|
52
|
+
api?: APIConnectionInfo;
|
|
53
|
+
utxo?: UtxoConnectionInfo;
|
|
54
|
+
};
|
|
55
|
+
export type BitcoinInterfaceConnectionInfo = BitcoinWalletInterfaceConnectionInfo & {
|
|
56
|
+
rpc?: RPCConnectionInfo;
|
|
57
|
+
};
|
|
58
|
+
export type BitcoinNodeConnectionInfo = BitcoinWalletInterfaceConnectionInfo & {
|
|
59
|
+
rpc: RPCConnectionInfo;
|
|
60
|
+
};
|
|
61
|
+
export type BitcoinTokenNodeConnectionInfo = BitcoinNodeConnectionInfo & {};
|
|
62
62
|
//# sourceMappingURL=type.d.ts.map
|
package/dist/type.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=type.js.map
|
package/dist/utils/networks.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as bitcoinLib from "bitcoinjs-lib";
|
|
2
|
-
declare const networks: {
|
|
3
|
-
[key: string]: bitcoinLib.Network;
|
|
4
|
-
};
|
|
5
|
-
export default networks;
|
|
1
|
+
import * as bitcoinLib from "bitcoinjs-lib";
|
|
2
|
+
declare const networks: {
|
|
3
|
+
[key: string]: bitcoinLib.Network;
|
|
4
|
+
};
|
|
5
|
+
export default networks;
|
|
6
6
|
//# sourceMappingURL=networks.d.ts.map
|
package/dist/utils/networks.js
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
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 (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const bitcoinLib = __importStar(require("bitcoinjs-lib"));
|
|
27
|
-
const networks = {
|
|
28
|
-
bitcoin: bitcoinLib.networks.bitcoin,
|
|
29
|
-
bitcoin_testnet: bitcoinLib.networks.testnet,
|
|
30
|
-
litecoin: {
|
|
31
|
-
messagePrefix: "\x19Litecoin Signed Message:\n",
|
|
32
|
-
bech32: "ltc",
|
|
33
|
-
bip32: {
|
|
34
|
-
public: 0x0488b21e,
|
|
35
|
-
private: 0x0488ade4,
|
|
36
|
-
},
|
|
37
|
-
pubKeyHash: 0x30,
|
|
38
|
-
scriptHash: 0x32,
|
|
39
|
-
wif: 0xb0,
|
|
40
|
-
},
|
|
41
|
-
litecoin_testnet: {
|
|
42
|
-
messagePrefix: "\x18Litecoin Signed Message:\n",
|
|
43
|
-
bech32: "tltc",
|
|
44
|
-
bip32: {
|
|
45
|
-
public: 0x043587cf,
|
|
46
|
-
private: 0x04358394,
|
|
47
|
-
},
|
|
48
|
-
pubKeyHash: 0x6f,
|
|
49
|
-
scriptHash: 0x3a,
|
|
50
|
-
wif: 0xef,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
exports.default = networks;
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const bitcoinLib = __importStar(require("bitcoinjs-lib"));
|
|
27
|
+
const networks = {
|
|
28
|
+
bitcoin: bitcoinLib.networks.bitcoin,
|
|
29
|
+
bitcoin_testnet: bitcoinLib.networks.testnet,
|
|
30
|
+
litecoin: {
|
|
31
|
+
messagePrefix: "\x19Litecoin Signed Message:\n",
|
|
32
|
+
bech32: "ltc",
|
|
33
|
+
bip32: {
|
|
34
|
+
public: 0x0488b21e,
|
|
35
|
+
private: 0x0488ade4,
|
|
36
|
+
},
|
|
37
|
+
pubKeyHash: 0x30,
|
|
38
|
+
scriptHash: 0x32,
|
|
39
|
+
wif: 0xb0,
|
|
40
|
+
},
|
|
41
|
+
litecoin_testnet: {
|
|
42
|
+
messagePrefix: "\x18Litecoin Signed Message:\n",
|
|
43
|
+
bech32: "tltc",
|
|
44
|
+
bip32: {
|
|
45
|
+
public: 0x043587cf,
|
|
46
|
+
private: 0x04358394,
|
|
47
|
+
},
|
|
48
|
+
pubKeyHash: 0x6f,
|
|
49
|
+
scriptHash: 0x3a,
|
|
50
|
+
wif: 0xef,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
exports.default = networks;
|
|
54
54
|
//# sourceMappingURL=networks.js.map
|
package/dist/utils/tools.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
declare function sleep(ms: number): Promise<unknown>;
|
|
2
|
-
declare function runWithRetries<T>(action: () => Promise<T>, config?: {
|
|
3
|
-
maxTries?: number;
|
|
4
|
-
retrySleep?: number;
|
|
5
|
-
}): Promise<T>;
|
|
6
|
-
declare function getRandomInteger(min: number, max: number): number;
|
|
7
|
-
declare function getAxiosInstance({ baseUrl, timeout, headers, auth, }: {
|
|
8
|
-
baseUrl: string;
|
|
9
|
-
timeout?: number;
|
|
10
|
-
headers?: {
|
|
11
|
-
[key: string]: string;
|
|
12
|
-
};
|
|
13
|
-
auth?: {
|
|
14
|
-
username: string;
|
|
15
|
-
password: string;
|
|
16
|
-
};
|
|
17
|
-
}): import("axios").AxiosInstance;
|
|
18
|
-
export { sleep, runWithRetries, getRandomInteger, getAxiosInstance };
|
|
1
|
+
declare function sleep(ms: number): Promise<unknown>;
|
|
2
|
+
declare function runWithRetries<T>(action: () => Promise<T>, config?: {
|
|
3
|
+
maxTries?: number;
|
|
4
|
+
retrySleep?: number;
|
|
5
|
+
}): Promise<T>;
|
|
6
|
+
declare function getRandomInteger(min: number, max: number): number;
|
|
7
|
+
declare function getAxiosInstance({ baseUrl, timeout, headers, auth, }: {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
headers?: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
};
|
|
13
|
+
auth?: {
|
|
14
|
+
username: string;
|
|
15
|
+
password: string;
|
|
16
|
+
};
|
|
17
|
+
}): import("axios").AxiosInstance;
|
|
18
|
+
export { sleep, runWithRetries, getRandomInteger, getAxiosInstance };
|
|
19
19
|
//# sourceMappingURL=tools.d.ts.map
|
package/dist/utils/tools.js
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getAxiosInstance = exports.getRandomInteger = exports.runWithRetries = exports.sleep = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
function sleep(ms) {
|
|
18
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
19
|
-
}
|
|
20
|
-
exports.sleep = sleep;
|
|
21
|
-
function runWithRetries(action, config = {
|
|
22
|
-
maxTries: 2,
|
|
23
|
-
retrySleep: 1000,
|
|
24
|
-
}) {
|
|
25
|
-
var _a, _b, _c;
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const maxTries = (_a = config.maxTries) !== null && _a !== void 0 ? _a : 2;
|
|
28
|
-
const retrySleep = (_b = config.retrySleep) !== null && _b !== void 0 ? _b : 1000;
|
|
29
|
-
const trace = (_c = new Error().stack) === null || _c === void 0 ? void 0 : _c.split("\n").slice(5).join("\n");
|
|
30
|
-
let lastError;
|
|
31
|
-
for (let count = 0; count < maxTries; count += 1) {
|
|
32
|
-
try {
|
|
33
|
-
return yield action();
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
error.message += `\n${trace}`;
|
|
37
|
-
console.log(`Attempt ${count + 1} failed: ${error.message}`);
|
|
38
|
-
lastError = error;
|
|
39
|
-
if (count < maxTries - 1) {
|
|
40
|
-
yield sleep(retrySleep);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
throw lastError || new Error(`Function failed after ${maxTries} retries: ${lastError === null || lastError === void 0 ? void 0 : lastError.message}`);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
exports.runWithRetries = runWithRetries;
|
|
48
|
-
function getRandomInteger(min, max) {
|
|
49
|
-
return Math.floor(Math.random() * (max - min)) + min;
|
|
50
|
-
}
|
|
51
|
-
exports.getRandomInteger = getRandomInteger;
|
|
52
|
-
function getAxiosInstance({ baseUrl, timeout = 10000, headers = {}, auth, }) {
|
|
53
|
-
let host = baseUrl;
|
|
54
|
-
let instance;
|
|
55
|
-
instance = axios_1.default.create({
|
|
56
|
-
baseURL: host,
|
|
57
|
-
timeout,
|
|
58
|
-
auth,
|
|
59
|
-
headers: Object.assign({}, headers),
|
|
60
|
-
});
|
|
61
|
-
instance.interceptors.response.use((response) => response, (error) => {
|
|
62
|
-
if (error.response) {
|
|
63
|
-
const serviceError = new Error(JSON.stringify({ data: error.response.data, message: error.message }));
|
|
64
|
-
return Promise.reject(serviceError);
|
|
65
|
-
}
|
|
66
|
-
if (error.request) {
|
|
67
|
-
const serviceError = new Error(error.message);
|
|
68
|
-
return Promise.reject(serviceError);
|
|
69
|
-
}
|
|
70
|
-
return Promise.reject(error);
|
|
71
|
-
});
|
|
72
|
-
return instance;
|
|
73
|
-
}
|
|
74
|
-
exports.getAxiosInstance = getAxiosInstance;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getAxiosInstance = exports.getRandomInteger = exports.runWithRetries = exports.sleep = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
function sleep(ms) {
|
|
18
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
19
|
+
}
|
|
20
|
+
exports.sleep = sleep;
|
|
21
|
+
function runWithRetries(action, config = {
|
|
22
|
+
maxTries: 2,
|
|
23
|
+
retrySleep: 1000,
|
|
24
|
+
}) {
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const maxTries = (_a = config.maxTries) !== null && _a !== void 0 ? _a : 2;
|
|
28
|
+
const retrySleep = (_b = config.retrySleep) !== null && _b !== void 0 ? _b : 1000;
|
|
29
|
+
const trace = (_c = new Error().stack) === null || _c === void 0 ? void 0 : _c.split("\n").slice(5).join("\n");
|
|
30
|
+
let lastError;
|
|
31
|
+
for (let count = 0; count < maxTries; count += 1) {
|
|
32
|
+
try {
|
|
33
|
+
return yield action();
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
error.message += `\n${trace}`;
|
|
37
|
+
console.log(`Attempt ${count + 1} failed: ${error.message}`);
|
|
38
|
+
lastError = error;
|
|
39
|
+
if (count < maxTries - 1) {
|
|
40
|
+
yield sleep(retrySleep);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw lastError || new Error(`Function failed after ${maxTries} retries: ${lastError === null || lastError === void 0 ? void 0 : lastError.message}`);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.runWithRetries = runWithRetries;
|
|
48
|
+
function getRandomInteger(min, max) {
|
|
49
|
+
return Math.floor(Math.random() * (max - min)) + min;
|
|
50
|
+
}
|
|
51
|
+
exports.getRandomInteger = getRandomInteger;
|
|
52
|
+
function getAxiosInstance({ baseUrl, timeout = 10000, headers = {}, auth, }) {
|
|
53
|
+
let host = baseUrl;
|
|
54
|
+
let instance;
|
|
55
|
+
instance = axios_1.default.create({
|
|
56
|
+
baseURL: host,
|
|
57
|
+
timeout,
|
|
58
|
+
auth,
|
|
59
|
+
headers: Object.assign({}, headers),
|
|
60
|
+
});
|
|
61
|
+
instance.interceptors.response.use((response) => response, (error) => {
|
|
62
|
+
if (error.response) {
|
|
63
|
+
const serviceError = new Error(JSON.stringify({ data: error.response.data, message: error.message }));
|
|
64
|
+
return Promise.reject(serviceError);
|
|
65
|
+
}
|
|
66
|
+
if (error.request) {
|
|
67
|
+
const serviceError = new Error(error.message);
|
|
68
|
+
return Promise.reject(serviceError);
|
|
69
|
+
}
|
|
70
|
+
return Promise.reject(error);
|
|
71
|
+
});
|
|
72
|
+
return instance;
|
|
73
|
+
}
|
|
74
|
+
exports.getAxiosInstance = getAxiosInstance;
|
|
75
75
|
//# sourceMappingURL=tools.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teleportdao/bitcoin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "teleswap bitcoin package",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@bitcoinerlab/secp256k1": "^1.0.5",
|
|
17
|
-
"@teleportdao/configs": "^2.0.
|
|
18
|
-
"@teleportdao/providers": "^2.0.
|
|
17
|
+
"@teleportdao/configs": "^2.0.7",
|
|
18
|
+
"@teleportdao/providers": "^2.0.6",
|
|
19
19
|
"axios": "^0.27.2",
|
|
20
20
|
"bignumber.js": "^9.1.1",
|
|
21
21
|
"bip32": "^4.0.0",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "a9ffe19bd4d8e3b104b6cb7c00d1d49f39547119"
|
|
35
35
|
}
|