@cityofzion/blockchain-service 1.15.3 → 1.16.0
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/constants.d.ts +3 -0
- package/dist/constants.js +7 -0
- package/dist/functions.d.ts +15 -1
- package/dist/functions.js +49 -3
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlockchainServiceConstants = void 0;
|
|
4
|
+
class BlockchainServiceConstants {
|
|
5
|
+
}
|
|
6
|
+
exports.BlockchainServiceConstants = BlockchainServiceConstants;
|
|
7
|
+
BlockchainServiceConstants.COZ_NEO3_MIGRATION_ADDRESS = 'NLMsicDapULKFDmAzTsbhwrZjYZ83j53Ty';
|
package/dist/functions.d.ts
CHANGED
|
@@ -11,7 +11,21 @@ export declare function wait(ms: number): Promise<unknown>;
|
|
|
11
11
|
* @deprecated use `waitForAccountTransaction` instead
|
|
12
12
|
*/
|
|
13
13
|
export declare function waitForTransaction<BSName extends string = string>(service: BlockchainService<BSName>, txId: string): Promise<boolean>;
|
|
14
|
-
export declare function waitForAccountTransaction<BSName extends string = string>(
|
|
14
|
+
export declare function waitForAccountTransaction<BSName extends string = string>(params: {
|
|
15
|
+
service: BlockchainService<BSName>;
|
|
16
|
+
txId: string;
|
|
17
|
+
address: string;
|
|
18
|
+
maxAttempts?: number;
|
|
19
|
+
}): Promise<boolean>;
|
|
20
|
+
export declare function waitForMigration(params: {
|
|
21
|
+
service: BlockchainService & BSMigrationNeo3;
|
|
22
|
+
neo3Service: BlockchainService;
|
|
23
|
+
neo3Address: string;
|
|
24
|
+
txId: string;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
isTransactionConfirmed: boolean;
|
|
27
|
+
isNeo3TransactionConfirmed: boolean;
|
|
28
|
+
}>;
|
|
15
29
|
export declare function fetchAccounts<BSName extends string = string>(blockchainServices: BlockchainService<BSName>, initialIndex: number, getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>): Promise<Account<BSName>[]>;
|
|
16
30
|
export declare function generateAccount<BSName extends string = string>(blockchainServices: BlockchainService<BSName>, initialIndex: number, untilIndex: number, getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>): Promise<Account<BSName>[]>;
|
|
17
31
|
export declare function generateAccountForBlockchainService<BSName extends string = string>(blockchainServices: BlockchainService<BSName>[], getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>, untilIndexByBlockchainService?: UntilIndexRecord<BSName>): Promise<Map<BSName, Account<BSName>[]>>;
|
package/dist/functions.js
CHANGED
|
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.formatNumber = exports.countDecimals = exports.denormalizeHash = exports.normalizeHash = exports.generateAccountForBlockchainService = exports.generateAccount = exports.fetchAccounts = exports.waitForAccountTransaction = exports.waitForTransaction = exports.wait = exports.hasLedger = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.hasMigrationNeo3 = exports.isClaimable = exports.hasNameService = void 0;
|
|
12
|
+
exports.formatNumber = exports.countDecimals = exports.denormalizeHash = exports.normalizeHash = exports.generateAccountForBlockchainService = exports.generateAccount = exports.fetchAccounts = exports.waitForMigration = exports.waitForAccountTransaction = exports.waitForTransaction = exports.wait = exports.hasLedger = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.hasMigrationNeo3 = exports.isClaimable = exports.hasNameService = void 0;
|
|
13
|
+
const constants_1 = require("./constants");
|
|
13
14
|
function hasNameService(service) {
|
|
14
15
|
return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
|
|
15
16
|
}
|
|
@@ -65,13 +66,14 @@ function waitForTransaction(service, txId) {
|
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
exports.waitForTransaction = waitForTransaction;
|
|
68
|
-
function waitForAccountTransaction(
|
|
69
|
+
function waitForAccountTransaction(params) {
|
|
69
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const { address, maxAttempts = 10, service, txId } = params;
|
|
70
72
|
let attempts = 1;
|
|
71
73
|
do {
|
|
72
74
|
yield wait(60000);
|
|
73
75
|
try {
|
|
74
|
-
const response = yield service.blockchainDataService.getTransactionsByAddress({ address
|
|
76
|
+
const response = yield service.blockchainDataService.getTransactionsByAddress({ address });
|
|
75
77
|
const isTransactionConfirmed = response.transactions.some(transaction => transaction.hash === txId);
|
|
76
78
|
if (isTransactionConfirmed)
|
|
77
79
|
return true;
|
|
@@ -85,6 +87,50 @@ function waitForAccountTransaction(service, txId, account, maxAttempts = 10) {
|
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
89
|
exports.waitForAccountTransaction = waitForAccountTransaction;
|
|
90
|
+
function waitForMigration(params) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const { neo3Address, neo3Service, service, txId } = params;
|
|
93
|
+
const MAX_ATTEMPTS = 10;
|
|
94
|
+
const NEO3_MAX_ATTEMPTS = 20;
|
|
95
|
+
const response = {
|
|
96
|
+
isTransactionConfirmed: false,
|
|
97
|
+
isNeo3TransactionConfirmed: false,
|
|
98
|
+
};
|
|
99
|
+
let transactionResponse;
|
|
100
|
+
for (let i = 0; i < MAX_ATTEMPTS; i++) {
|
|
101
|
+
yield wait(30000);
|
|
102
|
+
try {
|
|
103
|
+
transactionResponse = yield service.blockchainDataService.getTransaction(txId);
|
|
104
|
+
response.isTransactionConfirmed = true;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
catch (_b) {
|
|
108
|
+
// Empty block
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!response.isTransactionConfirmed)
|
|
112
|
+
return response;
|
|
113
|
+
for (let i = 0; i < NEO3_MAX_ATTEMPTS; i++) {
|
|
114
|
+
yield wait(60000);
|
|
115
|
+
try {
|
|
116
|
+
const neo3Response = yield neo3Service.blockchainDataService.getTransactionsByAddress({
|
|
117
|
+
address: neo3Address,
|
|
118
|
+
});
|
|
119
|
+
const isTransactionConfirmed = neo3Response.transactions.some(transaction => transaction.time > transactionResponse.time &&
|
|
120
|
+
transaction.transfers.some(transfer => transfer.from === constants_1.BlockchainServiceConstants.COZ_NEO3_MIGRATION_ADDRESS));
|
|
121
|
+
if (isTransactionConfirmed) {
|
|
122
|
+
response.isNeo3TransactionConfirmed = true;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (_c) {
|
|
127
|
+
// Empty block
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return response;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
exports.waitForMigration = waitForMigration;
|
|
88
134
|
function fetchAccounts(blockchainServices, initialIndex, getAccountCallback) {
|
|
89
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
136
|
const accounts = [];
|