@cityofzion/bs-ethereum 2.2.4 → 2.2.6

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.
@@ -157,21 +157,21 @@ class BSEthereum {
157
157
  }
158
158
  const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
159
159
  const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
160
- let transactionParams;
160
+ const gasPrice = yield provider.getGasPrice();
161
+ let transactionParams = {
162
+ gasPrice,
163
+ };
161
164
  const isNative = BSEthereumHelper_1.BSEthereumHelper.normalizeHash(this.feeToken.hash) === BSEthereumHelper_1.BSEthereumHelper.normalizeHash(param.intent.tokenHash);
162
165
  if (isNative) {
163
- const gasPrice = yield provider.getGasPrice();
164
- transactionParams = {
165
- to: param.intent.receiverAddress,
166
- value: amount,
167
- gasPrice,
168
- };
166
+ transactionParams.to = param.intent.receiverAddress;
167
+ transactionParams.value = amount;
169
168
  }
170
169
  else {
171
170
  const contract = new ethers_1.ethers.Contract(param.intent.tokenHash, [
172
171
  'function transfer(address to, uint amount) returns (bool)',
173
172
  ]);
174
- transactionParams = yield contract.populateTransaction.transfer(param.intent.receiverAddress, amount);
173
+ const populatedTransaction = yield contract.populateTransaction.transfer(param.intent.receiverAddress, amount);
174
+ transactionParams = Object.assign(Object.assign({}, populatedTransaction), transactionParams);
175
175
  }
176
176
  const transaction = yield signer.sendTransaction(transactionParams);
177
177
  return transaction.hash;
@@ -51,6 +51,9 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
51
51
  }
52
52
  const client = BlockscoutNeoXBDSEthereum.getClient(this._network);
53
53
  const { data } = yield client.get(`/transactions/${txid}`);
54
+ if (!data || 'message' in data) {
55
+ throw new Error('Transaction not found');
56
+ }
54
57
  const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
55
58
  const transfers = __classPrivateFieldGet(this, _BlockscoutNeoXBDSEthereum_instances, "m", _BlockscoutNeoXBDSEthereum_parseTransfers).call(this, data, nativeToken);
56
59
  return {
@@ -77,6 +80,9 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
77
80
  next_page_params: params.nextPageParams,
78
81
  },
79
82
  });
83
+ if (!data || 'message' in data) {
84
+ throw new Error('Transactions not found');
85
+ }
80
86
  const nativeToken = BSEthereumHelper_1.BSEthereumHelper.getNativeAsset(this._network);
81
87
  const transactions = [];
82
88
  data.items.forEach(item => {
@@ -107,6 +113,9 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
107
113
  try {
108
114
  const client = BlockscoutNeoXBDSEthereum.getClient(this._network);
109
115
  const { data } = yield client.get(`/smart-contracts/${contractHash}`);
116
+ if (!data || 'message' in data) {
117
+ throw new Error('Contract not found');
118
+ }
110
119
  const methods = [];
111
120
  data.abi.forEach(abi => {
112
121
  var _a, _b;
@@ -149,6 +158,9 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
149
158
  }
150
159
  const client = BlockscoutNeoXBDSEthereum.getClient(this._network);
151
160
  const { data } = yield client.get(`/tokens/${tokenHash}`);
161
+ if (!data || 'message' in data) {
162
+ throw new Error('Token not found');
163
+ }
152
164
  return {
153
165
  decimals: parseInt(data.decimals),
154
166
  hash: tokenHash,
@@ -167,6 +179,9 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
167
179
  }
168
180
  const client = BlockscoutNeoXBDSEthereum.getClient(this._network);
169
181
  const { data: nativeBalance } = yield client.get(`/addresses/${address}`);
182
+ if (!nativeBalance || 'message' in nativeBalance) {
183
+ throw new Error('Native balance not found');
184
+ }
170
185
  const balances = [
171
186
  {
172
187
  amount: ethers_1.ethers.utils.formatUnits(nativeBalance.coin_balance, 18),
@@ -174,6 +189,9 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
174
189
  },
175
190
  ];
176
191
  const { data: erc20Balances } = yield client.get(`/addresses/${address}/token-balances`);
192
+ if (!erc20Balances || 'message' in erc20Balances) {
193
+ throw new Error('ERC20 balance not found');
194
+ }
177
195
  erc20Balances.forEach(balance => {
178
196
  const token = {
179
197
  decimals: parseInt(balance.token.decimals),
@@ -199,6 +217,9 @@ class BlockscoutNeoXBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
199
217
  }
200
218
  const client = BlockscoutNeoXBDSEthereum.getClient(this._network);
201
219
  const { data } = yield client.get('/blocks');
220
+ if (!data || 'message' in data) {
221
+ throw new Error('Block not found');
222
+ }
202
223
  return data.items[0].height;
203
224
  });
204
225
  }
@@ -231,7 +252,7 @@ _BlockscoutNeoXBDSEthereum_instances = new WeakSet(), _BlockscoutNeoXBDSEthereum
231
252
  symbol: tokenTransfer.token.symbol,
232
253
  name: tokenTransfer.token.name,
233
254
  hash: tokenTransfer.token.address,
234
- decimals: tokenTransfer.total.decimals,
255
+ decimals: Number(tokenTransfer.total.decimals),
235
256
  },
236
257
  });
237
258
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-ethereum",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",