@cityofzion/blockchain-service 0.7.3 → 0.8.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/BSAggregator.d.ts +16 -16
- package/dist/BSAggregator.js +86 -86
- package/dist/exceptions.d.ts +9 -9
- package/dist/exceptions.js +21 -21
- package/dist/functions.d.ts +7 -7
- package/dist/functions.js +53 -53
- package/dist/index.d.ts +3 -3
- package/dist/index.js +19 -19
- package/dist/interfaces.d.ts +182 -181
- package/dist/interfaces.js +2 -2
- package/package.json +19 -20
- package/dist/BSAgreggator.d.ts +0 -16
- package/dist/BSAgreggator.js +0 -70
- package/dist/exchanges/flamingo/Flamingo.d.ts +0 -8
- package/dist/exchanges/flamingo/Flamingo.js +0 -37
- package/dist/exchanges/flamingo/FlamingoResponses.d.ts +0 -4
- package/dist/exchanges/flamingo/FlamingoResponses.js +0 -2
- package/dist/exchanges/flamingo/FlamingoRoutes.d.ts +0 -3
- package/dist/exchanges/flamingo/FlamingoRoutes.js +0 -8
- package/dist/exchanges/index.d.ts +0 -7
- package/dist/exchanges/index.js +0 -24
package/dist/BSAggregator.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { AccountWithDerivationPath, BlockchainService } from './interfaces';
|
|
2
|
-
export declare class BSAggregator<BSCustomName extends string = string, BSCustom extends BlockchainService<BSCustomName> = BlockchainService<BSCustomName>> {
|
|
3
|
-
readonly blockchainServicesByName: Record<BSCustomName, BSCustom>;
|
|
4
|
-
readonly blockchainServices: BlockchainService<BSCustomName>[];
|
|
5
|
-
constructor(blockchainServices: Record<BSCustomName, BSCustom>);
|
|
6
|
-
addBlockchain(name: BSCustomName, blockchain: BSCustom): void;
|
|
7
|
-
validateAddressAllBlockchains(address: string): boolean;
|
|
8
|
-
validateTextAllBlockchains(text: string): boolean;
|
|
9
|
-
validateKeyAllBlockchains(wif: string): boolean;
|
|
10
|
-
validateEncryptedAllBlockchains(keyOrJson: string): boolean;
|
|
11
|
-
getBlockchainByName(name: BSCustomName): BlockchainService<BSCustomName>;
|
|
12
|
-
getBlockchainByAddress(address: string): BlockchainService<BSCustomName> | undefined;
|
|
13
|
-
getBlockchainByKey(wif: string): BlockchainService<BSCustomName> | undefined;
|
|
14
|
-
getBlockchainByEncrypted(keyOrJson: string): BlockchainService<BSCustomName> | undefined;
|
|
15
|
-
generateAccountFromMnemonicAllBlockchains(mnemonic: string, skippedAddresses?: string[]): Promise<Map<BSCustomName, AccountWithDerivationPath[]>>;
|
|
16
|
-
}
|
|
1
|
+
import { AccountWithDerivationPath, BlockchainService } from './interfaces';
|
|
2
|
+
export declare class BSAggregator<BSCustomName extends string = string, BSCustom extends BlockchainService<BSCustomName> = BlockchainService<BSCustomName>> {
|
|
3
|
+
readonly blockchainServicesByName: Record<BSCustomName, BSCustom>;
|
|
4
|
+
readonly blockchainServices: BlockchainService<BSCustomName>[];
|
|
5
|
+
constructor(blockchainServices: Record<BSCustomName, BSCustom>);
|
|
6
|
+
addBlockchain(name: BSCustomName, blockchain: BSCustom): void;
|
|
7
|
+
validateAddressAllBlockchains(address: string): boolean;
|
|
8
|
+
validateTextAllBlockchains(text: string): boolean;
|
|
9
|
+
validateKeyAllBlockchains(wif: string): boolean;
|
|
10
|
+
validateEncryptedAllBlockchains(keyOrJson: string): boolean;
|
|
11
|
+
getBlockchainByName(name: BSCustomName): BlockchainService<BSCustomName>;
|
|
12
|
+
getBlockchainByAddress(address: string): BlockchainService<BSCustomName> | undefined;
|
|
13
|
+
getBlockchainByKey(wif: string): BlockchainService<BSCustomName> | undefined;
|
|
14
|
+
getBlockchainByEncrypted(keyOrJson: string): BlockchainService<BSCustomName> | undefined;
|
|
15
|
+
generateAccountFromMnemonicAllBlockchains(mnemonic: string, skippedAddresses?: string[]): Promise<Map<BSCustomName, AccountWithDerivationPath[]>>;
|
|
16
|
+
}
|
package/dist/BSAggregator.js
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.BSAggregator = void 0;
|
|
13
|
-
const exceptions_1 = require("./exceptions");
|
|
14
|
-
class BSAggregator {
|
|
15
|
-
constructor(blockchainServices) {
|
|
16
|
-
this.blockchainServicesByName = blockchainServices;
|
|
17
|
-
this.blockchainServices = Object.values(blockchainServices);
|
|
18
|
-
}
|
|
19
|
-
addBlockchain(name, blockchain) {
|
|
20
|
-
if (this.blockchainServicesByName[name])
|
|
21
|
-
throw new exceptions_1.BlockchainAlreadyExistError(name);
|
|
22
|
-
this.blockchainServicesByName[name] = blockchain;
|
|
23
|
-
this.blockchainServices.push(blockchain);
|
|
24
|
-
}
|
|
25
|
-
validateAddressAllBlockchains(address) {
|
|
26
|
-
return this.blockchainServices.some(bs => bs.validateAddress(address));
|
|
27
|
-
}
|
|
28
|
-
validateTextAllBlockchains(text) {
|
|
29
|
-
return this.blockchainServices.some(bs => [bs.validateAddress(text), bs.validateEncrypted(text), bs.validateKey(text)].some(it => it === true));
|
|
30
|
-
}
|
|
31
|
-
validateKeyAllBlockchains(wif) {
|
|
32
|
-
return this.blockchainServices.some(bs => bs.validateKey(wif));
|
|
33
|
-
}
|
|
34
|
-
validateEncryptedAllBlockchains(keyOrJson) {
|
|
35
|
-
return this.blockchainServices.some(bs => bs.validateEncrypted(keyOrJson));
|
|
36
|
-
}
|
|
37
|
-
getBlockchainByName(name) {
|
|
38
|
-
const service = this.blockchainServicesByName[name];
|
|
39
|
-
if (!service)
|
|
40
|
-
throw new exceptions_1.BlockchainNotFoundError(name);
|
|
41
|
-
return this.blockchainServicesByName[name];
|
|
42
|
-
}
|
|
43
|
-
getBlockchainByAddress(address) {
|
|
44
|
-
return this.blockchainServices.find(bs => bs.validateAddress(address));
|
|
45
|
-
}
|
|
46
|
-
getBlockchainByKey(wif) {
|
|
47
|
-
return this.blockchainServices.find(bs => bs.validateKey(wif));
|
|
48
|
-
}
|
|
49
|
-
getBlockchainByEncrypted(keyOrJson) {
|
|
50
|
-
return this.blockchainServices.find(bs => bs.validateEncrypted(keyOrJson));
|
|
51
|
-
}
|
|
52
|
-
generateAccountFromMnemonicAllBlockchains(mnemonic, skippedAddresses) {
|
|
53
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const mnemonicAccounts = new Map();
|
|
55
|
-
const promises = this.blockchainServices.map((service) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
let index = 0;
|
|
57
|
-
const accounts = [];
|
|
58
|
-
while (true) {
|
|
59
|
-
const generatedAccount = service.generateAccountFromMnemonic(mnemonic, index);
|
|
60
|
-
if (skippedAddresses && skippedAddresses.find(address => address === generatedAccount.address)) {
|
|
61
|
-
index++;
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
if (index !== 0) {
|
|
65
|
-
try {
|
|
66
|
-
const { totalCount } = yield service.blockchainDataService.getTransactionsByAddress({
|
|
67
|
-
address: generatedAccount.address,
|
|
68
|
-
});
|
|
69
|
-
if (!totalCount || totalCount <= 0)
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
catch (_a) {
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
accounts.push(generatedAccount);
|
|
77
|
-
index++;
|
|
78
|
-
}
|
|
79
|
-
mnemonicAccounts.set(service.blockchainName, accounts);
|
|
80
|
-
}));
|
|
81
|
-
yield Promise.all(promises);
|
|
82
|
-
return mnemonicAccounts;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.BSAggregator = BSAggregator;
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BSAggregator = void 0;
|
|
13
|
+
const exceptions_1 = require("./exceptions");
|
|
14
|
+
class BSAggregator {
|
|
15
|
+
constructor(blockchainServices) {
|
|
16
|
+
this.blockchainServicesByName = blockchainServices;
|
|
17
|
+
this.blockchainServices = Object.values(blockchainServices);
|
|
18
|
+
}
|
|
19
|
+
addBlockchain(name, blockchain) {
|
|
20
|
+
if (this.blockchainServicesByName[name])
|
|
21
|
+
throw new exceptions_1.BlockchainAlreadyExistError(name);
|
|
22
|
+
this.blockchainServicesByName[name] = blockchain;
|
|
23
|
+
this.blockchainServices.push(blockchain);
|
|
24
|
+
}
|
|
25
|
+
validateAddressAllBlockchains(address) {
|
|
26
|
+
return this.blockchainServices.some(bs => bs.validateAddress(address));
|
|
27
|
+
}
|
|
28
|
+
validateTextAllBlockchains(text) {
|
|
29
|
+
return this.blockchainServices.some(bs => [bs.validateAddress(text), bs.validateEncrypted(text), bs.validateKey(text)].some(it => it === true));
|
|
30
|
+
}
|
|
31
|
+
validateKeyAllBlockchains(wif) {
|
|
32
|
+
return this.blockchainServices.some(bs => bs.validateKey(wif));
|
|
33
|
+
}
|
|
34
|
+
validateEncryptedAllBlockchains(keyOrJson) {
|
|
35
|
+
return this.blockchainServices.some(bs => bs.validateEncrypted(keyOrJson));
|
|
36
|
+
}
|
|
37
|
+
getBlockchainByName(name) {
|
|
38
|
+
const service = this.blockchainServicesByName[name];
|
|
39
|
+
if (!service)
|
|
40
|
+
throw new exceptions_1.BlockchainNotFoundError(name);
|
|
41
|
+
return this.blockchainServicesByName[name];
|
|
42
|
+
}
|
|
43
|
+
getBlockchainByAddress(address) {
|
|
44
|
+
return this.blockchainServices.find(bs => bs.validateAddress(address));
|
|
45
|
+
}
|
|
46
|
+
getBlockchainByKey(wif) {
|
|
47
|
+
return this.blockchainServices.find(bs => bs.validateKey(wif));
|
|
48
|
+
}
|
|
49
|
+
getBlockchainByEncrypted(keyOrJson) {
|
|
50
|
+
return this.blockchainServices.find(bs => bs.validateEncrypted(keyOrJson));
|
|
51
|
+
}
|
|
52
|
+
generateAccountFromMnemonicAllBlockchains(mnemonic, skippedAddresses) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const mnemonicAccounts = new Map();
|
|
55
|
+
const promises = this.blockchainServices.map((service) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
let index = 0;
|
|
57
|
+
const accounts = [];
|
|
58
|
+
while (true) {
|
|
59
|
+
const generatedAccount = service.generateAccountFromMnemonic(mnemonic, index);
|
|
60
|
+
if (skippedAddresses && skippedAddresses.find(address => address === generatedAccount.address)) {
|
|
61
|
+
index++;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (index !== 0) {
|
|
65
|
+
try {
|
|
66
|
+
const { totalCount } = yield service.blockchainDataService.getTransactionsByAddress({
|
|
67
|
+
address: generatedAccount.address,
|
|
68
|
+
});
|
|
69
|
+
if (!totalCount || totalCount <= 0)
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
catch (_a) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
accounts.push(generatedAccount);
|
|
77
|
+
index++;
|
|
78
|
+
}
|
|
79
|
+
mnemonicAccounts.set(service.blockchainName, accounts);
|
|
80
|
+
}));
|
|
81
|
+
yield Promise.all(promises);
|
|
82
|
+
return mnemonicAccounts;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.BSAggregator = BSAggregator;
|
package/dist/exceptions.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare class BlockchainAlreadyExistError extends Error {
|
|
2
|
-
constructor(blockchainName: string);
|
|
3
|
-
}
|
|
4
|
-
export declare class InvalidBlockchainServiceError extends Error {
|
|
5
|
-
constructor(message?: string);
|
|
6
|
-
}
|
|
7
|
-
export declare class BlockchainNotFoundError extends Error {
|
|
8
|
-
constructor(blockchainName: string);
|
|
9
|
-
}
|
|
1
|
+
export declare class BlockchainAlreadyExistError extends Error {
|
|
2
|
+
constructor(blockchainName: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class InvalidBlockchainServiceError extends Error {
|
|
5
|
+
constructor(message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class BlockchainNotFoundError extends Error {
|
|
8
|
+
constructor(blockchainName: string);
|
|
9
|
+
}
|
package/dist/exceptions.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BlockchainNotFoundError = exports.InvalidBlockchainServiceError = exports.BlockchainAlreadyExistError = void 0;
|
|
4
|
-
class BlockchainAlreadyExistError extends Error {
|
|
5
|
-
constructor(blockchainName) {
|
|
6
|
-
super(`The blockchain ${blockchainName} already exist`);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
exports.BlockchainAlreadyExistError = BlockchainAlreadyExistError;
|
|
10
|
-
class InvalidBlockchainServiceError extends Error {
|
|
11
|
-
constructor(message) {
|
|
12
|
-
super(`Invalid blockchainServices => ${message}`);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.InvalidBlockchainServiceError = InvalidBlockchainServiceError;
|
|
16
|
-
class BlockchainNotFoundError extends Error {
|
|
17
|
-
constructor(blockchainName) {
|
|
18
|
-
super(`The blockchain ${blockchainName} not found`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.BlockchainNotFoundError = BlockchainNotFoundError;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlockchainNotFoundError = exports.InvalidBlockchainServiceError = exports.BlockchainAlreadyExistError = void 0;
|
|
4
|
+
class BlockchainAlreadyExistError extends Error {
|
|
5
|
+
constructor(blockchainName) {
|
|
6
|
+
super(`The blockchain ${blockchainName} already exist`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.BlockchainAlreadyExistError = BlockchainAlreadyExistError;
|
|
10
|
+
class InvalidBlockchainServiceError extends Error {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(`Invalid blockchainServices => ${message}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.InvalidBlockchainServiceError = InvalidBlockchainServiceError;
|
|
16
|
+
class BlockchainNotFoundError extends Error {
|
|
17
|
+
constructor(blockchainName) {
|
|
18
|
+
super(`The blockchain ${blockchainName} not found`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.BlockchainNotFoundError = BlockchainNotFoundError;
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithNameService, BSWithNft } from './interfaces';
|
|
2
|
-
export declare function hasNameService(service: BlockchainService): service is BlockchainService & BSWithNameService;
|
|
3
|
-
export declare function isClaimable(service: BlockchainService): service is BlockchainService & BSClaimable;
|
|
4
|
-
export declare function isCalculableFee(service: BlockchainService): service is BlockchainService & BSCalculableFee;
|
|
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>;
|
|
1
|
+
import { BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithNameService, BSWithNft } from './interfaces';
|
|
2
|
+
export declare function hasNameService(service: BlockchainService): service is BlockchainService & BSWithNameService;
|
|
3
|
+
export declare function isClaimable(service: BlockchainService): service is BlockchainService & BSClaimable;
|
|
4
|
+
export declare function isCalculableFee(service: BlockchainService): service is BlockchainService & BSCalculableFee;
|
|
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,53 +1,53 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.waitForTransaction = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
|
|
13
|
-
function hasNameService(service) {
|
|
14
|
-
return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
|
|
15
|
-
}
|
|
16
|
-
exports.hasNameService = hasNameService;
|
|
17
|
-
function isClaimable(service) {
|
|
18
|
-
return 'claim' in service && 'claimToken' in service && 'getUnclaimed' in service.blockchainDataService;
|
|
19
|
-
}
|
|
20
|
-
exports.isClaimable = isClaimable;
|
|
21
|
-
function isCalculableFee(service) {
|
|
22
|
-
return 'calculateTransferFee' in service;
|
|
23
|
-
}
|
|
24
|
-
exports.isCalculableFee = isCalculableFee;
|
|
25
|
-
function hasNft(service) {
|
|
26
|
-
return 'nftDataService' in service;
|
|
27
|
-
}
|
|
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;
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.waitForTransaction = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
|
|
13
|
+
function hasNameService(service) {
|
|
14
|
+
return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
|
|
15
|
+
}
|
|
16
|
+
exports.hasNameService = hasNameService;
|
|
17
|
+
function isClaimable(service) {
|
|
18
|
+
return 'claim' in service && 'claimToken' in service && 'getUnclaimed' in service.blockchainDataService;
|
|
19
|
+
}
|
|
20
|
+
exports.isClaimable = isClaimable;
|
|
21
|
+
function isCalculableFee(service) {
|
|
22
|
+
return 'calculateTransferFee' in service;
|
|
23
|
+
}
|
|
24
|
+
exports.isCalculableFee = isCalculableFee;
|
|
25
|
+
function hasNft(service) {
|
|
26
|
+
return 'nftDataService' in service;
|
|
27
|
+
}
|
|
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/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './interfaces';
|
|
2
|
-
export * from './BSAggregator';
|
|
3
|
-
export * from './functions';
|
|
1
|
+
export * from './interfaces';
|
|
2
|
+
export * from './BSAggregator';
|
|
3
|
+
export * from './functions';
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./interfaces"), exports);
|
|
18
|
-
__exportStar(require("./BSAggregator"), exports);
|
|
19
|
-
__exportStar(require("./functions"), exports);
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./interfaces"), exports);
|
|
18
|
+
__exportStar(require("./BSAggregator"), exports);
|
|
19
|
+
__exportStar(require("./functions"), exports);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,181 +1,182 @@
|
|
|
1
|
-
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
2
|
-
export type Account = {
|
|
3
|
-
key: string;
|
|
4
|
-
type: 'wif' | 'privateKey';
|
|
5
|
-
address: string;
|
|
6
|
-
};
|
|
7
|
-
export type AccountWithDerivationPath = Account & {
|
|
8
|
-
derivationPath: string;
|
|
9
|
-
};
|
|
10
|
-
export interface Token {
|
|
11
|
-
symbol: string;
|
|
12
|
-
name: string;
|
|
13
|
-
hash: string;
|
|
14
|
-
decimals: number;
|
|
15
|
-
}
|
|
16
|
-
export type NetworkType = 'mainnet' | 'testnet' | 'custom';
|
|
17
|
-
export type Network = {
|
|
18
|
-
type: NetworkType;
|
|
19
|
-
url: string;
|
|
20
|
-
};
|
|
21
|
-
export type IntentTransferParam = {
|
|
22
|
-
receiverAddress: string;
|
|
23
|
-
tokenHash: string;
|
|
24
|
-
amount: string;
|
|
25
|
-
tokenDecimals?: number;
|
|
26
|
-
};
|
|
27
|
-
export type TransferParam = {
|
|
28
|
-
senderAccount: Account;
|
|
29
|
-
intent: IntentTransferParam;
|
|
30
|
-
tipIntent?: IntentTransferParam;
|
|
31
|
-
priorityFee?: string;
|
|
32
|
-
};
|
|
33
|
-
export type TokenPricesResponse = {
|
|
34
|
-
price: number;
|
|
35
|
-
symbol: string;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
readonly
|
|
44
|
-
readonly
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
readonly
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
1
|
+
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
2
|
+
export type Account = {
|
|
3
|
+
key: string;
|
|
4
|
+
type: 'wif' | 'privateKey';
|
|
5
|
+
address: string;
|
|
6
|
+
};
|
|
7
|
+
export type AccountWithDerivationPath = Account & {
|
|
8
|
+
derivationPath: string;
|
|
9
|
+
};
|
|
10
|
+
export interface Token {
|
|
11
|
+
symbol: string;
|
|
12
|
+
name: string;
|
|
13
|
+
hash: string;
|
|
14
|
+
decimals: number;
|
|
15
|
+
}
|
|
16
|
+
export type NetworkType = 'mainnet' | 'testnet' | 'custom';
|
|
17
|
+
export type Network = {
|
|
18
|
+
type: NetworkType;
|
|
19
|
+
url: string;
|
|
20
|
+
};
|
|
21
|
+
export type IntentTransferParam = {
|
|
22
|
+
receiverAddress: string;
|
|
23
|
+
tokenHash: string;
|
|
24
|
+
amount: string;
|
|
25
|
+
tokenDecimals?: number;
|
|
26
|
+
};
|
|
27
|
+
export type TransferParam = {
|
|
28
|
+
senderAccount: Account;
|
|
29
|
+
intent: IntentTransferParam;
|
|
30
|
+
tipIntent?: IntentTransferParam;
|
|
31
|
+
priorityFee?: string;
|
|
32
|
+
};
|
|
33
|
+
export type TokenPricesResponse = {
|
|
34
|
+
price: number;
|
|
35
|
+
symbol: string;
|
|
36
|
+
hash: string;
|
|
37
|
+
};
|
|
38
|
+
export type Currency = 'USD' | 'BRL' | 'EUR';
|
|
39
|
+
export interface ExchangeDataService {
|
|
40
|
+
getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
|
|
41
|
+
}
|
|
42
|
+
export interface BlockchainService<BSCustomName extends string = string> {
|
|
43
|
+
readonly blockchainName: BSCustomName;
|
|
44
|
+
readonly derivationPath: string;
|
|
45
|
+
readonly feeToken: Token;
|
|
46
|
+
exchangeDataService: ExchangeDataService;
|
|
47
|
+
blockchainDataService: BlockchainDataService;
|
|
48
|
+
tokens: Token[];
|
|
49
|
+
network: Network;
|
|
50
|
+
setNetwork: (network: PartialBy<Network, 'url'>) => void;
|
|
51
|
+
generateAccountFromMnemonic(mnemonic: string | string, index: number): AccountWithDerivationPath;
|
|
52
|
+
generateAccountFromKey(key: string): Account;
|
|
53
|
+
decrypt(keyOrJson: string, password: string): Promise<Account>;
|
|
54
|
+
validateAddress(address: string): boolean;
|
|
55
|
+
validateEncrypted(keyOrJson: string): boolean;
|
|
56
|
+
validateKey(key: string): boolean;
|
|
57
|
+
transfer(param: TransferParam): Promise<string>;
|
|
58
|
+
}
|
|
59
|
+
export interface BSCalculableFee {
|
|
60
|
+
calculateTransferFee(param: TransferParam, details?: boolean): Promise<string>;
|
|
61
|
+
}
|
|
62
|
+
export interface BSClaimable {
|
|
63
|
+
readonly claimToken: Token;
|
|
64
|
+
readonly burnToken: Token;
|
|
65
|
+
blockchainDataService: BlockchainDataService & BDSClaimable;
|
|
66
|
+
claim(account: Account): Promise<string>;
|
|
67
|
+
}
|
|
68
|
+
export interface BSWithNameService {
|
|
69
|
+
resolveNameServiceDomain(domainName: string): Promise<string>;
|
|
70
|
+
validateNameServiceDomainFormat(domainName: string): boolean;
|
|
71
|
+
}
|
|
72
|
+
export interface BSWithExplorerService {
|
|
73
|
+
explorerService: ExplorerService;
|
|
74
|
+
}
|
|
75
|
+
export interface BSWithNft {
|
|
76
|
+
nftDataService: NftDataService;
|
|
77
|
+
}
|
|
78
|
+
export type TransactionNotifications = {
|
|
79
|
+
eventName: string;
|
|
80
|
+
state: {
|
|
81
|
+
type: string;
|
|
82
|
+
value: string;
|
|
83
|
+
}[];
|
|
84
|
+
};
|
|
85
|
+
export type TransactionTransferAsset = {
|
|
86
|
+
amount: string;
|
|
87
|
+
to: string;
|
|
88
|
+
from: string;
|
|
89
|
+
type: 'token';
|
|
90
|
+
contractHash: string;
|
|
91
|
+
token?: Token;
|
|
92
|
+
};
|
|
93
|
+
export type TransactionTransferNft = {
|
|
94
|
+
tokenId: string;
|
|
95
|
+
to: string;
|
|
96
|
+
from: string;
|
|
97
|
+
type: 'nft';
|
|
98
|
+
contractHash: string;
|
|
99
|
+
};
|
|
100
|
+
export type TransactionResponse = {
|
|
101
|
+
hash: string;
|
|
102
|
+
block: number;
|
|
103
|
+
time: number;
|
|
104
|
+
transfers: (TransactionTransferAsset | TransactionTransferNft)[];
|
|
105
|
+
fee?: string;
|
|
106
|
+
notifications: TransactionNotifications[];
|
|
107
|
+
};
|
|
108
|
+
export type ContractParameter = {
|
|
109
|
+
name: string;
|
|
110
|
+
type: string;
|
|
111
|
+
};
|
|
112
|
+
export type TransactionsByAddressResponse = {
|
|
113
|
+
totalCount: number;
|
|
114
|
+
limit: number;
|
|
115
|
+
transactions: TransactionResponse[];
|
|
116
|
+
};
|
|
117
|
+
export type TransactionsByAddressParams = {
|
|
118
|
+
address: string;
|
|
119
|
+
page?: number;
|
|
120
|
+
};
|
|
121
|
+
export type ContractMethod = {
|
|
122
|
+
name: string;
|
|
123
|
+
parameters: ContractParameter[];
|
|
124
|
+
};
|
|
125
|
+
export type ContractResponse = {
|
|
126
|
+
hash: string;
|
|
127
|
+
name: string;
|
|
128
|
+
methods: ContractMethod[];
|
|
129
|
+
};
|
|
130
|
+
export type BalanceResponse = {
|
|
131
|
+
amount: string;
|
|
132
|
+
token: Token;
|
|
133
|
+
};
|
|
134
|
+
export interface BlockchainDataService {
|
|
135
|
+
maxTimeToConfirmTransactionInMs: number;
|
|
136
|
+
getTransaction(txid: string): Promise<TransactionResponse>;
|
|
137
|
+
getTransactionsByAddress(params: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
|
|
138
|
+
getContract(contractHash: string): Promise<ContractResponse>;
|
|
139
|
+
getTokenInfo(tokenHash: string): Promise<Token>;
|
|
140
|
+
getBalance(address: string): Promise<BalanceResponse[]>;
|
|
141
|
+
getBlockHeight(): Promise<number>;
|
|
142
|
+
}
|
|
143
|
+
export interface BDSClaimable {
|
|
144
|
+
getUnclaimed(address: string): Promise<string>;
|
|
145
|
+
}
|
|
146
|
+
export interface NftResponse {
|
|
147
|
+
id: string;
|
|
148
|
+
contractHash: string;
|
|
149
|
+
collectionName?: string;
|
|
150
|
+
collectionImage?: string;
|
|
151
|
+
symbol: string;
|
|
152
|
+
image?: string;
|
|
153
|
+
name?: string;
|
|
154
|
+
isSVG?: boolean;
|
|
155
|
+
}
|
|
156
|
+
export interface NftsResponse {
|
|
157
|
+
items: NftResponse[];
|
|
158
|
+
nextCursor?: string;
|
|
159
|
+
total?: number;
|
|
160
|
+
}
|
|
161
|
+
export type GetNftsByAddressParams = {
|
|
162
|
+
address: string;
|
|
163
|
+
page?: number;
|
|
164
|
+
cursor?: string;
|
|
165
|
+
size?: number;
|
|
166
|
+
};
|
|
167
|
+
export type GetNftParam = {
|
|
168
|
+
tokenId: string;
|
|
169
|
+
contractHash: string;
|
|
170
|
+
};
|
|
171
|
+
export interface NftDataService {
|
|
172
|
+
getNftsByAddress(params: GetNftsByAddressParams): Promise<NftsResponse>;
|
|
173
|
+
getNft(params: GetNftParam): Promise<NftResponse>;
|
|
174
|
+
}
|
|
175
|
+
export type BuildNftUrlParams = {
|
|
176
|
+
contractHash: string;
|
|
177
|
+
tokenId: string;
|
|
178
|
+
};
|
|
179
|
+
export interface ExplorerService {
|
|
180
|
+
buildTransactionUrl(hash: string): string;
|
|
181
|
+
buildNftUrl(params: BuildNftUrlParams): string;
|
|
182
|
+
}
|
package/dist/interfaces.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@cityofzion/blockchain-service",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"types": "dist/index.d.ts",
|
|
6
|
-
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
7
|
-
"author": "Coz",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"files": [
|
|
10
|
-
"/dist"
|
|
11
|
-
],
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@cityofzion/blockchain-service",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
7
|
+
"author": "Coz",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"files": [
|
|
10
|
+
"/dist"
|
|
11
|
+
],
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@types/node": "~20.2.5",
|
|
14
|
+
"ts-node": "10.9.1",
|
|
15
|
+
"typescript": "4.9.5"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc"
|
|
19
|
+
}
|
|
21
20
|
}
|
package/dist/BSAgreggator.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { BlockchainService, Claimable } from "./interfaces";
|
|
2
|
-
export declare class BSAgreggator<BSCustom extends BlockchainService = BlockchainService, BSCustomName extends string = string> {
|
|
3
|
-
readonly blockchainservices: Record<BSCustomName, BSCustom>;
|
|
4
|
-
private bsList;
|
|
5
|
-
constructor(blockchainservices: Record<BSCustomName, BSCustom>);
|
|
6
|
-
private haveBlockchainServices;
|
|
7
|
-
addBlockchain(name: BSCustomName, blockchain: BSCustom): void;
|
|
8
|
-
validateAddressesAllBlockchains(address: string): boolean;
|
|
9
|
-
validateTextAllBlockchains(text: string): boolean;
|
|
10
|
-
validateWifAllBlockchains(wif: string): boolean;
|
|
11
|
-
validateEncryptedKeyAllBlockchains(encryptedKey: string): boolean;
|
|
12
|
-
getBlockchainByAddress(address: string): BlockchainService<BSCustomName> | null;
|
|
13
|
-
getBlockchainByWif(wif: string): BlockchainService<BSCustomName> | null;
|
|
14
|
-
getBlockchainByEncryptedKey(encryptedKey: string): BlockchainService<BSCustomName> | null;
|
|
15
|
-
getBlockchainsClaimable(): (BlockchainService<BSCustomName> & Claimable)[];
|
|
16
|
-
}
|
package/dist/BSAgreggator.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BSAgreggator = void 0;
|
|
4
|
-
const exceptions_1 = require("./exceptions");
|
|
5
|
-
class BSAgreggator {
|
|
6
|
-
constructor(blockchainservices) {
|
|
7
|
-
this.blockchainservices = blockchainservices;
|
|
8
|
-
this.bsList = Object.values(blockchainservices);
|
|
9
|
-
}
|
|
10
|
-
haveBlockchainServices() {
|
|
11
|
-
const blockchainservices = Object.values(this.blockchainservices);
|
|
12
|
-
const rules = [
|
|
13
|
-
Object.keys(blockchainservices).length > 1,
|
|
14
|
-
Object.values(blockchainservices).length > 1,
|
|
15
|
-
];
|
|
16
|
-
return rules.every(rule => rule === true);
|
|
17
|
-
}
|
|
18
|
-
addBlockchain(name, blockchain) {
|
|
19
|
-
if (this.blockchainservices[name])
|
|
20
|
-
exceptions_1.exceptions.blockchainAlreadyExist(name);
|
|
21
|
-
this.blockchainservices[name] = blockchain;
|
|
22
|
-
this.bsList = Object.values(this.blockchainservices);
|
|
23
|
-
}
|
|
24
|
-
validateAddressesAllBlockchains(address) {
|
|
25
|
-
if (this.haveBlockchainServices())
|
|
26
|
-
exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
|
|
27
|
-
return this.bsList.some(bs => bs.validateAddress(address));
|
|
28
|
-
}
|
|
29
|
-
validateTextAllBlockchains(text) {
|
|
30
|
-
if (this.haveBlockchainServices())
|
|
31
|
-
exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
|
|
32
|
-
return this.bsList.some(bs => [bs.validateAddress(text), bs.validateEncryptedKey(text), bs.validateWif(text)].some(it => it === true));
|
|
33
|
-
}
|
|
34
|
-
validateWifAllBlockchains(wif) {
|
|
35
|
-
if (this.haveBlockchainServices())
|
|
36
|
-
exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
|
|
37
|
-
return this.bsList.some(bs => bs.validateWif(wif));
|
|
38
|
-
}
|
|
39
|
-
validateEncryptedKeyAllBlockchains(encryptedKey) {
|
|
40
|
-
if (this.haveBlockchainServices())
|
|
41
|
-
exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
|
|
42
|
-
return this.bsList.some(bs => bs.validateEncryptedKey(encryptedKey));
|
|
43
|
-
}
|
|
44
|
-
getBlockchainByAddress(address) {
|
|
45
|
-
var _a;
|
|
46
|
-
if (this.haveBlockchainServices())
|
|
47
|
-
exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
|
|
48
|
-
return (_a = this.bsList.find(bs => bs.validateAddress(address))) !== null && _a !== void 0 ? _a : null;
|
|
49
|
-
}
|
|
50
|
-
getBlockchainByWif(wif) {
|
|
51
|
-
var _a;
|
|
52
|
-
if (this.haveBlockchainServices())
|
|
53
|
-
exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
|
|
54
|
-
return (_a = this.bsList.find(bs => bs.validateWif(wif))) !== null && _a !== void 0 ? _a : null;
|
|
55
|
-
}
|
|
56
|
-
getBlockchainByEncryptedKey(encryptedKey) {
|
|
57
|
-
var _a;
|
|
58
|
-
if (this.haveBlockchainServices())
|
|
59
|
-
exceptions_1.exceptions.invalidBlockchainService(JSON.stringify(this.blockchainservices));
|
|
60
|
-
return (_a = this.bsList.find(bs => bs.validateEncryptedKey(encryptedKey))) !== null && _a !== void 0 ? _a : null;
|
|
61
|
-
}
|
|
62
|
-
getBlockchainsClaimable() {
|
|
63
|
-
const methodName = { claim: 'claim', getUnclaimed: 'getUnclaimed', tokenClaim: 'tokenClaim' };
|
|
64
|
-
const claimableBlockchains = this.bsList.filter(blockchain => methodName.claim in blockchain &&
|
|
65
|
-
methodName.getUnclaimed in blockchain.dataService &&
|
|
66
|
-
methodName.tokenClaim in blockchain);
|
|
67
|
-
return claimableBlockchains;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.BSAgreggator = BSAgreggator;
|
|
@@ -1,37 +0,0 @@
|
|
|
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.Flamingo = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const FlamingoRoutes_1 = require("./FlamingoRoutes");
|
|
18
|
-
class Flamingo {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.request = axios_1.default.create({ baseURL: 'https://api.flamingo.finance' });
|
|
21
|
-
}
|
|
22
|
-
getTokenPrices(currency) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const { data: prices } = yield this.request.get(`/${FlamingoRoutes_1.FLAMINGO_TOKENINFO_PRICES}`);
|
|
25
|
-
let currencyRatio = 1;
|
|
26
|
-
if (currency !== 'USD') {
|
|
27
|
-
const { data } = yield this.request.get(`/${(0, FlamingoRoutes_1.FLAMINGO_FIAT_EXCHANGE_RATE)('USD', currency)}`);
|
|
28
|
-
currencyRatio = data;
|
|
29
|
-
}
|
|
30
|
-
return prices.map(price => ({
|
|
31
|
-
amount: price.usd_price * currencyRatio,
|
|
32
|
-
Symbol: price.symbol
|
|
33
|
-
}));
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.Flamingo = Flamingo;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FLAMINGO_FIAT_EXCHANGE_RATE = exports.FLAMINGO_TOKENINFO_PRICES = void 0;
|
|
4
|
-
exports.FLAMINGO_TOKENINFO_PRICES = 'token-info/prices';
|
|
5
|
-
const FLAMINGO_FIAT_EXCHANGE_RATE = (currencyFrom, currencyTo) => {
|
|
6
|
-
return `fiat/exchange-rate?pair=${currencyFrom}_${currencyTo}`;
|
|
7
|
-
};
|
|
8
|
-
exports.FLAMINGO_FIAT_EXCHANGE_RATE = FLAMINGO_FIAT_EXCHANGE_RATE;
|
package/dist/exchanges/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.exchangeOptions = void 0;
|
|
18
|
-
__exportStar(require("./flamingo/Flamingo"), exports);
|
|
19
|
-
__exportStar(require("./flamingo/FlamingoResponses"), exports);
|
|
20
|
-
__exportStar(require("./flamingo/FlamingoRoutes"), exports);
|
|
21
|
-
const Flamingo_1 = require("./flamingo/Flamingo");
|
|
22
|
-
exports.exchangeOptions = {
|
|
23
|
-
flamingo: new Flamingo_1.Flamingo()
|
|
24
|
-
};
|