@cityofzion/blockchain-service 0.7.2 → 0.7.3
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/functions.d.ts +3 -1
- package/dist/functions.js +35 -1
- package/dist/interfaces.d.ts +12 -0
- package/package.json +1 -1
package/dist/functions.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { BlockchainService, BSCalculableFee, BSClaimable, BSWithNameService, BSWithNft } from './interfaces';
|
|
1
|
+
import { BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithNameService, BSWithNft } from './interfaces';
|
|
2
2
|
export declare function hasNameService(service: BlockchainService): service is BlockchainService & BSWithNameService;
|
|
3
3
|
export declare function isClaimable(service: BlockchainService): service is BlockchainService & BSClaimable;
|
|
4
4
|
export declare function isCalculableFee(service: BlockchainService): service is BlockchainService & BSCalculableFee;
|
|
5
5
|
export declare function hasNft(service: BlockchainService): service is BlockchainService & BSWithNft;
|
|
6
|
+
export declare function hasExplorerService(service: BlockchainService): service is BlockchainService & BSWithExplorerService;
|
|
7
|
+
export declare function waitForTransaction(service: BlockchainService, txId: string): Promise<boolean>;
|
package/dist/functions.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
|
|
12
|
+
exports.waitForTransaction = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
|
|
4
13
|
function hasNameService(service) {
|
|
5
14
|
return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
|
|
6
15
|
}
|
|
@@ -17,3 +26,28 @@ function hasNft(service) {
|
|
|
17
26
|
return 'nftDataService' in service;
|
|
18
27
|
}
|
|
19
28
|
exports.hasNft = hasNft;
|
|
29
|
+
function hasExplorerService(service) {
|
|
30
|
+
return 'explorerService' in service;
|
|
31
|
+
}
|
|
32
|
+
exports.hasExplorerService = hasExplorerService;
|
|
33
|
+
function wait(ms) {
|
|
34
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
35
|
+
}
|
|
36
|
+
function waitForTransaction(service, txId) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const maxAttempts = 30;
|
|
39
|
+
const waitMs = service.blockchainDataService.maxTimeToConfirmTransactionInMs / maxAttempts;
|
|
40
|
+
let attempts = 1;
|
|
41
|
+
do {
|
|
42
|
+
try {
|
|
43
|
+
yield service.blockchainDataService.getTransaction(txId);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch (_a) { }
|
|
47
|
+
attempts++;
|
|
48
|
+
yield wait(waitMs);
|
|
49
|
+
} while (attempts < maxAttempts);
|
|
50
|
+
return false;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.waitForTransaction = waitForTransaction;
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -68,6 +68,9 @@ export interface BSWithNameService {
|
|
|
68
68
|
resolveNameServiceDomain(domainName: string): Promise<string>;
|
|
69
69
|
validateNameServiceDomainFormat(domainName: string): boolean;
|
|
70
70
|
}
|
|
71
|
+
export interface BSWithExplorerService {
|
|
72
|
+
explorerService: ExplorerService;
|
|
73
|
+
}
|
|
71
74
|
export interface BSWithNft {
|
|
72
75
|
nftDataService: NftDataService;
|
|
73
76
|
}
|
|
@@ -128,6 +131,7 @@ export type BalanceResponse = {
|
|
|
128
131
|
token: Token;
|
|
129
132
|
};
|
|
130
133
|
export interface BlockchainDataService {
|
|
134
|
+
maxTimeToConfirmTransactionInMs: number;
|
|
131
135
|
getTransaction(txid: string): Promise<TransactionResponse>;
|
|
132
136
|
getTransactionsByAddress(params: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
|
|
133
137
|
getContract(contractHash: string): Promise<ContractResponse>;
|
|
@@ -167,3 +171,11 @@ export interface NftDataService {
|
|
|
167
171
|
getNftsByAddress(params: GetNftsByAddressParams): Promise<NftsResponse>;
|
|
168
172
|
getNft(params: GetNftParam): Promise<NftResponse>;
|
|
169
173
|
}
|
|
174
|
+
export type BuildNftUrlParams = {
|
|
175
|
+
contractHash: string;
|
|
176
|
+
tokenId: string;
|
|
177
|
+
};
|
|
178
|
+
export interface ExplorerService {
|
|
179
|
+
buildTransactionUrl(hash: string): string;
|
|
180
|
+
buildNftUrl(params: BuildNftUrlParams): string;
|
|
181
|
+
}
|