@cityofzion/blockchain-service 1.16.3 → 1.17.1
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/BSCommonConstants.d.ts +3 -0
- package/dist/constants/BSCommonConstants.js +7 -0
- package/dist/functions.d.ts +6 -2
- package/dist/functions.js +8 -2
- package/dist/helpers/BSFullTransactionsByAddressHelper.d.ts +4 -0
- package/dist/helpers/BSFullTransactionsByAddressHelper.js +25 -0
- package/dist/helpers/BSPromisesHelper.d.ts +3 -0
- package/dist/helpers/BSPromisesHelper.js +26 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -1
- package/dist/interfaces.d.ts +54 -0
- package/dist/{CryptoCompareEDS.d.ts → services/exchange-data/CryptoCompareEDS.d.ts} +1 -1
- package/dist/{CryptoCompareEDS.js → services/exchange-data/CryptoCompareEDS.js} +1 -4
- package/dist/services/exchange-data/FlamingoForthewinEDS.d.ts +8 -0
- package/dist/services/exchange-data/FlamingoForthewinEDS.js +68 -0
- package/package.json +3 -2
package/dist/functions.d.ts
CHANGED
|
@@ -19,7 +19,11 @@ export declare function waitForAccountTransaction<BSName extends string = string
|
|
|
19
19
|
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>[]>;
|
|
20
20
|
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>[]>;
|
|
21
21
|
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>[]>>;
|
|
22
|
-
|
|
22
|
+
type NormalizedHashOptions = {
|
|
23
|
+
lowercase?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare function normalizeHash(hash: string, options?: NormalizedHashOptions): string;
|
|
23
26
|
export declare function denormalizeHash(hash: string): string;
|
|
24
27
|
export declare function countDecimals(value: string | number): number;
|
|
25
|
-
export declare function formatNumber(value
|
|
28
|
+
export declare function formatNumber(value?: string | number, decimals?: number): string;
|
|
29
|
+
export {};
|
package/dist/functions.js
CHANGED
|
@@ -140,8 +140,12 @@ function generateAccountForBlockchainService(blockchainServices, getAccountCallb
|
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
exports.generateAccountForBlockchainService = generateAccountForBlockchainService;
|
|
143
|
-
function normalizeHash(hash) {
|
|
144
|
-
|
|
143
|
+
function normalizeHash(hash, options) {
|
|
144
|
+
const { lowercase = true } = options !== null && options !== void 0 ? options : {};
|
|
145
|
+
hash = hash.replace('0x', '');
|
|
146
|
+
if (lowercase)
|
|
147
|
+
hash = hash.toLowerCase();
|
|
148
|
+
return hash;
|
|
145
149
|
}
|
|
146
150
|
exports.normalizeHash = normalizeHash;
|
|
147
151
|
function denormalizeHash(hash) {
|
|
@@ -155,6 +159,8 @@ function countDecimals(value) {
|
|
|
155
159
|
}
|
|
156
160
|
exports.countDecimals = countDecimals;
|
|
157
161
|
function formatNumber(value, decimals = 0) {
|
|
162
|
+
if (!value)
|
|
163
|
+
return '0';
|
|
158
164
|
let newValue = typeof value === 'number' ? value.toFixed(decimals) : value;
|
|
159
165
|
newValue = newValue.replace(/,|\.\.|\.,/g, '.');
|
|
160
166
|
if (decimals === 0) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BSFullTransactionsByAddressHelper = void 0;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
class BSFullTransactionsByAddressHelper {
|
|
6
|
+
static validateFullTransactionsByAddressParams(params) {
|
|
7
|
+
if (!params.dateFrom)
|
|
8
|
+
throw new Error('Missing dateFrom param');
|
|
9
|
+
if (!params.dateTo)
|
|
10
|
+
throw new Error('Missing dateTo param');
|
|
11
|
+
const dateFrom = (0, date_fns_1.parseISO)(params.dateFrom);
|
|
12
|
+
const dateTo = (0, date_fns_1.parseISO)(params.dateTo);
|
|
13
|
+
if (!(0, date_fns_1.isValid)(dateFrom))
|
|
14
|
+
throw new Error('Invalid dateFrom param');
|
|
15
|
+
if (!(0, date_fns_1.isValid)(dateTo))
|
|
16
|
+
throw new Error('Invalid dateTo param');
|
|
17
|
+
if ((0, date_fns_1.isFuture)(dateFrom) || (0, date_fns_1.isFuture)(dateTo))
|
|
18
|
+
throw new Error('The dateFrom and/or dateTo are in future');
|
|
19
|
+
if ((0, date_fns_1.isAfter)(dateFrom, dateTo))
|
|
20
|
+
throw new Error('Invalid date order because dateFrom is greater than dateTo');
|
|
21
|
+
if ((0, date_fns_1.differenceInYears)(dateTo, dateFrom) >= 1)
|
|
22
|
+
throw new Error('Date range greater than one year');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.BSFullTransactionsByAddressHelper = BSFullTransactionsByAddressHelper;
|
|
@@ -0,0 +1,26 @@
|
|
|
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.BSPromisesHelper = void 0;
|
|
13
|
+
class BSPromisesHelper {
|
|
14
|
+
static tryCatch(callback) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
const result = yield callback();
|
|
18
|
+
return [result, null];
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return [null, error];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.BSPromisesHelper = BSPromisesHelper;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
export * from './constants/BSCommonConstants';
|
|
2
|
+
export * from './helpers/BSFullTransactionsByAddressHelper';
|
|
3
|
+
export * from './helpers/BSPromisesHelper';
|
|
4
|
+
export * from './services/exchange-data/CryptoCompareEDS';
|
|
5
|
+
export * from './services/exchange-data/FlamingoForthewinEDS';
|
|
1
6
|
export * from './BSAggregator';
|
|
2
|
-
export * from './CryptoCompareEDS';
|
|
3
7
|
export * from './functions';
|
|
4
8
|
export * from './interfaces';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants/BSCommonConstants"), exports);
|
|
18
|
+
__exportStar(require("./helpers/BSFullTransactionsByAddressHelper"), exports);
|
|
19
|
+
__exportStar(require("./helpers/BSPromisesHelper"), exports);
|
|
20
|
+
__exportStar(require("./services/exchange-data/CryptoCompareEDS"), exports);
|
|
21
|
+
__exportStar(require("./services/exchange-data/FlamingoForthewinEDS"), exports);
|
|
17
22
|
__exportStar(require("./BSAggregator"), exports);
|
|
18
|
-
__exportStar(require("./CryptoCompareEDS"), exports);
|
|
19
23
|
__exportStar(require("./functions"), exports);
|
|
20
24
|
__exportStar(require("./interfaces"), exports);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -118,6 +118,57 @@ export type TransactionsByAddressParams = {
|
|
|
118
118
|
address: string;
|
|
119
119
|
nextPageParams?: any;
|
|
120
120
|
};
|
|
121
|
+
export type FullTransactionsByAddressParams = {
|
|
122
|
+
address: string;
|
|
123
|
+
dateFrom: string;
|
|
124
|
+
dateTo: string;
|
|
125
|
+
nextCursor?: string;
|
|
126
|
+
};
|
|
127
|
+
export type FullTransactionNftEvent = {
|
|
128
|
+
eventType: 'nft';
|
|
129
|
+
amount: string;
|
|
130
|
+
methodName: string;
|
|
131
|
+
hash: string;
|
|
132
|
+
hashUrl?: string;
|
|
133
|
+
to?: string;
|
|
134
|
+
toUrl?: string;
|
|
135
|
+
from?: string;
|
|
136
|
+
fromUrl?: string;
|
|
137
|
+
tokenType: 'generic' | (string & NonNullable<unknown>);
|
|
138
|
+
tokenId?: string;
|
|
139
|
+
nftImageUrl?: string;
|
|
140
|
+
nftUrl?: string;
|
|
141
|
+
name?: string;
|
|
142
|
+
collectionName?: string;
|
|
143
|
+
};
|
|
144
|
+
export type FullTransactionAssetEvent = {
|
|
145
|
+
eventType: 'token';
|
|
146
|
+
amount: string;
|
|
147
|
+
methodName: string;
|
|
148
|
+
hash: string;
|
|
149
|
+
hashUrl?: string;
|
|
150
|
+
to?: string;
|
|
151
|
+
toUrl?: string;
|
|
152
|
+
from?: string;
|
|
153
|
+
fromUrl?: string;
|
|
154
|
+
token?: Token;
|
|
155
|
+
tokenType: 'generic' | (string & NonNullable<unknown>);
|
|
156
|
+
};
|
|
157
|
+
export type FullTransactionsItem = {
|
|
158
|
+
txId: string;
|
|
159
|
+
txIdUrl?: string;
|
|
160
|
+
block: number;
|
|
161
|
+
date: string;
|
|
162
|
+
invocationCount: number;
|
|
163
|
+
notificationCount: number;
|
|
164
|
+
networkFeeAmount: string;
|
|
165
|
+
systemFeeAmount: string;
|
|
166
|
+
events: (FullTransactionAssetEvent | FullTransactionNftEvent)[];
|
|
167
|
+
};
|
|
168
|
+
export type FullTransactionsByAddressResponse = {
|
|
169
|
+
nextCursor?: string;
|
|
170
|
+
data: FullTransactionsItem[];
|
|
171
|
+
};
|
|
121
172
|
export type ContractMethod = {
|
|
122
173
|
name: string;
|
|
123
174
|
parameters: ContractParameter[];
|
|
@@ -140,6 +191,7 @@ export interface BlockchainDataService {
|
|
|
140
191
|
maxTimeToConfirmTransactionInMs: number;
|
|
141
192
|
getTransaction(txid: string): Promise<TransactionResponse>;
|
|
142
193
|
getTransactionsByAddress(params: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
|
|
194
|
+
getFullTransactionsByAddress(params: FullTransactionsByAddressParams): Promise<FullTransactionsByAddressResponse>;
|
|
143
195
|
getContract(contractHash: string): Promise<ContractResponse>;
|
|
144
196
|
getTokenInfo(tokenHash: string): Promise<Token>;
|
|
145
197
|
getBalance(address: string): Promise<BalanceResponse[]>;
|
|
@@ -219,6 +271,8 @@ export interface ExplorerService {
|
|
|
219
271
|
buildNftUrl(params: BuildNftUrlParams): string;
|
|
220
272
|
getAddressTemplateUrl(): string | undefined;
|
|
221
273
|
getTxTemplateUrl(): string | undefined;
|
|
274
|
+
getNftTemplateUrl(): string | undefined;
|
|
275
|
+
getContractTemplateUrl(): string | undefined;
|
|
222
276
|
}
|
|
223
277
|
export type LedgerServiceEmitter = TypedEmitter<{
|
|
224
278
|
getSignatureStart(): void | Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExchangeDataService, GetTokenPriceHistoryParams, GetTokenPricesParams, TokenPricesHistoryResponse, TokenPricesResponse } from '
|
|
1
|
+
import { ExchangeDataService, GetTokenPriceHistoryParams, GetTokenPricesParams, TokenPricesHistoryResponse, TokenPricesResponse } from '../../interfaces';
|
|
2
2
|
export declare class CryptoCompareEDS implements ExchangeDataService {
|
|
3
3
|
#private;
|
|
4
4
|
constructor();
|
|
@@ -42,10 +42,7 @@ class CryptoCompareEDS {
|
|
|
42
42
|
return Object.entries(prices.RAW).map(([symbol, priceObject]) => {
|
|
43
43
|
const usdPrice = priceObject.USD.PRICE;
|
|
44
44
|
const token = params.tokens.find(token => token.symbol === symbol);
|
|
45
|
-
return {
|
|
46
|
-
usdPrice,
|
|
47
|
-
token,
|
|
48
|
-
};
|
|
45
|
+
return { usdPrice, token };
|
|
49
46
|
});
|
|
50
47
|
});
|
|
51
48
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExchangeDataService, GetTokenPricesParams, TokenPricesResponse } from '../../interfaces';
|
|
2
|
+
import { CryptoCompareEDS } from './CryptoCompareEDS';
|
|
3
|
+
export declare class FlamingoForthewinEDS extends CryptoCompareEDS implements ExchangeDataService {
|
|
4
|
+
#private;
|
|
5
|
+
constructor();
|
|
6
|
+
getTokenPrices({ tokens }: GetTokenPricesParams): Promise<TokenPricesResponse[]>;
|
|
7
|
+
private predicateToken;
|
|
8
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
var _FlamingoForthewinEDS_flamingoAxiosInstance, _FlamingoForthewinEDS_forthewinAxiosInstance;
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.FlamingoForthewinEDS = void 0;
|
|
22
|
+
const axios_1 = __importDefault(require("axios"));
|
|
23
|
+
const CryptoCompareEDS_1 = require("./CryptoCompareEDS");
|
|
24
|
+
const functions_1 = require("../../functions");
|
|
25
|
+
class FlamingoForthewinEDS extends CryptoCompareEDS_1.CryptoCompareEDS {
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
_FlamingoForthewinEDS_flamingoAxiosInstance.set(this, axios_1.default.create({ baseURL: 'https://neo-api.b-cdn.net/flamingo' }));
|
|
29
|
+
_FlamingoForthewinEDS_forthewinAxiosInstance.set(this, axios_1.default.create({ baseURL: 'https://api.forthewin.network' }));
|
|
30
|
+
}
|
|
31
|
+
getTokenPrices({ tokens }) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const { data: flamingoData } = yield __classPrivateFieldGet(this, _FlamingoForthewinEDS_flamingoAxiosInstance, "f").get('/live-data/prices/latest');
|
|
34
|
+
const prices = [];
|
|
35
|
+
const neoToken = tokens.find(({ symbol }) => symbol === 'NEO');
|
|
36
|
+
if (neoToken && !flamingoData.find(this.predicateToken(neoToken)))
|
|
37
|
+
flamingoData.forEach(item => {
|
|
38
|
+
if (item.symbol === 'bNEO')
|
|
39
|
+
flamingoData.push(Object.assign(Object.assign({}, item), { symbol: neoToken.symbol, hash: neoToken.hash }));
|
|
40
|
+
});
|
|
41
|
+
flamingoData.forEach(item => {
|
|
42
|
+
const token = tokens.find(this.predicateToken(item));
|
|
43
|
+
if (!token)
|
|
44
|
+
return;
|
|
45
|
+
prices.push({ usdPrice: item.usd_price, token });
|
|
46
|
+
});
|
|
47
|
+
if (tokens.length > prices.length) {
|
|
48
|
+
const { data: forthewinData } = yield __classPrivateFieldGet(this, _FlamingoForthewinEDS_forthewinAxiosInstance, "f").get('/mainnet/prices');
|
|
49
|
+
Object.entries(forthewinData).forEach(([hash, usdPrice]) => {
|
|
50
|
+
const hasPrice = !!prices.find(({ token }) => this.predicateToken({ hash })(token));
|
|
51
|
+
if (hasPrice)
|
|
52
|
+
return;
|
|
53
|
+
const foundToken = tokens.find(this.predicateToken({ hash }));
|
|
54
|
+
if (!foundToken)
|
|
55
|
+
return;
|
|
56
|
+
prices.push({ usdPrice, token: foundToken });
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return prices;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
predicateToken({ hash, symbol }) {
|
|
63
|
+
const normalizedHash = (0, functions_1.normalizeHash)(hash);
|
|
64
|
+
return (params) => normalizedHash === (0, functions_1.normalizeHash)(params.hash) || (!!symbol && !!params.symbol && symbol === params.symbol);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.FlamingoForthewinEDS = FlamingoForthewinEDS;
|
|
68
|
+
_FlamingoForthewinEDS_flamingoAxiosInstance = new WeakMap(), _FlamingoForthewinEDS_forthewinAxiosInstance = new WeakMap();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/blockchain-service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@ledgerhq/hw-transport": "~6.30.5",
|
|
23
|
-
"axios": "1.
|
|
23
|
+
"axios": "1.8.2",
|
|
24
|
+
"date-fns": "~4.1.0"
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|
|
26
27
|
"build": "tsc",
|