@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
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { bitcoin } from "@teleportdao/providers";
|
|
2
|
-
import { UnwrapInfo, WrapOpReturnWithType } from "./helper/teleswap-helper";
|
|
3
|
-
import BitcoinInterface from "./bitcoin-interface";
|
|
4
|
-
import { BitcoinNodeConnectionInfo, Transaction } from "./type";
|
|
5
|
-
export type ValidWrapRequest = {
|
|
6
|
-
transaction: bitcoin.Types.ConfirmedTransaction & {
|
|
7
|
-
address?: string;
|
|
8
|
-
addressScript?: string;
|
|
9
|
-
merkleProof?: Transaction["merkleProof"];
|
|
10
|
-
};
|
|
11
|
-
request: {
|
|
12
|
-
status: boolean;
|
|
13
|
-
data: WrapOpReturnWithType;
|
|
14
|
-
value: number;
|
|
15
|
-
valueOutputIndex: number;
|
|
16
|
-
};
|
|
17
|
-
lockerAddress: string;
|
|
18
|
-
lockerLockingScript: string;
|
|
19
|
-
};
|
|
20
|
-
export type InValidWrapRequest = {
|
|
21
|
-
transaction: bitcoin.Types.ConfirmedTransaction & {
|
|
22
|
-
address?: string;
|
|
23
|
-
addressScript?: string;
|
|
24
|
-
merkleProof?: Transaction["merkleProof"];
|
|
25
|
-
};
|
|
26
|
-
request: {
|
|
27
|
-
status: boolean;
|
|
28
|
-
message: string;
|
|
29
|
-
code: string;
|
|
30
|
-
};
|
|
31
|
-
lockerAddress: string;
|
|
32
|
-
lockerLockingScript: string;
|
|
33
|
-
};
|
|
34
|
-
export type UnwrapRequest = {
|
|
35
|
-
burnInfo: UnwrapInfo | undefined;
|
|
36
|
-
lockerAddress: string;
|
|
37
|
-
lockerLockingScript: string;
|
|
38
|
-
};
|
|
39
|
-
export declare class BitcoinInterfaceTeleswap extends BitcoinInterface {
|
|
40
|
-
constructor(connectionInfo: BitcoinNodeConnectionInfo, networkName: string);
|
|
41
|
-
getHexBlockHeaders(startBlockNumber: number, endBlockNumber: number): Promise<{
|
|
42
|
-
hexBlockHeaders: string;
|
|
43
|
-
fromBlockNumber: number;
|
|
44
|
-
toBlockNumber: number;
|
|
45
|
-
difficulty: string | null;
|
|
46
|
-
}[]>;
|
|
47
|
-
getWrapRequests(addresses: string[], startblockNumber: number, endBlockNumber: number): Promise<{
|
|
48
|
-
requests: ValidWrapRequest[];
|
|
49
|
-
invalidRequests: InValidWrapRequest[];
|
|
50
|
-
}>;
|
|
51
|
-
getWrapRequestByTx(inputTransaction: {
|
|
52
|
-
txId: string;
|
|
53
|
-
} | (bitcoin.Types.ConfirmedTransaction & {
|
|
54
|
-
address?: string;
|
|
55
|
-
addressScript?: string;
|
|
56
|
-
merkleProof?: Transaction["merkleProof"];
|
|
57
|
-
}), lockerAddress: string): Promise<{
|
|
58
|
-
transaction: bitcoin.Types.ConfirmedTransaction & {
|
|
59
|
-
address?: string | undefined;
|
|
60
|
-
addressScript?: string | undefined;
|
|
61
|
-
merkleProof?: Transaction["merkleProof"];
|
|
62
|
-
};
|
|
63
|
-
request: {
|
|
64
|
-
status: boolean;
|
|
65
|
-
message: string;
|
|
66
|
-
code: string;
|
|
67
|
-
data?: undefined;
|
|
68
|
-
value?: undefined;
|
|
69
|
-
valueOutputIndex?: undefined;
|
|
70
|
-
requestOutputIndex?: undefined;
|
|
71
|
-
} | {
|
|
72
|
-
status: true;
|
|
73
|
-
data: WrapOpReturnWithType;
|
|
74
|
-
value: number;
|
|
75
|
-
valueOutputIndex: number;
|
|
76
|
-
requestOutputIndex: number;
|
|
77
|
-
message?: undefined;
|
|
78
|
-
code?: undefined;
|
|
79
|
-
};
|
|
80
|
-
lockerAddress: string;
|
|
81
|
-
lockerLockingScript: string;
|
|
82
|
-
}>;
|
|
83
|
-
getLockersUnWrapTransactions(addresses: string[], startBlockNumber: number, endBlockNumber: number): Promise<{
|
|
84
|
-
transaction: Transaction;
|
|
85
|
-
burnInfo: UnwrapInfo | undefined;
|
|
86
|
-
lockerAddress: string;
|
|
87
|
-
lockerLockingScript: string;
|
|
88
|
-
}[]>;
|
|
89
|
-
getLockersUnwrapMEmpoolTransactions(addresses: string[], startBlockNumber: number, endBlockNumber: number): Promise<{
|
|
90
|
-
transaction: Transaction;
|
|
91
|
-
burnInfo: UnwrapInfo | undefined;
|
|
92
|
-
lockerAddress: string;
|
|
93
|
-
lockerLockingScript: string;
|
|
94
|
-
}[]>;
|
|
95
|
-
getTransactionUnwrapInfoByTx(transaction: {
|
|
96
|
-
txId: any;
|
|
97
|
-
vout?: any;
|
|
98
|
-
vin?: any;
|
|
99
|
-
addressScript?: any;
|
|
100
|
-
}, lockerAddress: string): Promise<UnwrapRequest | undefined>;
|
|
101
|
-
}
|
|
1
|
+
import { bitcoin } from "@teleportdao/providers";
|
|
2
|
+
import { UnwrapInfo, WrapOpReturnWithType } from "./helper/teleswap-helper";
|
|
3
|
+
import BitcoinInterface from "./bitcoin-interface";
|
|
4
|
+
import { BitcoinNodeConnectionInfo, Transaction } from "./type";
|
|
5
|
+
export type ValidWrapRequest = {
|
|
6
|
+
transaction: bitcoin.Types.ConfirmedTransaction & {
|
|
7
|
+
address?: string;
|
|
8
|
+
addressScript?: string;
|
|
9
|
+
merkleProof?: Transaction["merkleProof"];
|
|
10
|
+
};
|
|
11
|
+
request: {
|
|
12
|
+
status: boolean;
|
|
13
|
+
data: WrapOpReturnWithType;
|
|
14
|
+
value: number;
|
|
15
|
+
valueOutputIndex: number;
|
|
16
|
+
};
|
|
17
|
+
lockerAddress: string;
|
|
18
|
+
lockerLockingScript: string;
|
|
19
|
+
};
|
|
20
|
+
export type InValidWrapRequest = {
|
|
21
|
+
transaction: bitcoin.Types.ConfirmedTransaction & {
|
|
22
|
+
address?: string;
|
|
23
|
+
addressScript?: string;
|
|
24
|
+
merkleProof?: Transaction["merkleProof"];
|
|
25
|
+
};
|
|
26
|
+
request: {
|
|
27
|
+
status: boolean;
|
|
28
|
+
message: string;
|
|
29
|
+
code: string;
|
|
30
|
+
};
|
|
31
|
+
lockerAddress: string;
|
|
32
|
+
lockerLockingScript: string;
|
|
33
|
+
};
|
|
34
|
+
export type UnwrapRequest = {
|
|
35
|
+
burnInfo: UnwrapInfo | undefined;
|
|
36
|
+
lockerAddress: string;
|
|
37
|
+
lockerLockingScript: string;
|
|
38
|
+
};
|
|
39
|
+
export declare class BitcoinInterfaceTeleswap extends BitcoinInterface {
|
|
40
|
+
constructor(connectionInfo: BitcoinNodeConnectionInfo, networkName: string);
|
|
41
|
+
getHexBlockHeaders(startBlockNumber: number, endBlockNumber: number): Promise<{
|
|
42
|
+
hexBlockHeaders: string;
|
|
43
|
+
fromBlockNumber: number;
|
|
44
|
+
toBlockNumber: number;
|
|
45
|
+
difficulty: string | null;
|
|
46
|
+
}[]>;
|
|
47
|
+
getWrapRequests(addresses: string[], startblockNumber: number, endBlockNumber: number): Promise<{
|
|
48
|
+
requests: ValidWrapRequest[];
|
|
49
|
+
invalidRequests: InValidWrapRequest[];
|
|
50
|
+
}>;
|
|
51
|
+
getWrapRequestByTx(inputTransaction: {
|
|
52
|
+
txId: string;
|
|
53
|
+
} | (bitcoin.Types.ConfirmedTransaction & {
|
|
54
|
+
address?: string;
|
|
55
|
+
addressScript?: string;
|
|
56
|
+
merkleProof?: Transaction["merkleProof"];
|
|
57
|
+
}), lockerAddress: string): Promise<{
|
|
58
|
+
transaction: bitcoin.Types.ConfirmedTransaction & {
|
|
59
|
+
address?: string | undefined;
|
|
60
|
+
addressScript?: string | undefined;
|
|
61
|
+
merkleProof?: Transaction["merkleProof"];
|
|
62
|
+
};
|
|
63
|
+
request: {
|
|
64
|
+
status: boolean;
|
|
65
|
+
message: string;
|
|
66
|
+
code: string;
|
|
67
|
+
data?: undefined;
|
|
68
|
+
value?: undefined;
|
|
69
|
+
valueOutputIndex?: undefined;
|
|
70
|
+
requestOutputIndex?: undefined;
|
|
71
|
+
} | {
|
|
72
|
+
status: true;
|
|
73
|
+
data: WrapOpReturnWithType;
|
|
74
|
+
value: number;
|
|
75
|
+
valueOutputIndex: number;
|
|
76
|
+
requestOutputIndex: number;
|
|
77
|
+
message?: undefined;
|
|
78
|
+
code?: undefined;
|
|
79
|
+
};
|
|
80
|
+
lockerAddress: string;
|
|
81
|
+
lockerLockingScript: string;
|
|
82
|
+
}>;
|
|
83
|
+
getLockersUnWrapTransactions(addresses: string[], startBlockNumber: number, endBlockNumber: number): Promise<{
|
|
84
|
+
transaction: Transaction;
|
|
85
|
+
burnInfo: UnwrapInfo | undefined;
|
|
86
|
+
lockerAddress: string;
|
|
87
|
+
lockerLockingScript: string;
|
|
88
|
+
}[]>;
|
|
89
|
+
getLockersUnwrapMEmpoolTransactions(addresses: string[], startBlockNumber: number, endBlockNumber: number): Promise<{
|
|
90
|
+
transaction: Transaction;
|
|
91
|
+
burnInfo: UnwrapInfo | undefined;
|
|
92
|
+
lockerAddress: string;
|
|
93
|
+
lockerLockingScript: string;
|
|
94
|
+
}[]>;
|
|
95
|
+
getTransactionUnwrapInfoByTx(transaction: {
|
|
96
|
+
txId: any;
|
|
97
|
+
vout?: any;
|
|
98
|
+
vin?: any;
|
|
99
|
+
addressScript?: any;
|
|
100
|
+
}, lockerAddress: string): Promise<UnwrapRequest | undefined>;
|
|
101
|
+
}
|
|
102
102
|
//# sourceMappingURL=bitcoin-interface-teleswap.d.ts.map
|
|
@@ -1,177 +1,177 @@
|
|
|
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.BitcoinInterfaceTeleswap = void 0;
|
|
16
|
-
const configs_1 = require("@teleportdao/configs");
|
|
17
|
-
const bitcoin_utils_1 = require("./bitcoin-utils");
|
|
18
|
-
const teleswap_helper_1 = require("./helper/teleswap-helper");
|
|
19
|
-
const bitcoin_interface_1 = __importDefault(require("./bitcoin-interface"));
|
|
20
|
-
class BitcoinInterfaceTeleswap extends bitcoin_interface_1.default {
|
|
21
|
-
constructor(connectionInfo, networkName) {
|
|
22
|
-
if (!connectionInfo.rpc) {
|
|
23
|
-
throw new Error("rpc provider is required");
|
|
24
|
-
}
|
|
25
|
-
super(networkName, connectionInfo);
|
|
26
|
-
}
|
|
27
|
-
getHexBlockHeaders(startBlockNumber, endBlockNumber) {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const blockHeaders = [];
|
|
30
|
-
let difficulty = null;
|
|
31
|
-
let hexBlockHeaders = "";
|
|
32
|
-
let fromBlockNumber = startBlockNumber;
|
|
33
|
-
for (let blockNumber = startBlockNumber; blockNumber <= endBlockNumber; blockNumber += 1) {
|
|
34
|
-
let blockHeader = yield this.getBlockHeaderHex(blockNumber);
|
|
35
|
-
console.log("block", blockNumber);
|
|
36
|
-
let parsedBlockHeader = (0, bitcoin_utils_1.parseBlockHeader)(blockHeader);
|
|
37
|
-
if (difficulty && parsedBlockHeader.difficulty !== difficulty) {
|
|
38
|
-
blockHeaders.push({
|
|
39
|
-
hexBlockHeaders,
|
|
40
|
-
fromBlockNumber,
|
|
41
|
-
toBlockNumber: blockNumber - 1,
|
|
42
|
-
difficulty,
|
|
43
|
-
});
|
|
44
|
-
hexBlockHeaders = blockHeader;
|
|
45
|
-
fromBlockNumber = blockNumber;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
hexBlockHeaders += blockHeader;
|
|
49
|
-
}
|
|
50
|
-
difficulty = parsedBlockHeader.difficulty;
|
|
51
|
-
}
|
|
52
|
-
if (hexBlockHeaders) {
|
|
53
|
-
blockHeaders.push({
|
|
54
|
-
hexBlockHeaders,
|
|
55
|
-
fromBlockNumber,
|
|
56
|
-
toBlockNumber: endBlockNumber,
|
|
57
|
-
difficulty,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return blockHeaders;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
getWrapRequests(addresses, startblockNumber, endBlockNumber) {
|
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
let transactions = yield this.getMultipleBlocksTransactions(addresses, startblockNumber, endBlockNumber);
|
|
66
|
-
let requests = [];
|
|
67
|
-
let invalidRequests = [];
|
|
68
|
-
for (let inputTx of transactions) {
|
|
69
|
-
let { transaction, request, lockerAddress, lockerLockingScript } = yield this.getWrapRequestByTx(inputTx, inputTx.address);
|
|
70
|
-
if (request.status && "data" in request && request.data) {
|
|
71
|
-
if (!configs_1.teleswap.requestAppId[request.data.requestType].appIds.includes(request.data.appId)) {
|
|
72
|
-
invalidRequests.push({
|
|
73
|
-
transaction,
|
|
74
|
-
request: Object.assign(Object.assign({}, request), { message: "invalid app id", code: "INVALID_APP_ID" }),
|
|
75
|
-
lockerAddress,
|
|
76
|
-
lockerLockingScript,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
requests.push({
|
|
81
|
-
transaction,
|
|
82
|
-
request,
|
|
83
|
-
lockerAddress,
|
|
84
|
-
lockerLockingScript,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else if (request.code !== "NO_OP_RETURN") {
|
|
89
|
-
invalidRequests.push({ transaction, request, lockerAddress, lockerLockingScript });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return { requests, invalidRequests };
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
getWrapRequestByTx(inputTransaction, lockerAddress) {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
let transaction;
|
|
98
|
-
if ("vout" in inputTransaction && "blockNumber" in inputTransaction) {
|
|
99
|
-
transaction = inputTransaction;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
if (!inputTransaction.txId)
|
|
103
|
-
throw new Error("txId not exist");
|
|
104
|
-
transaction = yield this.getTransaction(inputTransaction.txId);
|
|
105
|
-
}
|
|
106
|
-
let vout = transaction.vout;
|
|
107
|
-
let request = (0, teleswap_helper_1.checkAndParseWrapRequest)(vout, lockerAddress);
|
|
108
|
-
let lockerLockingScript = transaction.addressScript ||
|
|
109
|
-
this.convertAddressToScript(lockerAddress).script.toString("hex");
|
|
110
|
-
return {
|
|
111
|
-
transaction,
|
|
112
|
-
request,
|
|
113
|
-
lockerAddress,
|
|
114
|
-
lockerLockingScript,
|
|
115
|
-
};
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
getLockersUnWrapTransactions(addresses, startBlockNumber, endBlockNumber) {
|
|
119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
let transactions = yield this.getMultipleBlocksTransactions(addresses, startBlockNumber, endBlockNumber);
|
|
121
|
-
let validTxs = [];
|
|
122
|
-
for (let transaction of transactions) {
|
|
123
|
-
let address = transaction.address;
|
|
124
|
-
let txBurnInfo = yield this.getTransactionUnwrapInfoByTx(transaction, address);
|
|
125
|
-
if (txBurnInfo) {
|
|
126
|
-
const { burnInfo, lockerAddress, lockerLockingScript } = txBurnInfo;
|
|
127
|
-
validTxs.push({
|
|
128
|
-
transaction,
|
|
129
|
-
burnInfo,
|
|
130
|
-
lockerAddress,
|
|
131
|
-
lockerLockingScript,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return validTxs;
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
getLockersUnwrapMEmpoolTransactions(addresses, startBlockNumber, endBlockNumber) {
|
|
139
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
let transactions = yield this.getMultipleBlocksTransactions(addresses, startBlockNumber, endBlockNumber);
|
|
141
|
-
let validTxs = [];
|
|
142
|
-
for (let transaction of transactions) {
|
|
143
|
-
let address = transaction.address;
|
|
144
|
-
let txBurnInfo = yield this.getTransactionUnwrapInfoByTx(transaction, address);
|
|
145
|
-
if (txBurnInfo) {
|
|
146
|
-
const { burnInfo, lockerAddress, lockerLockingScript } = txBurnInfo;
|
|
147
|
-
validTxs.push({
|
|
148
|
-
transaction,
|
|
149
|
-
burnInfo,
|
|
150
|
-
lockerAddress,
|
|
151
|
-
lockerLockingScript,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return validTxs;
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
getTransactionUnwrapInfoByTx(transaction, lockerAddress) {
|
|
159
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
if (!transaction.txId)
|
|
161
|
-
throw new Error("txId not exist");
|
|
162
|
-
let vin = transaction.vin || (yield this.getTransaction(transaction.txId)).vin;
|
|
163
|
-
let burnInfo = (0, teleswap_helper_1.getBurnTransactionInfo)(lockerAddress, vin, transaction.vout);
|
|
164
|
-
if (!burnInfo)
|
|
165
|
-
return;
|
|
166
|
-
let lockerLockingScript = transaction.addressScript ||
|
|
167
|
-
this.convertAddressToScript(lockerAddress).script.toString("hex");
|
|
168
|
-
return {
|
|
169
|
-
burnInfo,
|
|
170
|
-
lockerAddress,
|
|
171
|
-
lockerLockingScript,
|
|
172
|
-
};
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
exports.BitcoinInterfaceTeleswap = BitcoinInterfaceTeleswap;
|
|
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.BitcoinInterfaceTeleswap = void 0;
|
|
16
|
+
const configs_1 = require("@teleportdao/configs");
|
|
17
|
+
const bitcoin_utils_1 = require("./bitcoin-utils");
|
|
18
|
+
const teleswap_helper_1 = require("./helper/teleswap-helper");
|
|
19
|
+
const bitcoin_interface_1 = __importDefault(require("./bitcoin-interface"));
|
|
20
|
+
class BitcoinInterfaceTeleswap extends bitcoin_interface_1.default {
|
|
21
|
+
constructor(connectionInfo, networkName) {
|
|
22
|
+
if (!connectionInfo.rpc) {
|
|
23
|
+
throw new Error("rpc provider is required");
|
|
24
|
+
}
|
|
25
|
+
super(networkName, connectionInfo);
|
|
26
|
+
}
|
|
27
|
+
getHexBlockHeaders(startBlockNumber, endBlockNumber) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const blockHeaders = [];
|
|
30
|
+
let difficulty = null;
|
|
31
|
+
let hexBlockHeaders = "";
|
|
32
|
+
let fromBlockNumber = startBlockNumber;
|
|
33
|
+
for (let blockNumber = startBlockNumber; blockNumber <= endBlockNumber; blockNumber += 1) {
|
|
34
|
+
let blockHeader = yield this.getBlockHeaderHex(blockNumber);
|
|
35
|
+
console.log("block", blockNumber);
|
|
36
|
+
let parsedBlockHeader = (0, bitcoin_utils_1.parseBlockHeader)(blockHeader);
|
|
37
|
+
if (difficulty && parsedBlockHeader.difficulty !== difficulty) {
|
|
38
|
+
blockHeaders.push({
|
|
39
|
+
hexBlockHeaders,
|
|
40
|
+
fromBlockNumber,
|
|
41
|
+
toBlockNumber: blockNumber - 1,
|
|
42
|
+
difficulty,
|
|
43
|
+
});
|
|
44
|
+
hexBlockHeaders = blockHeader;
|
|
45
|
+
fromBlockNumber = blockNumber;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
hexBlockHeaders += blockHeader;
|
|
49
|
+
}
|
|
50
|
+
difficulty = parsedBlockHeader.difficulty;
|
|
51
|
+
}
|
|
52
|
+
if (hexBlockHeaders) {
|
|
53
|
+
blockHeaders.push({
|
|
54
|
+
hexBlockHeaders,
|
|
55
|
+
fromBlockNumber,
|
|
56
|
+
toBlockNumber: endBlockNumber,
|
|
57
|
+
difficulty,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return blockHeaders;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
getWrapRequests(addresses, startblockNumber, endBlockNumber) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
let transactions = yield this.getMultipleBlocksTransactions(addresses, startblockNumber, endBlockNumber);
|
|
66
|
+
let requests = [];
|
|
67
|
+
let invalidRequests = [];
|
|
68
|
+
for (let inputTx of transactions) {
|
|
69
|
+
let { transaction, request, lockerAddress, lockerLockingScript } = yield this.getWrapRequestByTx(inputTx, inputTx.address);
|
|
70
|
+
if (request.status && "data" in request && request.data) {
|
|
71
|
+
if (!configs_1.teleswap.requestAppId[request.data.requestType].appIds.includes(request.data.appId)) {
|
|
72
|
+
invalidRequests.push({
|
|
73
|
+
transaction,
|
|
74
|
+
request: Object.assign(Object.assign({}, request), { message: "invalid app id", code: "INVALID_APP_ID" }),
|
|
75
|
+
lockerAddress,
|
|
76
|
+
lockerLockingScript,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
requests.push({
|
|
81
|
+
transaction,
|
|
82
|
+
request,
|
|
83
|
+
lockerAddress,
|
|
84
|
+
lockerLockingScript,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (request.code !== "NO_OP_RETURN") {
|
|
89
|
+
invalidRequests.push({ transaction, request, lockerAddress, lockerLockingScript });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { requests, invalidRequests };
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
getWrapRequestByTx(inputTransaction, lockerAddress) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
let transaction;
|
|
98
|
+
if ("vout" in inputTransaction && "blockNumber" in inputTransaction) {
|
|
99
|
+
transaction = inputTransaction;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
if (!inputTransaction.txId)
|
|
103
|
+
throw new Error("txId not exist");
|
|
104
|
+
transaction = yield this.getTransaction(inputTransaction.txId);
|
|
105
|
+
}
|
|
106
|
+
let vout = transaction.vout;
|
|
107
|
+
let request = (0, teleswap_helper_1.checkAndParseWrapRequest)(vout, lockerAddress);
|
|
108
|
+
let lockerLockingScript = transaction.addressScript ||
|
|
109
|
+
this.convertAddressToScript(lockerAddress).script.toString("hex");
|
|
110
|
+
return {
|
|
111
|
+
transaction,
|
|
112
|
+
request,
|
|
113
|
+
lockerAddress,
|
|
114
|
+
lockerLockingScript,
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
getLockersUnWrapTransactions(addresses, startBlockNumber, endBlockNumber) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
let transactions = yield this.getMultipleBlocksTransactions(addresses, startBlockNumber, endBlockNumber);
|
|
121
|
+
let validTxs = [];
|
|
122
|
+
for (let transaction of transactions) {
|
|
123
|
+
let address = transaction.address;
|
|
124
|
+
let txBurnInfo = yield this.getTransactionUnwrapInfoByTx(transaction, address);
|
|
125
|
+
if (txBurnInfo) {
|
|
126
|
+
const { burnInfo, lockerAddress, lockerLockingScript } = txBurnInfo;
|
|
127
|
+
validTxs.push({
|
|
128
|
+
transaction,
|
|
129
|
+
burnInfo,
|
|
130
|
+
lockerAddress,
|
|
131
|
+
lockerLockingScript,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return validTxs;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
getLockersUnwrapMEmpoolTransactions(addresses, startBlockNumber, endBlockNumber) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
let transactions = yield this.getMultipleBlocksTransactions(addresses, startBlockNumber, endBlockNumber);
|
|
141
|
+
let validTxs = [];
|
|
142
|
+
for (let transaction of transactions) {
|
|
143
|
+
let address = transaction.address;
|
|
144
|
+
let txBurnInfo = yield this.getTransactionUnwrapInfoByTx(transaction, address);
|
|
145
|
+
if (txBurnInfo) {
|
|
146
|
+
const { burnInfo, lockerAddress, lockerLockingScript } = txBurnInfo;
|
|
147
|
+
validTxs.push({
|
|
148
|
+
transaction,
|
|
149
|
+
burnInfo,
|
|
150
|
+
lockerAddress,
|
|
151
|
+
lockerLockingScript,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return validTxs;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
getTransactionUnwrapInfoByTx(transaction, lockerAddress) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
if (!transaction.txId)
|
|
161
|
+
throw new Error("txId not exist");
|
|
162
|
+
let vin = transaction.vin || (yield this.getTransaction(transaction.txId)).vin;
|
|
163
|
+
let burnInfo = (0, teleswap_helper_1.getBurnTransactionInfo)(lockerAddress, vin, transaction.vout);
|
|
164
|
+
if (!burnInfo)
|
|
165
|
+
return;
|
|
166
|
+
let lockerLockingScript = transaction.addressScript ||
|
|
167
|
+
this.convertAddressToScript(lockerAddress).script.toString("hex");
|
|
168
|
+
return {
|
|
169
|
+
burnInfo,
|
|
170
|
+
lockerAddress,
|
|
171
|
+
lockerLockingScript,
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.BitcoinInterfaceTeleswap = BitcoinInterfaceTeleswap;
|
|
177
177
|
//# sourceMappingURL=bitcoin-interface-teleswap.js.map
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { Network } from "bitcoinjs-lib";
|
|
3
|
-
export declare class BitcoinInterfaceUtils {
|
|
4
|
-
testnet: boolean;
|
|
5
|
-
network: Network;
|
|
6
|
-
constructor(networkName: string);
|
|
7
|
-
convertHashToAddress(hashHex: string, addressType: string): string;
|
|
8
|
-
convertScriptToAddress(scriptHex: string, addressType: string): string;
|
|
9
|
-
convertAddressToScript(address: string): {
|
|
10
|
-
script: Buffer | undefined;
|
|
11
|
-
hash: Buffer | undefined;
|
|
12
|
-
addressType: "p2tr" | "p2wpkh" | "p2sh" | "p2pkh";
|
|
13
|
-
};
|
|
14
|
-
convertAddressToObject(address: string): {
|
|
15
|
-
addressObject: import("bitcoinjs-lib").Payment;
|
|
16
|
-
addressType: "p2tr" | "p2wpkh" | "p2sh" | "p2pkh";
|
|
17
|
-
};
|
|
18
|
-
createAddressObjectByPublicKey(publicKey: string, addressType: string): import("bitcoinjs-lib").Payment;
|
|
19
|
-
}
|
|
20
|
-
export default BitcoinInterfaceUtils;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Network } from "bitcoinjs-lib";
|
|
3
|
+
export declare class BitcoinInterfaceUtils {
|
|
4
|
+
testnet: boolean;
|
|
5
|
+
network: Network;
|
|
6
|
+
constructor(networkName: string);
|
|
7
|
+
convertHashToAddress(hashHex: string, addressType: string): string;
|
|
8
|
+
convertScriptToAddress(scriptHex: string, addressType: string): string;
|
|
9
|
+
convertAddressToScript(address: string): {
|
|
10
|
+
script: Buffer | undefined;
|
|
11
|
+
hash: Buffer | undefined;
|
|
12
|
+
addressType: "p2tr" | "p2wpkh" | "p2sh" | "p2pkh";
|
|
13
|
+
};
|
|
14
|
+
convertAddressToObject(address: string): {
|
|
15
|
+
addressObject: import("bitcoinjs-lib").Payment;
|
|
16
|
+
addressType: "p2tr" | "p2wpkh" | "p2sh" | "p2pkh";
|
|
17
|
+
};
|
|
18
|
+
createAddressObjectByPublicKey(publicKey: string, addressType: string): import("bitcoinjs-lib").Payment;
|
|
19
|
+
}
|
|
20
|
+
export default BitcoinInterfaceUtils;
|
|
21
21
|
//# sourceMappingURL=bitcoin-interface-utils.d.ts.map
|