@cityofzion/blockchain-service 1.19.2 → 1.20.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.
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BSUtilsHelper = void 0;
13
+ const error_1 = require("../error");
13
14
  class BSUtilsHelper {
14
15
  static wait(ms) {
15
16
  return new Promise(resolve => setTimeout(resolve, ms));
@@ -18,19 +19,21 @@ class BSUtilsHelper {
18
19
  const { retries = 50, delay = 100, shouldRetry } = options || {};
19
20
  // eslint-disable-next-line no-async-promise-executor
20
21
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
22
+ let errorMessage = '';
21
23
  for (let i = 0; i < retries; i++) {
22
24
  try {
23
25
  const result = yield callback();
24
26
  return resolve(result);
25
27
  }
26
28
  catch (error) {
29
+ errorMessage = error.message;
27
30
  if (shouldRetry && !shouldRetry(error)) {
28
31
  return reject(error);
29
32
  }
30
33
  }
31
34
  yield this.wait(delay);
32
35
  }
33
- return reject(new Error('timeout'));
36
+ return reject(new error_1.BSError('Timeout: ' + errorMessage, 'TIMEOUT'));
34
37
  }));
35
38
  }
36
39
  }
@@ -104,6 +104,17 @@ export type TransactionTransferNft = {
104
104
  type: 'nft';
105
105
  contractHash: string;
106
106
  };
107
+ type TransactionDefaultResponse = {
108
+ type: 'default';
109
+ };
110
+ export type TransactionBridgeNeo3NeoXResponse = {
111
+ type: 'bridgeNeo3NeoX';
112
+ data: {
113
+ amount: string;
114
+ token: Token;
115
+ receiverAddress: string;
116
+ };
117
+ };
107
118
  export type TransactionResponse = {
108
119
  hash: string;
109
120
  block: number;
@@ -111,7 +122,7 @@ export type TransactionResponse = {
111
122
  transfers: (TransactionTransferAsset | TransactionTransferNft)[];
112
123
  fee?: string;
113
124
  notifications: TransactionNotifications[];
114
- };
125
+ } & (TransactionDefaultResponse | TransactionBridgeNeo3NeoXResponse);
115
126
  export type ContractParameter = {
116
127
  name: string;
117
128
  type: string;
@@ -166,6 +177,17 @@ export type FullTransactionAssetEvent = {
166
177
  token?: Token;
167
178
  tokenType: 'generic' | (string & NonNullable<unknown>);
168
179
  };
180
+ type FullTransactionsItemDefault = {
181
+ type: 'default';
182
+ };
183
+ export type FullTransactionsItemBridgeNeo3NeoX = {
184
+ type: 'bridgeNeo3NeoX';
185
+ data: {
186
+ amount: string;
187
+ token: Token;
188
+ receiverAddress: string;
189
+ };
190
+ };
169
191
  export type FullTransactionsItem = {
170
192
  txId: string;
171
193
  txIdUrl?: string;
@@ -176,7 +198,7 @@ export type FullTransactionsItem = {
176
198
  networkFeeAmount?: string;
177
199
  systemFeeAmount?: string;
178
200
  events: (FullTransactionAssetEvent | FullTransactionNftEvent)[];
179
- };
201
+ } & (FullTransactionsItemDefault | FullTransactionsItemBridgeNeo3NeoX);
180
202
  export type FullTransactionsByAddressResponse = {
181
203
  nextCursor?: string;
182
204
  data: FullTransactionsItem[];
@@ -360,8 +382,9 @@ export interface ISwapOrchestrator<BSName extends string = string> {
360
382
  swap(): Promise<TSwapResult>;
361
383
  calculateFee(): Promise<string>;
362
384
  }
363
- export type TBridgeToken = Token & {
385
+ export type TBridgeToken<BSName extends string = string> = Token & {
364
386
  multichainId: string;
387
+ blockchain: BSName;
365
388
  };
366
389
  export type TBridgeValue<T> = {
367
390
  value: T | null;
@@ -376,24 +399,23 @@ export type TBridgeOrchestratorEvents<BSName extends string = string> = {
376
399
  amountToUse: (amount: TBridgeValidateValue<string>) => void | Promise<void>;
377
400
  amountToUseMin: (max: TBridgeValue<string>) => void | Promise<void>;
378
401
  amountToUseMax: (max: TBridgeValue<string>) => void | Promise<void>;
379
- tokenToUse: (token: TBridgeValue<TBridgeToken>) => void | Promise<void>;
380
- availableTokensToUse: (tokens: TBridgeValue<TBridgeToken[]>) => void | Promise<void>;
402
+ tokenToUse: (token: TBridgeValue<TBridgeToken<BSName>>) => void | Promise<void>;
403
+ availableTokensToUse: (tokens: TBridgeValue<TBridgeToken<BSName>[]>) => void | Promise<void>;
381
404
  addressToReceive: (account: TBridgeValidateValue<string>) => void | Promise<void>;
382
405
  amountToReceive: (amount: TBridgeValue<string>) => void | Promise<void>;
383
- tokenToReceive: (token: TBridgeValue<TBridgeToken>) => void | Promise<void>;
406
+ tokenToReceive: (token: TBridgeValue<TBridgeToken<BSName>>) => void | Promise<void>;
384
407
  tokenToUseBalance: (balance: TBridgeValue<BalanceResponse | undefined>) => void | Promise<void>;
385
408
  bridgeFee: (fee: TBridgeValue<string>) => void | Promise<void>;
386
409
  };
387
410
  export interface IBridgeOrchestrator<BSName extends string = string> {
388
411
  eventEmitter: TypedEmitter<TBridgeOrchestratorEvents<BSName>>;
389
- setTokenToUse(token: TBridgeToken | null): Promise<void>;
412
+ setTokenToUse(token: TBridgeToken<BSName> | null): Promise<void>;
390
413
  setAccountToUse(account: Account<BSName> | null): Promise<void>;
391
414
  setAmountToUse(amount: string | null): Promise<void>;
392
415
  setAddressToReceive(address: string | null): Promise<void>;
393
416
  setBalances(balances: BalanceResponse[] | null): Promise<void>;
394
417
  switchTokens(): Promise<void>;
395
418
  bridge(): Promise<string>;
396
- wait(): Promise<boolean>;
397
419
  }
398
420
  export interface IBSWithNeo3NeoXBridge<BSName extends string = string> {
399
421
  neo3NeoXBridgeService: INeo3NeoXBridgeService<BSName>;
@@ -407,27 +429,28 @@ export type TNeo3NeoXBridgeServiceBridgeParam<BSName extends string = string> =
407
429
  account: Account<BSName>;
408
430
  receiverAddress: string;
409
431
  amount: string;
410
- token: TBridgeToken;
432
+ token: TBridgeToken<BSName>;
411
433
  bridgeFee: string;
412
434
  };
413
435
  export type TNeo3NeoXBridgeServiceGetApprovalParam<BSName extends string = string> = {
414
436
  account: Account<BSName>;
415
437
  amount: string;
416
- token: TBridgeToken;
438
+ token: TBridgeToken<BSName>;
417
439
  };
418
- export type TNeo3NeoXBridgeServiceGetNonceParams = {
419
- token: TBridgeToken;
440
+ export type TNeo3NeoXBridgeServiceGetNonceParams<BSName extends string = string> = {
441
+ token: TBridgeToken<BSName>;
420
442
  transactionHash: string;
421
443
  };
422
- export type TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams = {
423
- token: TBridgeToken;
444
+ export type TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<BSName extends string = string> = {
445
+ token: TBridgeToken<BSName>;
424
446
  nonce: string;
425
447
  };
426
448
  export interface INeo3NeoXBridgeService<BSName extends string = string> {
427
- tokens: TBridgeToken[];
449
+ tokens: TBridgeToken<BSName>[];
428
450
  getApprovalFee(params: TNeo3NeoXBridgeServiceGetApprovalParam): Promise<string>;
429
451
  getBridgeConstants(token: TBridgeToken): Promise<TNeo3NeoXBridgeServiceConstants>;
430
452
  bridge(params: TNeo3NeoXBridgeServiceBridgeParam<BSName>): Promise<string>;
431
- getNonce(params: TNeo3NeoXBridgeServiceGetNonceParams): Promise<string | null>;
432
- getTransactionHashByNonce(params: TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams): Promise<string | null>;
453
+ getNonce(params: TNeo3NeoXBridgeServiceGetNonceParams<BSName>): Promise<string>;
454
+ getTransactionHashByNonce(params: TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<BSName>): Promise<string>;
433
455
  }
456
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/blockchain-service",
3
- "version": "1.19.2",
3
+ "version": "1.20.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",