@cityofzion/bs-neo-legacy 0.10.6 → 1.0.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.
@@ -1,18 +1,20 @@
1
- import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSClaimable, ExchangeDataService, Token, Network, PartialBy, TransferParam, AccountWithDerivationPath, BSWithExplorerService, ExplorerService } from '@cityofzion/blockchain-service';
2
- export declare class BSNeoLegacy<BSCustomName extends string = string> implements BlockchainService, BSClaimable, BSWithExplorerService {
1
+ import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSClaimable, ExchangeDataService, Token, Network, TransferParam, AccountWithDerivationPath, BSWithExplorerService, ExplorerService } from '@cityofzion/blockchain-service';
2
+ import { AvailableNetworkIds } from './BSNeoLegacyHelper';
3
+ export declare class BSNeoLegacy<BSCustomName extends string = string> implements BlockchainService<BSCustomName, AvailableNetworkIds>, BSClaimable, BSWithExplorerService {
4
+ #private;
3
5
  readonly blockchainName: BSCustomName;
4
- readonly feeToken: Token;
5
- readonly claimToken: Token;
6
- readonly burnToken: Token;
7
6
  readonly derivationPath: string;
7
+ feeToken: Token;
8
+ claimToken: Token;
9
+ burnToken: Token;
8
10
  blockchainDataService: BlockchainDataService & BDSClaimable;
9
11
  exchangeDataService: ExchangeDataService;
10
12
  explorerService: ExplorerService;
11
13
  tokens: Token[];
12
- network: Network;
14
+ network: Network<AvailableNetworkIds>;
13
15
  legacyNetwork: string;
14
- constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>);
15
- setNetwork(param: PartialBy<Network, 'url'>): void;
16
+ constructor(blockchainName: BSCustomName, network?: Network<AvailableNetworkIds>);
17
+ setNetwork(network: Network<AvailableNetworkIds>): void;
16
18
  validateAddress(address: string): boolean;
17
19
  validateEncrypted(key: string): boolean;
18
20
  validateKey(key: string): boolean;
@@ -8,6 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
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
+ };
11
16
  var __rest = (this && this.__rest) || function (s, e) {
12
17
  var t = {};
13
18
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -19,39 +24,30 @@ var __rest = (this && this.__rest) || function (s, e) {
19
24
  }
20
25
  return t;
21
26
  };
27
+ var _BSNeoLegacy_instances, _BSNeoLegacy_setTokens;
22
28
  Object.defineProperty(exports, "__esModule", { value: true });
23
29
  exports.BSNeoLegacy = void 0;
24
30
  const neon_js_1 = require("@cityofzion/neon-js");
25
- const constants_1 = require("./constants");
26
31
  const DoraBDSNeoLegacy_1 = require("./DoraBDSNeoLegacy");
27
32
  const CryptoCompareEDSNeoLegacy_1 = require("./CryptoCompareEDSNeoLegacy");
28
33
  const bs_asteroid_sdk_1 = require("@cityofzion/bs-asteroid-sdk");
29
- const DoraESNeoLegacy_1 = require("./DoraESNeoLegacy");
34
+ const BSNeoLegacyHelper_1 = require("./BSNeoLegacyHelper");
35
+ const NeoTubeESNeoLegacy_1 = require("./NeoTubeESNeoLegacy");
30
36
  class BSNeoLegacy {
31
37
  constructor(blockchainName, network) {
32
- if (network.type === 'custom')
33
- throw new Error('Custom network is not supported for NEO Legacy');
38
+ _BSNeoLegacy_instances.add(this);
39
+ network = network !== null && network !== void 0 ? network : BSNeoLegacyHelper_1.BSNeoLegacyHelper.DEFAULT_NETWORK;
34
40
  this.blockchainName = blockchainName;
35
- this.legacyNetwork = constants_1.LEGACY_NETWORK_BY_NETWORK_TYPE[network.type];
36
- this.derivationPath = constants_1.DERIVATION_PATH;
37
- this.tokens = constants_1.TOKENS[network.type];
38
- this.claimToken = this.tokens.find(token => token.symbol === 'GAS');
39
- this.burnToken = this.tokens.find(token => token.symbol === 'NEO');
40
- this.feeToken = this.tokens.find(token => token.symbol === 'GAS');
41
+ this.legacyNetwork = BSNeoLegacyHelper_1.BSNeoLegacyHelper.LEGACY_NETWORK_BY_NETWORK_ID[network.id];
42
+ this.derivationPath = BSNeoLegacyHelper_1.BSNeoLegacyHelper.DERIVATION_PATH;
41
43
  this.setNetwork(network);
42
44
  }
43
- setNetwork(param) {
44
- var _a;
45
- if (param.type === 'custom')
46
- throw new Error('Custom network is not supported for NEO Legacy');
47
- const network = {
48
- type: param.type,
49
- url: (_a = param.url) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.type],
50
- };
45
+ setNetwork(network) {
46
+ __classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_setTokens).call(this, network);
51
47
  this.network = network;
52
- this.blockchainDataService = new DoraBDSNeoLegacy_1.DoraBDSNeoLegacy(network, this.feeToken, this.claimToken);
53
- this.exchangeDataService = new CryptoCompareEDSNeoLegacy_1.CryptoCompareEDSNeoLegacy(network.type);
54
- this.explorerService = new DoraESNeoLegacy_1.DoraESNeoLegacy(network.type);
48
+ this.blockchainDataService = new DoraBDSNeoLegacy_1.DoraBDSNeoLegacy(network, this.feeToken, this.claimToken, this.tokens);
49
+ this.exchangeDataService = new CryptoCompareEDSNeoLegacy_1.CryptoCompareEDSNeoLegacy(network.id, this.tokens);
50
+ this.explorerService = new NeoTubeESNeoLegacy_1.NeoTubeESNeoLegacy(network.id);
55
51
  }
56
52
  validateAddress(address) {
57
53
  return neon_js_1.wallet.isAddress(address);
@@ -98,7 +94,7 @@ class BSNeoLegacy {
98
94
  const intents = [transferIntent, ...(tipIntent ? [tipIntent] : [])];
99
95
  for (const intent of intents) {
100
96
  const tokenHashFixed = intent.tokenHash.replace('0x', '');
101
- const nativeAsset = constants_1.NATIVE_ASSETS.find(asset => asset.hash === tokenHashFixed);
97
+ const nativeAsset = BSNeoLegacyHelper_1.BSNeoLegacyHelper.NATIVE_ASSETS.find(asset => asset.hash === tokenHashFixed);
102
98
  if (nativeAsset) {
103
99
  nativeIntents.push(...neon_js_1.api.makeIntent({ [nativeAsset.symbol]: Number(intent.amount) }, intent.receiverAddress));
104
100
  continue;
@@ -162,3 +158,10 @@ class BSNeoLegacy {
162
158
  }
163
159
  }
164
160
  exports.BSNeoLegacy = BSNeoLegacy;
161
+ _BSNeoLegacy_instances = new WeakSet(), _BSNeoLegacy_setTokens = function _BSNeoLegacy_setTokens(network) {
162
+ const tokens = BSNeoLegacyHelper_1.BSNeoLegacyHelper.getTokens(network);
163
+ this.tokens = tokens;
164
+ this.feeToken = tokens.find(token => token.symbol === 'GAS');
165
+ this.burnToken = tokens.find(token => token.symbol === 'NEO');
166
+ this.claimToken = tokens.find(token => token.symbol === 'GAS');
167
+ };
@@ -0,0 +1,27 @@
1
+ import { Network } from '@cityofzion/blockchain-service';
2
+ export type AvailableNetworkIds = 'mainnet' | 'testnet';
3
+ export declare class BSNeoLegacyHelper {
4
+ #private;
5
+ static NATIVE_ASSETS: {
6
+ symbol: string;
7
+ name: string;
8
+ hash: string;
9
+ decimals: number;
10
+ }[];
11
+ static LEGACY_NETWORK_BY_NETWORK_ID: Record<AvailableNetworkIds, string>;
12
+ static MAINNET_NETWORK_IDS: AvailableNetworkIds[];
13
+ static TESTNET_NETWORK_IDS: AvailableNetworkIds[];
14
+ static ALL_NETWORK_IDS: AvailableNetworkIds[];
15
+ static MAINNET_NETWORKS: Network<AvailableNetworkIds>[];
16
+ static TESTNET_NETWORKS: Network<AvailableNetworkIds>[];
17
+ static ALL_NETWORKS: Network<AvailableNetworkIds>[];
18
+ static DERIVATION_PATH: string;
19
+ static DEFAULT_NETWORK: Network<AvailableNetworkIds>;
20
+ static getTokens(network: Network<AvailableNetworkIds>): {
21
+ symbol: string;
22
+ name: string;
23
+ hash: string;
24
+ decimals: number;
25
+ }[];
26
+ static getRpcList(network: Network<AvailableNetworkIds>): string[];
27
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ var _a, _BSNeoLegacyHelper_EXTRA_TOKENS_BY_NETWORK_ID, _BSNeoLegacyHelper_RPC_LIST_BY_NETWORK_ID;
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BSNeoLegacyHelper = void 0;
13
+ const common_json_1 = __importDefault(require("./assets/tokens/common.json"));
14
+ const mainnet_json_1 = __importDefault(require("./assets/tokens/mainnet.json"));
15
+ class BSNeoLegacyHelper {
16
+ static getTokens(network) {
17
+ var _b;
18
+ const extraTokens = (_b = __classPrivateFieldGet(this, _a, "f", _BSNeoLegacyHelper_EXTRA_TOKENS_BY_NETWORK_ID)[network.id]) !== null && _b !== void 0 ? _b : [];
19
+ return [...extraTokens, ...common_json_1.default];
20
+ }
21
+ static getRpcList(network) {
22
+ var _b;
23
+ return (_b = __classPrivateFieldGet(this, _a, "f", _BSNeoLegacyHelper_RPC_LIST_BY_NETWORK_ID)[network.id]) !== null && _b !== void 0 ? _b : [];
24
+ }
25
+ }
26
+ exports.BSNeoLegacyHelper = BSNeoLegacyHelper;
27
+ _a = BSNeoLegacyHelper;
28
+ _BSNeoLegacyHelper_EXTRA_TOKENS_BY_NETWORK_ID = { value: {
29
+ mainnet: mainnet_json_1.default,
30
+ } };
31
+ BSNeoLegacyHelper.NATIVE_ASSETS = common_json_1.default;
32
+ _BSNeoLegacyHelper_RPC_LIST_BY_NETWORK_ID = { value: {
33
+ mainnet: [
34
+ 'http://seed9.ngd.network:10332',
35
+ 'https://mainnet1.neo2.coz.io:443',
36
+ 'https://mainnet2.neo2.coz.io:443',
37
+ 'https://mainnet3.neo2.coz.io:443',
38
+ 'http://seed1.ngd.network:10332',
39
+ 'http://seed2.ngd.network:10332',
40
+ 'http://seed3.ngd.network:10332',
41
+ 'http://seed4.ngd.network:10332',
42
+ 'http://seed5.ngd.network:10332',
43
+ ],
44
+ testnet: [
45
+ 'http://seed5.ngd.network:20332',
46
+ 'http://seed1.ngd.network:20332',
47
+ 'http://seed2.ngd.network:20332',
48
+ 'https://testnet1.neo2.coz.io:443',
49
+ ],
50
+ } };
51
+ BSNeoLegacyHelper.LEGACY_NETWORK_BY_NETWORK_ID = {
52
+ mainnet: 'MainNet',
53
+ testnet: 'TestNet',
54
+ };
55
+ BSNeoLegacyHelper.MAINNET_NETWORK_IDS = ['mainnet'];
56
+ BSNeoLegacyHelper.TESTNET_NETWORK_IDS = ['testnet'];
57
+ BSNeoLegacyHelper.ALL_NETWORK_IDS = [..._a.MAINNET_NETWORK_IDS, ..._a.TESTNET_NETWORK_IDS];
58
+ BSNeoLegacyHelper.MAINNET_NETWORKS = [
59
+ {
60
+ id: 'mainnet',
61
+ name: 'Mainnet',
62
+ url: __classPrivateFieldGet(_a, _a, "f", _BSNeoLegacyHelper_RPC_LIST_BY_NETWORK_ID)['mainnet'][0],
63
+ },
64
+ ];
65
+ BSNeoLegacyHelper.TESTNET_NETWORKS = [
66
+ {
67
+ id: 'testnet',
68
+ name: 'Testnet',
69
+ url: __classPrivateFieldGet(_a, _a, "f", _BSNeoLegacyHelper_RPC_LIST_BY_NETWORK_ID)['testnet'][0],
70
+ },
71
+ ];
72
+ BSNeoLegacyHelper.ALL_NETWORKS = [..._a.MAINNET_NETWORKS, ..._a.TESTNET_NETWORKS];
73
+ BSNeoLegacyHelper.DERIVATION_PATH = "m/44'/888'/0'/0/?";
74
+ BSNeoLegacyHelper.DEFAULT_NETWORK = _a.MAINNET_NETWORKS[0];
@@ -1,4 +1,8 @@
1
- import { CryptoCompareEDS, ExchangeDataService, NetworkType } from '@cityofzion/blockchain-service';
1
+ import { CryptoCompareEDS, Currency, ExchangeDataService, GetTokenPriceHistory, Token, TokenPricesHistoryResponse, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
+ import { AvailableNetworkIds } from './BSNeoLegacyHelper';
2
3
  export declare class CryptoCompareEDSNeoLegacy extends CryptoCompareEDS implements ExchangeDataService {
3
- constructor(networkType: NetworkType);
4
+ #private;
5
+ constructor(networkId: AvailableNetworkIds, tokens: Token[]);
6
+ getTokenPriceHistory(params: GetTokenPriceHistory): Promise<TokenPricesHistoryResponse[]>;
7
+ getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
4
8
  }
@@ -1,11 +1,35 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ 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");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _CryptoCompareEDSNeoLegacy_networkId;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.CryptoCompareEDSNeoLegacy = void 0;
4
16
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
5
- const constants_1 = require("./constants");
6
17
  class CryptoCompareEDSNeoLegacy extends blockchain_service_1.CryptoCompareEDS {
7
- constructor(networkType) {
8
- super(networkType, constants_1.TOKENS[networkType]);
18
+ constructor(networkId, tokens) {
19
+ super(tokens);
20
+ _CryptoCompareEDSNeoLegacy_networkId.set(this, void 0);
21
+ __classPrivateFieldSet(this, _CryptoCompareEDSNeoLegacy_networkId, networkId, "f");
22
+ }
23
+ getTokenPriceHistory(params) {
24
+ if (__classPrivateFieldGet(this, _CryptoCompareEDSNeoLegacy_networkId, "f") !== 'mainnet')
25
+ throw new Error('Exchange is only available on mainnet');
26
+ return super.getTokenPriceHistory(params);
27
+ }
28
+ getTokenPrices(currency) {
29
+ if (__classPrivateFieldGet(this, _CryptoCompareEDSNeoLegacy_networkId, "f") !== 'mainnet')
30
+ throw new Error('Exchange is only available on mainnet');
31
+ return super.getTokenPrices(currency);
9
32
  }
10
33
  }
11
34
  exports.CryptoCompareEDSNeoLegacy = CryptoCompareEDSNeoLegacy;
35
+ _CryptoCompareEDSNeoLegacy_networkId = new WeakMap();
@@ -1,8 +1,9 @@
1
1
  import { BalanceResponse, BlockchainDataService, ContractResponse, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, BDSClaimable, Token, Network, RpcResponse } from '@cityofzion/blockchain-service';
2
+ import { AvailableNetworkIds } from './BSNeoLegacyHelper';
2
3
  export declare class DoraBDSNeoLegacy implements BlockchainDataService, BDSClaimable {
3
4
  #private;
4
5
  maxTimeToConfirmTransactionInMs: number;
5
- constructor(network: Network, feeToken: Token, claimToken: Token);
6
+ constructor(network: Network<AvailableNetworkIds>, feeToken: Token, claimToken: Token, tokens: Token[]);
6
7
  getTransaction(hash: string): Promise<TransactionResponse>;
7
8
  getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
8
9
  getContract(contractHash: string): Promise<ContractResponse>;
@@ -19,29 +19,29 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
19
19
  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");
20
20
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
21
  };
22
- var _DoraBDSNeoLegacy_network, _DoraBDSNeoLegacy_claimToken, _DoraBDSNeoLegacy_feeToken, _DoraBDSNeoLegacy_tokenCache;
22
+ var _DoraBDSNeoLegacy_network, _DoraBDSNeoLegacy_claimToken, _DoraBDSNeoLegacy_feeToken, _DoraBDSNeoLegacy_tokens, _DoraBDSNeoLegacy_tokenCache;
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.DoraBDSNeoLegacy = void 0;
25
25
  const dora_ts_1 = require("@cityofzion/dora-ts");
26
- const constants_1 = require("./constants");
27
26
  const neon_js_1 = require("@cityofzion/neon-js");
27
+ const BSNeoLegacyHelper_1 = require("./BSNeoLegacyHelper");
28
28
  class DoraBDSNeoLegacy {
29
- constructor(network, feeToken, claimToken) {
29
+ constructor(network, feeToken, claimToken, tokens) {
30
30
  _DoraBDSNeoLegacy_network.set(this, void 0);
31
31
  _DoraBDSNeoLegacy_claimToken.set(this, void 0);
32
32
  _DoraBDSNeoLegacy_feeToken.set(this, void 0);
33
+ _DoraBDSNeoLegacy_tokens.set(this, void 0);
33
34
  _DoraBDSNeoLegacy_tokenCache.set(this, new Map());
34
35
  this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 2;
35
- if (network.type === 'custom')
36
- throw new Error('Custom network is not supported for NEO Legacy');
37
36
  __classPrivateFieldSet(this, _DoraBDSNeoLegacy_network, network, "f");
38
37
  __classPrivateFieldSet(this, _DoraBDSNeoLegacy_claimToken, claimToken, "f");
39
38
  __classPrivateFieldSet(this, _DoraBDSNeoLegacy_feeToken, feeToken, "f");
39
+ __classPrivateFieldSet(this, _DoraBDSNeoLegacy_tokens, tokens, "f");
40
40
  }
41
41
  getTransaction(hash) {
42
42
  var _a, _b, _c;
43
43
  return __awaiter(this, void 0, void 0, function* () {
44
- const data = yield dora_ts_1.api.NeoLegacyREST.transaction(hash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
44
+ const data = yield dora_ts_1.api.NeoLegacyREST.transaction(hash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
45
45
  if (!data || 'error' in data)
46
46
  throw new Error(`Transaction ${hash} not found`);
47
47
  const vout = (_a = data.vout) !== null && _a !== void 0 ? _a : [];
@@ -70,7 +70,7 @@ class DoraBDSNeoLegacy {
70
70
  }
71
71
  getTransactionsByAddress({ address, page = 1, }) {
72
72
  return __awaiter(this, void 0, void 0, function* () {
73
- const data = yield dora_ts_1.api.NeoLegacyREST.getAddressAbstracts(address, page, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
73
+ const data = yield dora_ts_1.api.NeoLegacyREST.getAddressAbstracts(address, page, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
74
74
  const transactions = new Map();
75
75
  const promises = data.entries.map((entry) => __awaiter(this, void 0, void 0, function* () {
76
76
  var _a, _b;
@@ -108,7 +108,7 @@ class DoraBDSNeoLegacy {
108
108
  }
109
109
  getContract(contractHash) {
110
110
  return __awaiter(this, void 0, void 0, function* () {
111
- const response = yield dora_ts_1.api.NeoLegacyREST.contract(contractHash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
111
+ const response = yield dora_ts_1.api.NeoLegacyREST.contract(contractHash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
112
112
  if (!response || 'error' in response)
113
113
  throw new Error(`Contract ${contractHash} not found`);
114
114
  return {
@@ -120,13 +120,13 @@ class DoraBDSNeoLegacy {
120
120
  }
121
121
  getTokenInfo(tokenHash) {
122
122
  return __awaiter(this, void 0, void 0, function* () {
123
- const localToken = constants_1.TOKENS[__classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type].find(token => token.hash === tokenHash);
123
+ const localToken = __classPrivateFieldGet(this, _DoraBDSNeoLegacy_tokens, "f").find(token => token.hash === tokenHash);
124
124
  if (localToken)
125
125
  return localToken;
126
126
  if (__classPrivateFieldGet(this, _DoraBDSNeoLegacy_tokenCache, "f").has(tokenHash)) {
127
127
  return __classPrivateFieldGet(this, _DoraBDSNeoLegacy_tokenCache, "f").get(tokenHash);
128
128
  }
129
- const data = yield dora_ts_1.api.NeoLegacyREST.asset(tokenHash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
129
+ const data = yield dora_ts_1.api.NeoLegacyREST.asset(tokenHash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
130
130
  if (!data || 'error' in data)
131
131
  throw new Error(`Token ${tokenHash} not found`);
132
132
  const token = {
@@ -141,7 +141,7 @@ class DoraBDSNeoLegacy {
141
141
  }
142
142
  getBalance(address) {
143
143
  return __awaiter(this, void 0, void 0, function* () {
144
- const data = yield dora_ts_1.api.NeoLegacyREST.balance(address, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
144
+ const data = yield dora_ts_1.api.NeoLegacyREST.balance(address, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
145
145
  const promises = data.map((balance) => __awaiter(this, void 0, void 0, function* () {
146
146
  const hash = balance.asset.replace('0x', '');
147
147
  let token = {
@@ -167,7 +167,7 @@ class DoraBDSNeoLegacy {
167
167
  }
168
168
  getUnclaimed(address) {
169
169
  return __awaiter(this, void 0, void 0, function* () {
170
- const { unclaimed } = yield dora_ts_1.api.NeoLegacyREST.getUnclaimed(address, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
170
+ const { unclaimed } = yield dora_ts_1.api.NeoLegacyREST.getUnclaimed(address, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
171
171
  return (unclaimed / Math.pow(10, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_claimToken, "f").decimals)).toFixed(__classPrivateFieldGet(this, _DoraBDSNeoLegacy_claimToken, "f").decimals);
172
172
  });
173
173
  }
@@ -180,8 +180,8 @@ class DoraBDSNeoLegacy {
180
180
  getRpcList() {
181
181
  return __awaiter(this, void 0, void 0, function* () {
182
182
  const list = [];
183
- const networkType = __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type;
184
- const promises = constants_1.RPC_LIST_BY_NETWORK_TYPE[networkType].map(url => {
183
+ const urls = BSNeoLegacyHelper_1.BSNeoLegacyHelper.getRpcList(__classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f"));
184
+ const promises = urls.map(url => {
185
185
  // eslint-disable-next-line no-async-promise-executor
186
186
  return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
187
187
  const timeout = setTimeout(() => {
@@ -206,4 +206,4 @@ class DoraBDSNeoLegacy {
206
206
  }
207
207
  }
208
208
  exports.DoraBDSNeoLegacy = DoraBDSNeoLegacy;
209
- _DoraBDSNeoLegacy_network = new WeakMap(), _DoraBDSNeoLegacy_claimToken = new WeakMap(), _DoraBDSNeoLegacy_feeToken = new WeakMap(), _DoraBDSNeoLegacy_tokenCache = new WeakMap();
209
+ _DoraBDSNeoLegacy_network = new WeakMap(), _DoraBDSNeoLegacy_claimToken = new WeakMap(), _DoraBDSNeoLegacy_feeToken = new WeakMap(), _DoraBDSNeoLegacy_tokens = new WeakMap(), _DoraBDSNeoLegacy_tokenCache = new WeakMap();
@@ -0,0 +1,10 @@
1
+ import { BuildNftUrlParams, ExplorerService } from '@cityofzion/blockchain-service';
2
+ import { AvailableNetworkIds } from './BSNeoLegacyHelper';
3
+ export declare class NeoTubeESNeoLegacy implements ExplorerService {
4
+ #private;
5
+ static SUPPORTED_NETWORKS: AvailableNetworkIds[];
6
+ constructor(networkId: AvailableNetworkIds);
7
+ buildTransactionUrl(hash: string): string;
8
+ buildContractUrl(contractHash: string): string;
9
+ buildNftUrl(_params: BuildNftUrlParams): string;
10
+ }
@@ -10,22 +10,28 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  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");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _DoraESNeoLegacy_networkType;
13
+ var _NeoTubeESNeoLegacy_networkId;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.DoraESNeoLegacy = void 0;
16
- class DoraESNeoLegacy {
17
- constructor(networkType) {
18
- _DoraESNeoLegacy_networkType.set(this, void 0);
19
- __classPrivateFieldSet(this, _DoraESNeoLegacy_networkType, networkType, "f");
15
+ exports.NeoTubeESNeoLegacy = void 0;
16
+ class NeoTubeESNeoLegacy {
17
+ constructor(networkId) {
18
+ _NeoTubeESNeoLegacy_networkId.set(this, void 0);
19
+ __classPrivateFieldSet(this, _NeoTubeESNeoLegacy_networkId, networkId, "f");
20
20
  }
21
21
  buildTransactionUrl(hash) {
22
- if (__classPrivateFieldGet(this, _DoraESNeoLegacy_networkType, "f") === 'custom')
23
- throw new Error('DoraESNeoLegacy does not support custom network');
24
- return `https://dora.coz.io/transaction/neo2/${__classPrivateFieldGet(this, _DoraESNeoLegacy_networkType, "f")}/${hash}`;
22
+ if (!NeoTubeESNeoLegacy.SUPPORTED_NETWORKS.includes(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_networkId, "f")))
23
+ throw new Error('Unsupported network');
24
+ return `https://neo2.neotube.io/transaction/${hash}`;
25
+ }
26
+ buildContractUrl(contractHash) {
27
+ if (!NeoTubeESNeoLegacy.SUPPORTED_NETWORKS.includes(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_networkId, "f")))
28
+ throw new Error('Unsupported network');
29
+ return `https://neo2.neotube.io/asset/${contractHash}/page/1`;
25
30
  }
26
31
  buildNftUrl(_params) {
27
32
  throw new Error('DoraESNeoLegacy does not support nft');
28
33
  }
29
34
  }
30
- exports.DoraESNeoLegacy = DoraESNeoLegacy;
31
- _DoraESNeoLegacy_networkType = new WeakMap();
35
+ exports.NeoTubeESNeoLegacy = NeoTubeESNeoLegacy;
36
+ _NeoTubeESNeoLegacy_networkId = new WeakMap();
37
+ NeoTubeESNeoLegacy.SUPPORTED_NETWORKS = ['mainnet'];
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './BSNeoLegacy';
2
2
  export * from './DoraBDSNeoLegacy';
3
- export * from './constants';
3
+ export * from './BSNeoLegacyHelper';
4
+ export * from './NeoTubeESNeoLegacy';
4
5
  export * from './CryptoCompareEDSNeoLegacy';
package/dist/index.js CHANGED
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./BSNeoLegacy"), exports);
18
18
  __exportStar(require("./DoraBDSNeoLegacy"), exports);
19
- __exportStar(require("./constants"), exports);
19
+ __exportStar(require("./BSNeoLegacyHelper"), exports);
20
+ __exportStar(require("./NeoTubeESNeoLegacy"), exports);
20
21
  __exportStar(require("./CryptoCompareEDSNeoLegacy"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo-legacy",
3
- "version": "0.10.6",
3
+ "version": "1.0.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "Coz",
@@ -11,8 +11,8 @@
11
11
  "dependencies": {
12
12
  "@cityofzion/dora-ts": "0.0.11",
13
13
  "@cityofzion/neon-js": "4.8.3",
14
- "@cityofzion/bs-asteroid-sdk": "0.9.0",
15
- "@cityofzion/blockchain-service": "0.13.0"
14
+ "@cityofzion/blockchain-service": "1.0.1",
15
+ "@cityofzion/bs-asteroid-sdk": "0.9.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/jest": "29.5.3",
@@ -1,7 +0,0 @@
1
- import { BuildNftUrlParams, ExplorerService, NetworkType } from '@cityofzion/blockchain-service';
2
- export declare class DoraESNeoLegacy implements ExplorerService {
3
- #private;
4
- constructor(networkType: NetworkType);
5
- buildTransactionUrl(hash: string): string;
6
- buildNftUrl(_params: BuildNftUrlParams): string;
7
- }
@@ -1,12 +0,0 @@
1
- import { NetworkType, Token } from '@cityofzion/blockchain-service';
2
- export declare const TOKENS: Record<NetworkType, Token[]>;
3
- export declare const LEGACY_NETWORK_BY_NETWORK_TYPE: Record<Exclude<NetworkType, 'custom'>, string>;
4
- export declare const NATIVE_ASSETS: {
5
- symbol: string;
6
- name: string;
7
- hash: string;
8
- decimals: number;
9
- }[];
10
- export declare const DERIVATION_PATH = "m/44'/888'/0'/0/?";
11
- export declare const RPC_LIST_BY_NETWORK_TYPE: Record<Exclude<NetworkType, 'custom'>, string[]>;
12
- export declare const DEFAULT_URL_BY_NETWORK_TYPE: Record<Exclude<NetworkType, 'custom'>, string>;
package/dist/constants.js DELETED
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DEFAULT_URL_BY_NETWORK_TYPE = exports.RPC_LIST_BY_NETWORK_TYPE = exports.DERIVATION_PATH = exports.NATIVE_ASSETS = exports.LEGACY_NETWORK_BY_NETWORK_TYPE = exports.TOKENS = void 0;
7
- const common_json_1 = __importDefault(require("./assets/tokens/common.json"));
8
- const mainnet_json_1 = __importDefault(require("./assets/tokens/mainnet.json"));
9
- exports.TOKENS = {
10
- mainnet: [...common_json_1.default, ...mainnet_json_1.default],
11
- testnet: common_json_1.default,
12
- custom: common_json_1.default,
13
- };
14
- exports.LEGACY_NETWORK_BY_NETWORK_TYPE = {
15
- mainnet: 'MainNet',
16
- testnet: 'TestNet',
17
- };
18
- exports.NATIVE_ASSETS = common_json_1.default;
19
- exports.DERIVATION_PATH = "m/44'/888'/0'/0/?";
20
- exports.RPC_LIST_BY_NETWORK_TYPE = {
21
- mainnet: [
22
- 'http://seed9.ngd.network:10332',
23
- 'https://mainnet1.neo2.coz.io:443',
24
- 'https://mainnet2.neo2.coz.io:443',
25
- 'https://mainnet3.neo2.coz.io:443',
26
- 'http://seed1.ngd.network:10332',
27
- 'http://seed2.ngd.network:10332',
28
- 'http://seed3.ngd.network:10332',
29
- 'http://seed4.ngd.network:10332',
30
- 'http://seed5.ngd.network:10332',
31
- ],
32
- testnet: [
33
- 'http://seed5.ngd.network:20332',
34
- 'http://seed1.ngd.network:20332',
35
- 'http://seed2.ngd.network:20332',
36
- 'https://testnet1.neo2.coz.io:443',
37
- ],
38
- };
39
- exports.DEFAULT_URL_BY_NETWORK_TYPE = {
40
- mainnet: exports.RPC_LIST_BY_NETWORK_TYPE.mainnet[0],
41
- testnet: exports.RPC_LIST_BY_NETWORK_TYPE.testnet[0],
42
- };