@mentaproject/client 0.1.37 → 0.1.38
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/.tsbuildinfo +1 -1
- package/dist/index.cjs +197 -235
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +179 -222
- package/dist/index.js.map +1 -1
- package/dist/structures/Account.d.ts +15 -79
- package/dist/structures/Action.d.ts +39 -0
- package/dist/structures/TransferAction.d.ts +41 -0
- package/dist/structures/index.d.ts +6 -5
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +6 -6
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
- package/src/structures/Account.ts +20 -103
- package/src/structures/Action.ts +51 -0
- package/src/structures/index.ts +6 -5
- package/src/types/index.ts +7 -7
package/dist/index.cjs
CHANGED
|
@@ -141,6 +141,7 @@ var src_exports = {};
|
|
|
141
141
|
__export(src_exports, {
|
|
142
142
|
Account: () => Account,
|
|
143
143
|
AccountManager: () => AccountManager,
|
|
144
|
+
Action: () => Action,
|
|
144
145
|
Block: () => Block,
|
|
145
146
|
BlockManager: () => BlockManager,
|
|
146
147
|
ContractManager: () => ContractManager,
|
|
@@ -159,12 +160,38 @@ module.exports = __toCommonJS(src_exports);
|
|
|
159
160
|
// src/structures/Account.ts
|
|
160
161
|
var import_actions2 = require("@mentaproject/core/actions");
|
|
161
162
|
|
|
162
|
-
// src/structures/
|
|
163
|
+
// src/structures/Action.ts
|
|
163
164
|
var import_actions = require("@mentaproject/core/actions");
|
|
164
|
-
var
|
|
165
|
+
var Action = class {
|
|
166
|
+
constructor(client, _call) {
|
|
167
|
+
this.client = client;
|
|
168
|
+
this._call = _call;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Returns the Call object for use with TransactionBuilder.
|
|
172
|
+
*/
|
|
173
|
+
call() {
|
|
174
|
+
return this._call;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Simulates the action without executing.
|
|
178
|
+
*/
|
|
179
|
+
async simulate() {
|
|
180
|
+
return (0, import_actions.simulateCalls)(this.client, { calls: [this._call] });
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Executes the action directly.
|
|
184
|
+
*
|
|
185
|
+
* @returns Transaction hash
|
|
186
|
+
*/
|
|
187
|
+
async execute() {
|
|
188
|
+
return this.client.sendTransaction(this._call);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
165
191
|
|
|
166
|
-
//
|
|
167
|
-
|
|
192
|
+
// src/structures/Account.ts
|
|
193
|
+
var import_utils = require("@mentaproject/core/utils");
|
|
194
|
+
var import_contracts = require("@mentaproject/contracts");
|
|
168
195
|
|
|
169
196
|
// src/utils/toJSON.ts
|
|
170
197
|
function isClassInstance(obj) {
|
|
@@ -234,68 +261,123 @@ async function toJSON({ obj, depth = 0 }) {
|
|
|
234
261
|
return convertBigintsToStrings(data);
|
|
235
262
|
}
|
|
236
263
|
|
|
237
|
-
// src/structures/
|
|
238
|
-
var
|
|
239
|
-
|
|
240
|
-
* @description Creates an instance of Block.
|
|
241
|
-
* @param client - The instance of MentaClient used to interact with the blockchain.
|
|
242
|
-
* @param data The raw block data conforming to IBlockData.
|
|
243
|
-
* @param includeTransactions Whether to include full transaction objects. Defaults to false.
|
|
244
|
-
*/
|
|
245
|
-
constructor(client, data) {
|
|
264
|
+
// src/structures/Account.ts
|
|
265
|
+
var Account = class {
|
|
266
|
+
constructor(client, data, persistenceManager) {
|
|
246
267
|
this.client = client;
|
|
247
|
-
this.
|
|
248
|
-
this.
|
|
249
|
-
this.difficulty = data.difficulty;
|
|
250
|
-
this.excessBlobGas = data.excessBlobGas;
|
|
251
|
-
this.extraData = data.extraData;
|
|
252
|
-
this.gasLimit = data.gasLimit;
|
|
253
|
-
this.gasUsed = data.gasUsed;
|
|
254
|
-
this.hash = data.hash;
|
|
255
|
-
this.logsBloom = data.logsBloom;
|
|
256
|
-
this.mixHash = data.mixHash;
|
|
257
|
-
this.nonce = data.nonce;
|
|
258
|
-
this.number = data.number;
|
|
259
|
-
this.parentBeaconBlockRoot = data.parentBeaconBlockRoot;
|
|
260
|
-
this.parentHash = data.parentHash;
|
|
261
|
-
this.receiptsRoot = data.receiptsRoot;
|
|
262
|
-
this.sealFields = data.sealFields;
|
|
263
|
-
this.sha3Uncles = data.sha3Uncles;
|
|
264
|
-
this.size = data.size;
|
|
265
|
-
this.stateRoot = data.stateRoot;
|
|
266
|
-
this.timestamp = data.timestamp;
|
|
267
|
-
this.totalDifficulty = data.totalDifficulty;
|
|
268
|
-
this.transactionsRoot = data.transactionsRoot;
|
|
269
|
-
this.uncles = data.uncles;
|
|
270
|
-
this.withdrawals = data.withdrawals;
|
|
271
|
-
this.withdrawalsRoot = data.withdrawalsRoot;
|
|
272
|
-
this.miner = new Account(this.client, { address: data.miner });
|
|
273
|
-
if (!data.transactions || data.transactions.length === 0) {
|
|
274
|
-
const parsed = data.transactions.map((data2) => typeof data2 === "string" ? data2 : new Transaction(this.client, data2));
|
|
275
|
-
this.transactions = parsed;
|
|
276
|
-
}
|
|
268
|
+
this.address = data.address;
|
|
269
|
+
this.persistenceManager = persistenceManager;
|
|
277
270
|
}
|
|
278
|
-
|
|
279
|
-
|
|
271
|
+
async isContract() {
|
|
272
|
+
const code = await (0, import_actions2.getCode)(this.client.rpc, { address: this.address });
|
|
273
|
+
if (!code || code === "0x") return false;
|
|
280
274
|
return true;
|
|
281
275
|
}
|
|
276
|
+
async contractType() {
|
|
277
|
+
const isContract = await this.isContract();
|
|
278
|
+
if (!isContract) return void 0;
|
|
279
|
+
return await (0, import_contracts.getContractType)(this.client.rpc, this.address);
|
|
280
|
+
}
|
|
282
281
|
/**
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
* @
|
|
287
|
-
*
|
|
282
|
+
* Creates an Action to send ETH to this account.
|
|
283
|
+
*
|
|
284
|
+
* @param amount The amount of ETH to send, in wei.
|
|
285
|
+
* @returns An Action with .call(), .simulate(), and .execute() methods.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* // Direct execution
|
|
290
|
+
* await account.sendEth(parseEther("1")).execute();
|
|
291
|
+
*
|
|
292
|
+
* // Batch with TransactionBuilder
|
|
293
|
+
* builder.addCall(account.sendEth(parseEther("1")));
|
|
294
|
+
* ```
|
|
288
295
|
*/
|
|
296
|
+
sendEth(amount) {
|
|
297
|
+
return new Action(this.client.rpc, {
|
|
298
|
+
to: this.address,
|
|
299
|
+
value: amount
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
async ETHBalance() {
|
|
303
|
+
return await (0, import_actions2.getBalance)(this.client.rpc, { address: this.address });
|
|
304
|
+
}
|
|
305
|
+
async transactionCount() {
|
|
306
|
+
return await (0, import_actions2.getTransactionCount)(this.client.rpc, { address: this.address });
|
|
307
|
+
}
|
|
308
|
+
async transactions(params, forceFetch = false) {
|
|
309
|
+
if (!this.persistenceManager || forceFetch) {
|
|
310
|
+
const hashes = await this._fetchTransactions(params);
|
|
311
|
+
const transactions = await Promise.all(
|
|
312
|
+
hashes.map((hash) => this.client.transactions.get({ hash }))
|
|
313
|
+
);
|
|
314
|
+
return transactions;
|
|
315
|
+
}
|
|
316
|
+
const jsons = await this.persistenceManager.getTransactions(
|
|
317
|
+
this.address,
|
|
318
|
+
params
|
|
319
|
+
);
|
|
320
|
+
return jsons.map((j) => this.client.transactions.parse(j));
|
|
321
|
+
}
|
|
322
|
+
async syncTransactions(limit = 1e3) {
|
|
323
|
+
if (!this.persistenceManager)
|
|
324
|
+
throw new Error("The persistence module is not configured.");
|
|
325
|
+
await this.persistenceManager.syncTransactions(this, limit);
|
|
326
|
+
}
|
|
327
|
+
async tokenTransactions(tokenAddress) {
|
|
328
|
+
if (!this.persistenceManager)
|
|
329
|
+
throw new Error("The persistence module is not configured.");
|
|
330
|
+
return {};
|
|
331
|
+
}
|
|
289
332
|
async toJSON(depth) {
|
|
290
333
|
return await toJSON({
|
|
291
334
|
obj: {
|
|
292
|
-
|
|
335
|
+
address: this.address,
|
|
336
|
+
isContract: this.isContract.bind(this),
|
|
337
|
+
contractType: this.contractType.bind(this),
|
|
338
|
+
ETHBalance: this.ETHBalance.bind(this),
|
|
339
|
+
transactionCount: this.transactionCount.bind(this)
|
|
293
340
|
},
|
|
294
341
|
depth
|
|
295
342
|
});
|
|
296
343
|
}
|
|
344
|
+
async _fetchTransactions({
|
|
345
|
+
fromBlock,
|
|
346
|
+
toBlock,
|
|
347
|
+
limit = 50
|
|
348
|
+
}) {
|
|
349
|
+
const lastBlock = await (0, import_actions2.getBlockNumber)(this.client.rpc);
|
|
350
|
+
const onBlockRange = async ({ fromBlock: fromBlock2, toBlock: toBlock2 }, stop) => {
|
|
351
|
+
const outgoing = await (0, import_actions2.traceFilter)(this.client.rpc, {
|
|
352
|
+
fromBlock: (0, import_utils.toHex)(fromBlock2),
|
|
353
|
+
toBlock: (0, import_utils.toHex)(toBlock2),
|
|
354
|
+
fromAddress: this.address
|
|
355
|
+
});
|
|
356
|
+
const incoming = await (0, import_actions2.traceFilter)(this.client.rpc, {
|
|
357
|
+
fromBlock: (0, import_utils.toHex)(fromBlock2),
|
|
358
|
+
toBlock: (0, import_utils.toHex)(toBlock2),
|
|
359
|
+
toAddress: this.address
|
|
360
|
+
});
|
|
361
|
+
const traces = outgoing.concat(incoming).sort((a, b) => a.blockNumber - b.blockNumber);
|
|
362
|
+
return traces.map((t) => t.transactionHash);
|
|
363
|
+
};
|
|
364
|
+
return await (0, import_actions2.fetchByBlockRange)({
|
|
365
|
+
toBlock: BigInt(toBlock !== void 0 ? toBlock : 0),
|
|
366
|
+
fromBlock: BigInt(fromBlock !== void 0 ? fromBlock : lastBlock),
|
|
367
|
+
direction: "backward",
|
|
368
|
+
itemLimit: limit,
|
|
369
|
+
onBlockRange
|
|
370
|
+
});
|
|
371
|
+
}
|
|
297
372
|
};
|
|
298
373
|
|
|
374
|
+
// src/structures/Transaction.ts
|
|
375
|
+
var import_actions3 = require("@mentaproject/core/actions");
|
|
376
|
+
var import_utils2 = require("@mentaproject/core/utils");
|
|
377
|
+
|
|
378
|
+
// node_modules/viem/_esm/index.js
|
|
379
|
+
init_transaction();
|
|
380
|
+
|
|
299
381
|
// src/structures/Transaction.ts
|
|
300
382
|
var Transaction = class {
|
|
301
383
|
/**
|
|
@@ -334,15 +416,15 @@ var Transaction = class {
|
|
|
334
416
|
* @returns {Promise<TransactionCall[] | undefined>} A promise that resolves to an array of call objects, each representing an internal call with sender, recipient, value, input data, gas used, and call type.
|
|
335
417
|
*/
|
|
336
418
|
async calls() {
|
|
337
|
-
const traces = await (0,
|
|
419
|
+
const traces = await (0, import_actions3.traceTransaction)(this.client.rpc, this.hash);
|
|
338
420
|
if (!traces) return void 0;
|
|
339
421
|
const calls = traces.filter((t) => t.type === "call" && t.action !== void 0);
|
|
340
422
|
return calls.map((c) => ({
|
|
341
423
|
from: new Account(this.client, { address: c.action.from }),
|
|
342
424
|
to: new Account(this.client, { address: c.action.to }),
|
|
343
|
-
value: (0,
|
|
425
|
+
value: (0, import_utils2.hexToBigInt)(c.action.value),
|
|
344
426
|
input: c.action.input,
|
|
345
|
-
gas: (0,
|
|
427
|
+
gas: (0, import_utils2.hexToBigInt)(c.action.gas),
|
|
346
428
|
callType: c.action.callType
|
|
347
429
|
}));
|
|
348
430
|
}
|
|
@@ -353,7 +435,7 @@ var Transaction = class {
|
|
|
353
435
|
* @returns {Promise<WaitForTransactionReceiptReturnType>} A promise that resolves to the transaction receipt once the specified number of confirmations are met.
|
|
354
436
|
*/
|
|
355
437
|
async waitForReceipt(confirmations) {
|
|
356
|
-
return await (0,
|
|
438
|
+
return await (0, import_actions3.waitForTransactionReceipt)(this.client.rpc, {
|
|
357
439
|
hash: this.hash,
|
|
358
440
|
confirmations: confirmations || 1
|
|
359
441
|
});
|
|
@@ -365,7 +447,7 @@ var Transaction = class {
|
|
|
365
447
|
*/
|
|
366
448
|
async receipt() {
|
|
367
449
|
try {
|
|
368
|
-
return await (0,
|
|
450
|
+
return await (0, import_actions3.getTransactionReceipt)(this.client.rpc, { hash: this.hash });
|
|
369
451
|
} catch (error) {
|
|
370
452
|
if (error instanceof TransactionReceiptNotFoundError) {
|
|
371
453
|
return void 0;
|
|
@@ -378,7 +460,7 @@ var Transaction = class {
|
|
|
378
460
|
* @returns {Promise<Block>} A promise that resolves to a Block instance representing the block that includes this transaction.
|
|
379
461
|
*/
|
|
380
462
|
async block() {
|
|
381
|
-
const data = await (0,
|
|
463
|
+
const data = await (0, import_actions3.getBlock)(this.client.rpc, { blockHash: this.blockHash });
|
|
382
464
|
return new Block(this.client, data);
|
|
383
465
|
}
|
|
384
466
|
/**
|
|
@@ -404,187 +486,66 @@ var Transaction = class {
|
|
|
404
486
|
}
|
|
405
487
|
};
|
|
406
488
|
|
|
407
|
-
// src/structures/
|
|
408
|
-
var
|
|
409
|
-
var import_contracts = require("@mentaproject/contracts");
|
|
410
|
-
var Account = class {
|
|
489
|
+
// src/structures/Block.ts
|
|
490
|
+
var Block = class {
|
|
411
491
|
/**
|
|
412
|
-
* Creates an instance of
|
|
413
|
-
* @param client
|
|
414
|
-
* @param
|
|
415
|
-
* @param
|
|
492
|
+
* @description Creates an instance of Block.
|
|
493
|
+
* @param client - The instance of MentaClient used to interact with the blockchain.
|
|
494
|
+
* @param data The raw block data conforming to IBlockData.
|
|
495
|
+
* @param includeTransactions Whether to include full transaction objects. Defaults to false.
|
|
416
496
|
*/
|
|
417
|
-
constructor(client, data
|
|
497
|
+
constructor(client, data) {
|
|
418
498
|
this.client = client;
|
|
419
|
-
this.
|
|
420
|
-
this.
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
* @returns {Promise<Transaction>} A promise that resolves to a `Transaction` object representing the sent transaction.
|
|
449
|
-
*/
|
|
450
|
-
async sendETH(amount) {
|
|
451
|
-
const hash = await (0, import_actions2.sendTransaction)(this.client.rpc, {
|
|
452
|
-
calls: [
|
|
453
|
-
{
|
|
454
|
-
to: this.address,
|
|
455
|
-
value: amount
|
|
456
|
-
}
|
|
457
|
-
]
|
|
458
|
-
});
|
|
459
|
-
const data = await (0, import_actions2.getTransaction)(this.client.rpc, { hash });
|
|
460
|
-
return new Transaction(this.client, data);
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Retrieves the current native cryptocurrency (ETH) balance of the account.
|
|
464
|
-
* @description This method queries the blockchain to get the balance associated with the account's address.
|
|
465
|
-
* @returns {Promise<bigint>} A promise that resolves to the ETH balance of the account, in wei.
|
|
466
|
-
*/
|
|
467
|
-
async ETHBalance() {
|
|
468
|
-
return await (0, import_actions2.getBalance)(this.client.rpc, {
|
|
469
|
-
address: this.address
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Retrieves the transaction count (nonce) for the account.
|
|
474
|
-
* @description The transaction count represents the number of transactions sent from this account,
|
|
475
|
-
* which is also used as the nonce for new transactions to prevent replay attacks.
|
|
476
|
-
* @returns {Promise<number>} A promise that resolves to the transaction count of the account.
|
|
477
|
-
*/
|
|
478
|
-
async transactionCount() {
|
|
479
|
-
return await (0, import_actions2.getTransactionCount)(this.client.rpc, {
|
|
480
|
-
address: this.address
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Retrieves all transactions involving this account.
|
|
485
|
-
* @description If a `PersistenceManager` is configured, this method will first attempt to retrieve transactions from the local cache.
|
|
486
|
-
* If not found in cache or if no `PersistenceManager` is configured, it will fetch transactions directly from the remote RPC.
|
|
487
|
-
* @param {GetTransactionsOptions} [options] - Optional parameters for filtering, pagination, and sorting the transactions.
|
|
488
|
-
* @param {number} [options.startBlock] - The starting block number (inclusive) from which to retrieve transactions.
|
|
489
|
-
* @param {number} [options.endBlock] - The ending block number (inclusive) up to which to retrieve transactions.
|
|
490
|
-
* @param {number} [options.page] - The page number for paginated results.
|
|
491
|
-
* @param {number} [options.offset] - The number of items to skip from the beginning of the result set.
|
|
492
|
-
* @param {'asc' | 'desc'} [options.sort] - The sorting order for transactions based on block number ('asc' for ascending, 'desc' for descending).
|
|
493
|
-
* @param {boolean} [forceFetch=false] - Forces the method to fetch transactions from the remote source even if they are already cached. (mostly used internally)
|
|
494
|
-
* @returns {Promise<Transaction[]>} A promise that resolves to an array of transactions.
|
|
495
|
-
*/
|
|
496
|
-
async transactions(params, forceFetch = false) {
|
|
497
|
-
if (!this.persistenceManager || forceFetch) {
|
|
498
|
-
const hashes = await this._fetchTransactions(params);
|
|
499
|
-
const transactions = await Promise.all(
|
|
500
|
-
hashes.map((hash) => this.client.transactions.get({ hash }))
|
|
501
|
-
);
|
|
502
|
-
return transactions;
|
|
499
|
+
this.baseFeePerGas = data.baseFeePerGas;
|
|
500
|
+
this.blobGasUsed = data.blobGasUsed;
|
|
501
|
+
this.difficulty = data.difficulty;
|
|
502
|
+
this.excessBlobGas = data.excessBlobGas;
|
|
503
|
+
this.extraData = data.extraData;
|
|
504
|
+
this.gasLimit = data.gasLimit;
|
|
505
|
+
this.gasUsed = data.gasUsed;
|
|
506
|
+
this.hash = data.hash;
|
|
507
|
+
this.logsBloom = data.logsBloom;
|
|
508
|
+
this.mixHash = data.mixHash;
|
|
509
|
+
this.nonce = data.nonce;
|
|
510
|
+
this.number = data.number;
|
|
511
|
+
this.parentBeaconBlockRoot = data.parentBeaconBlockRoot;
|
|
512
|
+
this.parentHash = data.parentHash;
|
|
513
|
+
this.receiptsRoot = data.receiptsRoot;
|
|
514
|
+
this.sealFields = data.sealFields;
|
|
515
|
+
this.sha3Uncles = data.sha3Uncles;
|
|
516
|
+
this.size = data.size;
|
|
517
|
+
this.stateRoot = data.stateRoot;
|
|
518
|
+
this.timestamp = data.timestamp;
|
|
519
|
+
this.totalDifficulty = data.totalDifficulty;
|
|
520
|
+
this.transactionsRoot = data.transactionsRoot;
|
|
521
|
+
this.uncles = data.uncles;
|
|
522
|
+
this.withdrawals = data.withdrawals;
|
|
523
|
+
this.withdrawalsRoot = data.withdrawalsRoot;
|
|
524
|
+
this.miner = new Account(this.client, { address: data.miner });
|
|
525
|
+
if (!data.transactions || data.transactions.length === 0) {
|
|
526
|
+
const parsed = data.transactions.map((data2) => typeof data2 === "string" ? data2 : new Transaction(this.client, data2));
|
|
527
|
+
this.transactions = parsed;
|
|
503
528
|
}
|
|
504
|
-
const jsons = await this.persistenceManager.getTransactions(
|
|
505
|
-
this.address,
|
|
506
|
-
params
|
|
507
|
-
);
|
|
508
|
-
return jsons.map((j) => this.client.transactions.parse(j));
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* Synchronizes the account's transactions with the remote data source using the configured `PersistenceManager`.
|
|
512
|
-
* @description This method initiates a synchronization process to ensure that the local cache of transactions
|
|
513
|
-
* for this account is up-to-date with the blockchain.
|
|
514
|
-
* @param {number} [limit] The maximum number of transactions to synchronize.
|
|
515
|
-
* @returns {Promise<void>} A promise that resolves when the synchronization process is complete.
|
|
516
|
-
* @throws {Error} If the persistence module is not configured.
|
|
517
|
-
*/
|
|
518
|
-
async syncTransactions(limit = 1e3) {
|
|
519
|
-
if (!this.persistenceManager)
|
|
520
|
-
throw new Error("The persistence module is not configured.");
|
|
521
|
-
await this.persistenceManager.syncTransactions(this, limit);
|
|
522
529
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
* @param {Address} tokenAddress The address of the token.
|
|
527
|
-
* @returns {Promise<any>} A promise that resolves to an array of transactions involving the token.
|
|
528
|
-
* @throws {Error} If the persistence module is not configured.
|
|
529
|
-
*/
|
|
530
|
-
async tokenTransactions(tokenAddress) {
|
|
531
|
-
if (!this.persistenceManager)
|
|
532
|
-
throw new Error("The persistence module is not configured.");
|
|
533
|
-
return {};
|
|
530
|
+
includeTransactions() {
|
|
531
|
+
if (!this.transactions || this.transactions.length === 0) return false;
|
|
532
|
+
return true;
|
|
534
533
|
}
|
|
535
534
|
/**
|
|
536
|
-
* Converts the
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
* @param
|
|
540
|
-
* @returns
|
|
535
|
+
* @description Converts the Block instance to a JSON representation.
|
|
536
|
+
* This method serializes the block's properties into a plain JavaScript object,
|
|
537
|
+
* suitable for JSON serialization.
|
|
538
|
+
* @param depth The depth of the conversion. Defaults to 1.
|
|
539
|
+
* @returns A promise that resolves to the JSON representation of the block.
|
|
541
540
|
*/
|
|
542
541
|
async toJSON(depth) {
|
|
543
542
|
return await toJSON({
|
|
544
543
|
obj: {
|
|
545
|
-
|
|
546
|
-
isContract: this.isContract.bind(this),
|
|
547
|
-
contractType: this.contractType.bind(this),
|
|
548
|
-
ETHBalance: this.ETHBalance.bind(this),
|
|
549
|
-
transactionCount: this.transactionCount.bind(this)
|
|
544
|
+
...this
|
|
550
545
|
},
|
|
551
546
|
depth
|
|
552
547
|
});
|
|
553
548
|
}
|
|
554
|
-
/**
|
|
555
|
-
* Fetches transactions from the account using a block range exploration with trace_filter calls.
|
|
556
|
-
*
|
|
557
|
-
* @param params - The parameters for the block range exploration.
|
|
558
|
-
* @returns A Promise that resolves to an array of transaction hashes.
|
|
559
|
-
*/
|
|
560
|
-
async _fetchTransactions({
|
|
561
|
-
fromBlock,
|
|
562
|
-
toBlock,
|
|
563
|
-
limit = 50
|
|
564
|
-
}) {
|
|
565
|
-
const lastBlock = await (0, import_actions2.getBlockNumber)(this.client.rpc);
|
|
566
|
-
const onBlockRange = async ({ fromBlock: fromBlock2, toBlock: toBlock2 }, stop) => {
|
|
567
|
-
const outgoing = await (0, import_actions2.traceFilter)(this.client.rpc, {
|
|
568
|
-
fromBlock: (0, import_utils2.toHex)(fromBlock2),
|
|
569
|
-
toBlock: (0, import_utils2.toHex)(toBlock2),
|
|
570
|
-
fromAddress: this.address
|
|
571
|
-
});
|
|
572
|
-
const incoming = await (0, import_actions2.traceFilter)(this.client.rpc, {
|
|
573
|
-
fromBlock: (0, import_utils2.toHex)(fromBlock2),
|
|
574
|
-
toBlock: (0, import_utils2.toHex)(toBlock2),
|
|
575
|
-
toAddress: this.address
|
|
576
|
-
});
|
|
577
|
-
const traces = outgoing.concat(incoming).sort((a, b) => a.blockNumber - b.blockNumber);
|
|
578
|
-
return traces.map((t) => t.transactionHash);
|
|
579
|
-
};
|
|
580
|
-
return await (0, import_actions2.fetchByBlockRange)({
|
|
581
|
-
toBlock: BigInt(toBlock !== void 0 ? toBlock : 0),
|
|
582
|
-
fromBlock: BigInt(fromBlock !== void 0 ? fromBlock : lastBlock),
|
|
583
|
-
direction: "backward",
|
|
584
|
-
itemLimit: limit,
|
|
585
|
-
onBlockRange
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
549
|
};
|
|
589
550
|
|
|
590
551
|
// src/structures/MentaClient.ts
|
|
@@ -592,7 +553,7 @@ var import_clients = require("@mentaproject/core/clients");
|
|
|
592
553
|
var import_core = require("@mentaproject/core");
|
|
593
554
|
|
|
594
555
|
// src/managers/BlockManager.ts
|
|
595
|
-
var
|
|
556
|
+
var import_actions4 = require("@mentaproject/core/actions");
|
|
596
557
|
var BlockManager = class {
|
|
597
558
|
/**
|
|
598
559
|
* Creates an instance of BlockManager.
|
|
@@ -630,13 +591,13 @@ var BlockManager = class {
|
|
|
630
591
|
* fetchBlock();
|
|
631
592
|
*/
|
|
632
593
|
async get(params) {
|
|
633
|
-
const data = await (0,
|
|
594
|
+
const data = await (0, import_actions4.getBlock)(this.client.rpc, params);
|
|
634
595
|
return new Block(this.client, data);
|
|
635
596
|
}
|
|
636
597
|
};
|
|
637
598
|
|
|
638
599
|
// src/managers/TransactionManager.ts
|
|
639
|
-
var
|
|
600
|
+
var import_actions5 = require("@mentaproject/core/actions");
|
|
640
601
|
|
|
641
602
|
// src/utils/bigint.ts
|
|
642
603
|
var bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
|
|
@@ -714,7 +675,7 @@ var TransactionManager = class {
|
|
|
714
675
|
* console.log(transaction);
|
|
715
676
|
*/
|
|
716
677
|
async get(params) {
|
|
717
|
-
const data = await (0,
|
|
678
|
+
const data = await (0, import_actions5.getTransaction)(this.client.rpc, params);
|
|
718
679
|
return new Transaction(this.client, data);
|
|
719
680
|
}
|
|
720
681
|
/**
|
|
@@ -758,7 +719,7 @@ var TransactionManager = class {
|
|
|
758
719
|
* console.log('Transaction sent with hash:', transactionResult.hash);
|
|
759
720
|
*/
|
|
760
721
|
async send(params) {
|
|
761
|
-
const hash = await (0,
|
|
722
|
+
const hash = await (0, import_actions5.sendTransaction)(this.client.rpc, params);
|
|
762
723
|
return await this.get({ hash });
|
|
763
724
|
}
|
|
764
725
|
};
|
|
@@ -856,7 +817,7 @@ var AccountManager = class {
|
|
|
856
817
|
};
|
|
857
818
|
|
|
858
819
|
// src/managers/PersistenceManager.ts
|
|
859
|
-
var
|
|
820
|
+
var import_actions6 = require("@mentaproject/core/actions");
|
|
860
821
|
var PersistenceManager = class {
|
|
861
822
|
/**
|
|
862
823
|
* Creates an instance of PersistenceManager.
|
|
@@ -885,7 +846,7 @@ var PersistenceManager = class {
|
|
|
885
846
|
async syncTransactions(account, limit = 1e5) {
|
|
886
847
|
const lastSyncedBlock = await this.persistenceAdapter.getLastSyncedBlock(account.address);
|
|
887
848
|
const lastBlock = lastSyncedBlock ?? 0n;
|
|
888
|
-
const fromBlock = lastSyncedBlock ? lastSyncedBlock + 1n : await (0,
|
|
849
|
+
const fromBlock = lastSyncedBlock ? lastSyncedBlock + 1n : await (0, import_actions6.getBlockNumber)(this.client.rpc);
|
|
889
850
|
const newTransactions = await account.transactions({
|
|
890
851
|
fromBlock,
|
|
891
852
|
toBlock: lastBlock,
|
|
@@ -900,22 +861,22 @@ var PersistenceManager = class {
|
|
|
900
861
|
};
|
|
901
862
|
|
|
902
863
|
// src/types/MentaClient.ts
|
|
903
|
-
var
|
|
864
|
+
var import_actions7 = require("@mentaproject/core/actions");
|
|
904
865
|
var ClientEvents = {
|
|
905
866
|
/**
|
|
906
867
|
* Event for new blocks.
|
|
907
868
|
* Uses the {@link watchBlocks} function from `@mentaproject/core`.
|
|
908
869
|
*/
|
|
909
|
-
block:
|
|
870
|
+
block: import_actions7.watchBlocks,
|
|
910
871
|
/**
|
|
911
872
|
* Event for new block numbers.
|
|
912
873
|
* Uses the {@link watchBlockNumber} function from `@mentaproject/core`.
|
|
913
874
|
*/
|
|
914
|
-
blockNumber:
|
|
875
|
+
blockNumber: import_actions7.watchBlockNumber
|
|
915
876
|
};
|
|
916
877
|
|
|
917
878
|
// src/utils/withCache.ts
|
|
918
|
-
var
|
|
879
|
+
var import_actions8 = require("@mentaproject/core/actions");
|
|
919
880
|
var GET_NONCE_SELECTOR = "0x35567e1a";
|
|
920
881
|
function isNonceCall(method, params) {
|
|
921
882
|
if (method !== "eth_call") return false;
|
|
@@ -923,7 +884,7 @@ function isNonceCall(method, params) {
|
|
|
923
884
|
return typeof callData === "string" && callData.startsWith(GET_NONCE_SELECTOR);
|
|
924
885
|
}
|
|
925
886
|
function withCache(client, cache) {
|
|
926
|
-
(0,
|
|
887
|
+
(0, import_actions8.watchBlockNumber)(client, {
|
|
927
888
|
onBlockNumber: (blockNumber) => {
|
|
928
889
|
cache.setBlockNumber(blockNumber);
|
|
929
890
|
},
|
|
@@ -1151,6 +1112,7 @@ var MemoryCache = class {
|
|
|
1151
1112
|
0 && (module.exports = {
|
|
1152
1113
|
Account,
|
|
1153
1114
|
AccountManager,
|
|
1115
|
+
Action,
|
|
1154
1116
|
Block,
|
|
1155
1117
|
BlockManager,
|
|
1156
1118
|
ContractManager,
|