@cityofzion/bs-ethereum 2.0.3 → 2.1.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.
@@ -8,18 +8,6 @@ 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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
- if (kind === "m") throw new TypeError("Private method is not writable");
13
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
- 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");
15
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
- };
17
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
- };
22
- var _RpcBDSEthereum_network;
23
11
  Object.defineProperty(exports, "__esModule", { value: true });
24
12
  exports.RpcBDSEthereum = void 0;
25
13
  const ethers_1 = require("ethers");
@@ -27,20 +15,20 @@ const ERC20_1 = require("./assets/abis/ERC20");
27
15
  const BSEthereumHelper_1 = require("./BSEthereumHelper");
28
16
  class RpcBDSEthereum {
29
17
  constructor(network) {
30
- _RpcBDSEthereum_network.set(this, void 0);
18
+ this._tokenCache = new Map();
31
19
  this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 5;
32
- __classPrivateFieldSet(this, _RpcBDSEthereum_network, network, "f");
20
+ this._network = network;
33
21
  }
34
22
  getTransaction(hash) {
35
23
  return __awaiter(this, void 0, void 0, function* () {
36
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").url);
24
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
37
25
  const transaction = yield provider.getTransaction(hash);
38
26
  if (!transaction || !transaction.blockHash || !transaction.to)
39
27
  throw new Error('Transaction not found');
40
28
  const block = yield provider.getBlock(transaction.blockHash);
41
29
  if (!block)
42
30
  throw new Error('Block not found');
43
- const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f"));
31
+ const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
44
32
  return {
45
33
  block: block.number,
46
34
  time: block.timestamp,
@@ -64,33 +52,38 @@ class RpcBDSEthereum {
64
52
  throw new Error("RPC doesn't support get transactions history of address");
65
53
  });
66
54
  }
67
- getContract() {
55
+ getContract(_hash) {
68
56
  return __awaiter(this, void 0, void 0, function* () {
69
57
  throw new Error("RPC doesn't support contract info");
70
58
  });
71
59
  }
72
60
  getTokenInfo(hash) {
73
61
  return __awaiter(this, void 0, void 0, function* () {
74
- const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f"));
75
- if (nativeAsset.hash === hash)
62
+ const nativeAsset = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
63
+ if (BSEthereumHelper_1.BSEthereumHelper.normalizeHash(nativeAsset.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(hash))
76
64
  return nativeAsset;
77
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").url);
65
+ if (this._tokenCache.has(hash)) {
66
+ return this._tokenCache.get(hash);
67
+ }
68
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
78
69
  const contract = new ethers_1.ethers.Contract(hash, ERC20_1.ERC20_ABI, provider);
79
70
  const decimals = yield contract.decimals();
80
71
  const symbol = yield contract.symbol();
81
- return {
72
+ const token = {
82
73
  decimals,
83
74
  symbol,
84
75
  hash,
85
76
  name: symbol,
86
77
  };
78
+ this._tokenCache.set(hash, token);
79
+ return token;
87
80
  });
88
81
  }
89
82
  getBalance(address) {
90
83
  return __awaiter(this, void 0, void 0, function* () {
91
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").url);
84
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
92
85
  const balance = yield provider.getBalance(address);
93
- const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f"));
86
+ const token = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
94
87
  return [
95
88
  {
96
89
  amount: ethers_1.ethers.utils.formatEther(balance),
@@ -101,14 +94,14 @@ class RpcBDSEthereum {
101
94
  }
102
95
  getBlockHeight() {
103
96
  return __awaiter(this, void 0, void 0, function* () {
104
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").url);
97
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(this._network.url);
105
98
  return yield provider.getBlockNumber();
106
99
  });
107
100
  }
108
101
  getRpcList() {
109
102
  return __awaiter(this, void 0, void 0, function* () {
110
103
  const list = [];
111
- const urls = BSEthereumHelper_1.BSEthereumHelper.getRpcList(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f"));
104
+ const urls = BSEthereumHelper_1.BSEthereumHelper.getRpcList(this._network);
112
105
  const promises = urls.map(url => {
113
106
  // eslint-disable-next-line no-async-promise-executor
114
107
  return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
@@ -141,4 +134,3 @@ class RpcBDSEthereum {
141
134
  }
142
135
  }
143
136
  exports.RpcBDSEthereum = RpcBDSEthereum;
144
- _RpcBDSEthereum_network = new WeakMap();
@@ -0,0 +1,44 @@
1
+ export declare const ERC271_ABI: ({
2
+ anonymous: boolean;
3
+ inputs: {
4
+ indexed: boolean;
5
+ internalType: string;
6
+ name: string;
7
+ type: string;
8
+ }[];
9
+ name: string;
10
+ type: string;
11
+ constant?: undefined;
12
+ outputs?: undefined;
13
+ payable?: undefined;
14
+ stateMutability?: undefined;
15
+ } | {
16
+ constant: boolean;
17
+ inputs: never[];
18
+ name: string;
19
+ outputs: {
20
+ name: string;
21
+ type: string;
22
+ }[];
23
+ payable: boolean;
24
+ stateMutability: string;
25
+ type: string;
26
+ anonymous?: undefined;
27
+ } | {
28
+ inputs: {
29
+ internalType: string;
30
+ name: string;
31
+ type: string;
32
+ }[];
33
+ name: string;
34
+ outputs: {
35
+ internalType: string;
36
+ name: string;
37
+ type: string;
38
+ }[];
39
+ stateMutability: string;
40
+ type: string;
41
+ anonymous?: undefined;
42
+ constant?: undefined;
43
+ payable?: undefined;
44
+ })[];
@@ -0,0 +1,349 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERC271_ABI = void 0;
4
+ exports.ERC271_ABI = [
5
+ {
6
+ anonymous: false,
7
+ inputs: [
8
+ {
9
+ indexed: true,
10
+ internalType: 'address',
11
+ name: 'owner',
12
+ type: 'address',
13
+ },
14
+ {
15
+ indexed: true,
16
+ internalType: 'address',
17
+ name: 'approved',
18
+ type: 'address',
19
+ },
20
+ {
21
+ indexed: true,
22
+ internalType: 'uint256',
23
+ name: 'tokenId',
24
+ type: 'uint256',
25
+ },
26
+ ],
27
+ name: 'Approval',
28
+ type: 'event',
29
+ },
30
+ {
31
+ anonymous: false,
32
+ inputs: [
33
+ {
34
+ indexed: true,
35
+ internalType: 'address',
36
+ name: 'owner',
37
+ type: 'address',
38
+ },
39
+ {
40
+ indexed: true,
41
+ internalType: 'address',
42
+ name: 'operator',
43
+ type: 'address',
44
+ },
45
+ {
46
+ indexed: false,
47
+ internalType: 'bool',
48
+ name: 'approved',
49
+ type: 'bool',
50
+ },
51
+ ],
52
+ name: 'ApprovalForAll',
53
+ type: 'event',
54
+ },
55
+ {
56
+ anonymous: false,
57
+ inputs: [
58
+ {
59
+ indexed: true,
60
+ internalType: 'address',
61
+ name: 'from',
62
+ type: 'address',
63
+ },
64
+ {
65
+ indexed: true,
66
+ internalType: 'address',
67
+ name: 'to',
68
+ type: 'address',
69
+ },
70
+ {
71
+ indexed: true,
72
+ internalType: 'uint256',
73
+ name: 'tokenId',
74
+ type: 'uint256',
75
+ },
76
+ ],
77
+ name: 'Transfer',
78
+ type: 'event',
79
+ },
80
+ {
81
+ inputs: [
82
+ {
83
+ internalType: 'address',
84
+ name: 'to',
85
+ type: 'address',
86
+ },
87
+ {
88
+ internalType: 'uint256',
89
+ name: 'tokenId',
90
+ type: 'uint256',
91
+ },
92
+ ],
93
+ name: 'approve',
94
+ outputs: [],
95
+ stateMutability: 'nonpayable',
96
+ type: 'function',
97
+ },
98
+ {
99
+ constant: true,
100
+ inputs: [],
101
+ name: 'totalSupply',
102
+ outputs: [
103
+ {
104
+ name: '',
105
+ type: 'uint256',
106
+ },
107
+ ],
108
+ payable: false,
109
+ stateMutability: 'view',
110
+ type: 'function',
111
+ },
112
+ {
113
+ inputs: [
114
+ {
115
+ internalType: 'address',
116
+ name: 'owner',
117
+ type: 'address',
118
+ },
119
+ ],
120
+ name: 'balanceOf',
121
+ outputs: [
122
+ {
123
+ internalType: 'uint256',
124
+ name: 'balance',
125
+ type: 'uint256',
126
+ },
127
+ ],
128
+ stateMutability: 'view',
129
+ type: 'function',
130
+ },
131
+ {
132
+ inputs: [
133
+ {
134
+ internalType: 'uint256',
135
+ name: 'tokenId',
136
+ type: 'uint256',
137
+ },
138
+ ],
139
+ name: 'getApproved',
140
+ outputs: [
141
+ {
142
+ internalType: 'address',
143
+ name: 'operator',
144
+ type: 'address',
145
+ },
146
+ ],
147
+ stateMutability: 'view',
148
+ type: 'function',
149
+ },
150
+ {
151
+ inputs: [
152
+ {
153
+ internalType: 'address',
154
+ name: 'owner',
155
+ type: 'address',
156
+ },
157
+ {
158
+ internalType: 'address',
159
+ name: 'operator',
160
+ type: 'address',
161
+ },
162
+ ],
163
+ name: 'isApprovedForAll',
164
+ outputs: [
165
+ {
166
+ internalType: 'bool',
167
+ name: '',
168
+ type: 'bool',
169
+ },
170
+ ],
171
+ stateMutability: 'view',
172
+ type: 'function',
173
+ },
174
+ {
175
+ inputs: [],
176
+ name: 'name',
177
+ outputs: [
178
+ {
179
+ internalType: 'string',
180
+ name: '',
181
+ type: 'string',
182
+ },
183
+ ],
184
+ stateMutability: 'view',
185
+ type: 'function',
186
+ },
187
+ {
188
+ inputs: [
189
+ {
190
+ internalType: 'uint256',
191
+ name: 'tokenId',
192
+ type: 'uint256',
193
+ },
194
+ ],
195
+ name: 'ownerOf',
196
+ outputs: [
197
+ {
198
+ internalType: 'address',
199
+ name: 'owner',
200
+ type: 'address',
201
+ },
202
+ ],
203
+ stateMutability: 'view',
204
+ type: 'function',
205
+ },
206
+ {
207
+ inputs: [
208
+ {
209
+ internalType: 'address',
210
+ name: 'from',
211
+ type: 'address',
212
+ },
213
+ {
214
+ internalType: 'address',
215
+ name: 'to',
216
+ type: 'address',
217
+ },
218
+ {
219
+ internalType: 'uint256',
220
+ name: 'tokenId',
221
+ type: 'uint256',
222
+ },
223
+ ],
224
+ name: 'safeTransferFrom',
225
+ outputs: [],
226
+ stateMutability: 'nonpayable',
227
+ type: 'function',
228
+ },
229
+ {
230
+ inputs: [
231
+ {
232
+ internalType: 'address',
233
+ name: 'from',
234
+ type: 'address',
235
+ },
236
+ {
237
+ internalType: 'address',
238
+ name: 'to',
239
+ type: 'address',
240
+ },
241
+ {
242
+ internalType: 'uint256',
243
+ name: 'tokenId',
244
+ type: 'uint256',
245
+ },
246
+ {
247
+ internalType: 'bytes',
248
+ name: 'data',
249
+ type: 'bytes',
250
+ },
251
+ ],
252
+ name: 'safeTransferFrom',
253
+ outputs: [],
254
+ stateMutability: 'nonpayable',
255
+ type: 'function',
256
+ },
257
+ {
258
+ inputs: [
259
+ {
260
+ internalType: 'address',
261
+ name: 'operator',
262
+ type: 'address',
263
+ },
264
+ {
265
+ internalType: 'bool',
266
+ name: '_approved',
267
+ type: 'bool',
268
+ },
269
+ ],
270
+ name: 'setApprovalForAll',
271
+ outputs: [],
272
+ stateMutability: 'nonpayable',
273
+ type: 'function',
274
+ },
275
+ {
276
+ inputs: [
277
+ {
278
+ internalType: 'bytes4',
279
+ name: 'interfaceId',
280
+ type: 'bytes4',
281
+ },
282
+ ],
283
+ name: 'supportsInterface',
284
+ outputs: [
285
+ {
286
+ internalType: 'bool',
287
+ name: '',
288
+ type: 'bool',
289
+ },
290
+ ],
291
+ stateMutability: 'view',
292
+ type: 'function',
293
+ },
294
+ {
295
+ inputs: [],
296
+ name: 'symbol',
297
+ outputs: [
298
+ {
299
+ internalType: 'string',
300
+ name: '',
301
+ type: 'string',
302
+ },
303
+ ],
304
+ stateMutability: 'view',
305
+ type: 'function',
306
+ },
307
+ {
308
+ inputs: [
309
+ {
310
+ internalType: 'uint256',
311
+ name: 'tokenId',
312
+ type: 'uint256',
313
+ },
314
+ ],
315
+ name: 'tokenURI',
316
+ outputs: [
317
+ {
318
+ internalType: 'string',
319
+ name: '',
320
+ type: 'string',
321
+ },
322
+ ],
323
+ stateMutability: 'view',
324
+ type: 'function',
325
+ },
326
+ {
327
+ inputs: [
328
+ {
329
+ internalType: 'address',
330
+ name: 'from',
331
+ type: 'address',
332
+ },
333
+ {
334
+ internalType: 'address',
335
+ name: 'to',
336
+ type: 'address',
337
+ },
338
+ {
339
+ internalType: 'uint256',
340
+ name: 'tokenId',
341
+ type: 'uint256',
342
+ },
343
+ ],
344
+ name: 'transferFrom',
345
+ outputs: [],
346
+ stateMutability: 'nonpayable',
347
+ type: 'function',
348
+ },
349
+ ];
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from './BSEthereum';
2
2
  export * from './GhostMarketNDSEthereum';
3
3
  export * from './RpcNDSEthereum';
4
4
  export * from './BSEthereumHelper';
5
- export * from './BitqueryBDSEthereum';
5
+ export * from './MoralisBDSEthereum';
6
6
  export * from './RpcBDSEthereum';
7
- export * from './BitqueryEDSEthereum';
7
+ export * from './MoralisEDSEthereum';
8
8
  export * from './EthersLedgerServiceEthereum';
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ __exportStar(require("./BSEthereum"), exports);
18
18
  __exportStar(require("./GhostMarketNDSEthereum"), exports);
19
19
  __exportStar(require("./RpcNDSEthereum"), exports);
20
20
  __exportStar(require("./BSEthereumHelper"), exports);
21
- __exportStar(require("./BitqueryBDSEthereum"), exports);
21
+ __exportStar(require("./MoralisBDSEthereum"), exports);
22
22
  __exportStar(require("./RpcBDSEthereum"), exports);
23
- __exportStar(require("./BitqueryEDSEthereum"), exports);
23
+ __exportStar(require("./MoralisEDSEthereum"), exports);
24
24
  __exportStar(require("./EthersLedgerServiceEthereum"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-ethereum",
3
- "version": "2.0.3",
3
+ "version": "2.1.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -12,8 +12,6 @@
12
12
  "dependencies": {
13
13
  "axios": "1.5.1",
14
14
  "ethers": "5.7.2",
15
- "graphql": "~16.8.0",
16
- "dayjs": "~1.11.9",
17
15
  "query-string": "7.1.3",
18
16
  "@ethersproject/json-wallets": "5.7.0",
19
17
  "@ethersproject/bytes": "5.7.0",
@@ -22,7 +20,7 @@
22
20
  "@ledgerhq/hw-app-eth": "~6.35.7",
23
21
  "@ethersproject/abstract-signer": "~5.7.0",
24
22
  "@ethersproject/properties": "~5.7.0",
25
- "@cityofzion/blockchain-service": "1.0.2"
23
+ "@cityofzion/blockchain-service": "1.1.0"
26
24
  },
27
25
  "devDependencies": {
28
26
  "@ledgerhq/hw-transport-node-hid": "~6.28.5",
@@ -1,15 +0,0 @@
1
- import { BalanceResponse, ContractResponse, Token, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, Network } from '@cityofzion/blockchain-service';
2
- import { RpcBDSEthereum } from './RpcBDSEthereum';
3
- import { BSEthereumNetworkId } from './BSEthereumHelper';
4
- export declare class BitqueryBDSEthereum extends RpcBDSEthereum {
5
- #private;
6
- static MIRROR_URL: string;
7
- static MIRROR_NETWORK_BY_NETWORK_ID: Partial<Record<BSEthereumNetworkId, string>>;
8
- maxTimeToConfirmTransactionInMs: number;
9
- constructor(network: Network<BSEthereumNetworkId>);
10
- getTransaction(hash: string): Promise<TransactionResponse>;
11
- getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
12
- getContract(): Promise<ContractResponse>;
13
- getTokenInfo(hash: string): Promise<Token>;
14
- getBalance(address: string): Promise<BalanceResponse[]>;
15
- }