@mentaproject/client 0.1.37 → 0.2.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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.cjs +193 -269
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +187 -267
- package/dist/index.js.map +1 -1
- package/dist/managers/TransactionManager.d.ts +48 -48
- package/dist/structures/Account.d.ts +18 -81
- package/dist/structures/Action.d.ts +55 -0
- package/dist/structures/TransferAction.d.ts +41 -0
- package/dist/structures/index.d.ts +5 -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 +2 -1
- package/src/managers/TransactionManager.ts +81 -76
- package/src/structures/Account.ts +23 -105
- package/src/structures/index.ts +5 -5
- package/src/types/index.ts +7 -7
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Call, Hex, TransactionReceipt } from "@mentaproject/core";
|
|
2
|
+
import { MentaAccountClient } from "@mentaproject/core/types";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a transaction that has been sent but not yet confirmed.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PendingTransaction {
|
|
7
|
+
private client;
|
|
8
|
+
readonly hash: Hex;
|
|
9
|
+
constructor(client: MentaAccountClient, hash: Hex);
|
|
10
|
+
/**
|
|
11
|
+
* Waits for the transaction to be confirmed.
|
|
12
|
+
*
|
|
13
|
+
* @param confirmations Number of block confirmations to wait for (default: 1)
|
|
14
|
+
* @returns The transaction receipt
|
|
15
|
+
*/
|
|
16
|
+
confirm(confirmations?: number): Promise<TransactionReceipt>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generic action object that wraps a single call.
|
|
20
|
+
*
|
|
21
|
+
* Provides `.call()` for batching with TransactionBuilder
|
|
22
|
+
* and `.execute()` for direct execution.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* // Direct execution
|
|
27
|
+
* const pending = await account.sendEth(parseEther("1")).execute();
|
|
28
|
+
* const receipt = await pending.confirm();
|
|
29
|
+
*
|
|
30
|
+
* // Batching with TransactionBuilder
|
|
31
|
+
* new TransactionBuilder(client.rpc)
|
|
32
|
+
* .addCall(account.sendEth(parseEther("1")))
|
|
33
|
+
* .addCall(token.transfer(to, amount))
|
|
34
|
+
* .execute();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class Action {
|
|
38
|
+
private client;
|
|
39
|
+
private _call;
|
|
40
|
+
constructor(client: MentaAccountClient, _call: Call);
|
|
41
|
+
/**
|
|
42
|
+
* Returns the Call object for use with TransactionBuilder.
|
|
43
|
+
*/
|
|
44
|
+
call(): Call;
|
|
45
|
+
/**
|
|
46
|
+
* Simulates the action without executing.
|
|
47
|
+
*/
|
|
48
|
+
simulate(): Promise<import("viem").SimulateCallsReturnType<readonly [Call]>>;
|
|
49
|
+
/**
|
|
50
|
+
* Executes the action directly.
|
|
51
|
+
*
|
|
52
|
+
* @returns A PendingTransaction with the hash and .confirm() method
|
|
53
|
+
*/
|
|
54
|
+
execute(): Promise<PendingTransaction>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Call, Hex, SimulateCallsReturnType } from "@mentaproject/core";
|
|
2
|
+
import { MentaAccountClient } from "@mentaproject/core/types";
|
|
3
|
+
import type { Address } from "@mentaproject/core/types";
|
|
4
|
+
/**
|
|
5
|
+
* Action object for ETH transfers.
|
|
6
|
+
*
|
|
7
|
+
* Provides both `.call()` for batching with TransactionBuilder
|
|
8
|
+
* and `.execute()` for direct execution.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // Direct execution
|
|
13
|
+
* await account.sendEth(parseEther("1")).execute();
|
|
14
|
+
*
|
|
15
|
+
* // Batching with TransactionBuilder
|
|
16
|
+
* new TransactionBuilder(client.rpc)
|
|
17
|
+
* .addCall(account.sendEth(parseEther("1")))
|
|
18
|
+
* .addCall(erc20.transfer(to, amount))
|
|
19
|
+
* .execute();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class TransferAction {
|
|
23
|
+
private client;
|
|
24
|
+
private to;
|
|
25
|
+
private amount;
|
|
26
|
+
constructor(client: MentaAccountClient, to: Address, amount: bigint);
|
|
27
|
+
/**
|
|
28
|
+
* Returns the Call object for use with TransactionBuilder.
|
|
29
|
+
*/
|
|
30
|
+
call(): Call;
|
|
31
|
+
/**
|
|
32
|
+
* Simulates the transfer without executing.
|
|
33
|
+
*/
|
|
34
|
+
simulate(): Promise<SimulateCallsReturnType<Call[]>>;
|
|
35
|
+
/**
|
|
36
|
+
* Executes the transfer directly.
|
|
37
|
+
*
|
|
38
|
+
* @returns Transaction hash
|
|
39
|
+
*/
|
|
40
|
+
execute(): Promise<Hex>;
|
|
41
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./Account";
|
|
2
|
+
export * from "./Block";
|
|
3
|
+
export * from "./MentaClient";
|
|
4
|
+
export * from "./Transaction";
|
|
5
|
+
export * from "./Cache";
|
package/dist/types/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export * from
|
|
1
|
+
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export * from \"./Account\";\nexport * from \"./Block\";\nexport * from \"./Transaction\";\nexport * from \"./Cache\";\nexport * from \"./PersistenceAdapter\";\nexport * from \"./Utils\";\n\nexport * from \"@mentaproject/core/types\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAOA,0BAAc,qCAPd;","names":[]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
1
|
+
export * from "./Account";
|
|
2
|
+
export * from "./Block";
|
|
3
|
+
export * from "./Transaction";
|
|
4
|
+
export * from "./Cache";
|
|
5
|
+
export * from "./PersistenceAdapter";
|
|
6
|
+
export * from "./Utils";
|
|
7
7
|
export * from "@mentaproject/core/types";
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export * from
|
|
1
|
+
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export * from \"./Account\";\nexport * from \"./Block\";\nexport * from \"./Transaction\";\nexport * from \"./Cache\";\nexport * from \"./PersistenceAdapter\";\nexport * from \"./Utils\";\n\nexport * from \"@mentaproject/core/types\";\n"],"mappings":";AAOA,cAAc;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentaproject/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "High level EVM library used into the Menta App to facilitate Blockchain interactions. ",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@mentaproject/contracts": "^0.0.11",
|
|
38
38
|
"@mentaproject/core": "^0.7.3",
|
|
39
|
+
"@mentaproject/transactions": "^0.0.3",
|
|
39
40
|
"@modelcontextprotocol/sdk": "^1.13.0",
|
|
40
41
|
"@shazow/whatsabi": "^0.21.1"
|
|
41
42
|
},
|
|
@@ -1,92 +1,97 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module TransactionManager
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import { Transaction } from "../structures/Transaction";
|
|
4
|
+
import { GetTransactionParameters, Transaction as RawTransaction, SendTransactionParameters } from "@mentaproject/core/types";
|
|
5
|
+
import { Transaction as RichTransaction } from "../structures/Transaction";
|
|
6
|
+
import { MulticallTransaction } from "@mentaproject/transactions";
|
|
6
7
|
import { getTransaction, sendTransaction } from "@mentaproject/core/actions";
|
|
7
8
|
import { MentaClient } from "../structures";
|
|
8
9
|
import { JSONTransaction } from "../types";
|
|
9
10
|
import { parseBingints } from "../utils/bigint";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* Manages blockchain transaction-related operations
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* Manages blockchain transaction-related operations.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Create a multicall transaction
|
|
18
|
+
* const pending = await client.transactions.create()
|
|
19
|
+
* .addCall(account.sendEth(parseEther("1")))
|
|
20
|
+
* .addCall(erc20.transfer(to, amount))
|
|
21
|
+
* .execute();
|
|
22
|
+
*
|
|
23
|
+
* const receipt = await pending.confirm();
|
|
24
|
+
*
|
|
25
|
+
* // Get a transaction by hash
|
|
26
|
+
* const tx = await client.transactions.fromHash(hash);
|
|
27
|
+
* console.log(tx.receipt, tx.block);
|
|
28
|
+
* ```
|
|
17
29
|
*/
|
|
18
30
|
export class TransactionManager {
|
|
19
|
-
|
|
20
|
-
* Creates an instance of `TransactionManager`.
|
|
21
|
-
* @constructor
|
|
22
|
-
* @param {MentaClient} client - The instance of MentaClient used to interact with the blockchain.
|
|
23
|
-
*/
|
|
24
|
-
constructor(public client: MentaClient) {};
|
|
31
|
+
constructor(public client: MentaClient) {}
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new MulticallTransaction for batching multiple calls.
|
|
35
|
+
*
|
|
36
|
+
* @returns A MulticallTransaction builder
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const pending = await client.transactions.create()
|
|
41
|
+
* .addCall(account.sendEth(parseEther("1")))
|
|
42
|
+
* .addCall(erc20.transfer(to, amount))
|
|
43
|
+
* .execute();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
create(): MulticallTransaction {
|
|
47
|
+
return new MulticallTransaction(this.client.rpc);
|
|
48
|
+
}
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves a rich transaction by its hash.
|
|
52
|
+
*
|
|
53
|
+
* @param hash - The transaction hash
|
|
54
|
+
* @returns A rich Transaction with receipt, block, etc.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const tx = await client.transactions.fromHash(hash);
|
|
59
|
+
* console.log(tx.from, tx.to, tx.value);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
async fromHash(hash: `0x${string}`): Promise<RichTransaction> {
|
|
63
|
+
return this.get({ hash });
|
|
64
|
+
}
|
|
52
65
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves a transaction by its hash or block number and index.
|
|
68
|
+
*/
|
|
69
|
+
async get(params: GetTransactionParameters): Promise<RichTransaction> {
|
|
70
|
+
const data = await getTransaction(this.client.rpc, params);
|
|
71
|
+
return new RichTransaction(this.client, data);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Parse a transaction object from a JSON converted transaction data object.
|
|
76
|
+
*/
|
|
77
|
+
parse<J extends JSONTransaction<0>>(data: J): RichTransaction {
|
|
78
|
+
const parsed = parseBingints(data);
|
|
61
79
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @param {SendTransactionParameters} params - The parameters required to send the transaction,
|
|
67
|
-
* such as `to`, `value`, `data`, `gasLimit`, etc.
|
|
68
|
-
* @returns {Promise<Transaction>} A promise that resolves to a {@link Transaction} instance
|
|
69
|
-
* representing the sent transaction, including its hash and other details.
|
|
70
|
-
* @example
|
|
71
|
-
* import { MentaClient } from '@mentaproject/client';
|
|
72
|
-
* import { http } from '@mentaproject/core';
|
|
73
|
-
*
|
|
74
|
-
* // This example assumes you have an account with funds, which is available to the client.
|
|
75
|
-
* const client = new MentaClient({
|
|
76
|
-
* chain: 'mainnet',
|
|
77
|
-
* transport: http('http://rpcurlhere.com')
|
|
78
|
-
* });
|
|
79
|
-
*
|
|
80
|
-
* const transactionResult = await client.transactions.send({
|
|
81
|
-
* to: '0xRecipientAddress...', // Replace with a valid recipient address
|
|
82
|
-
* value: 1000000000000000000n, // 1 ETH in wei
|
|
83
|
-
* });
|
|
84
|
-
*
|
|
85
|
-
* console.log('Transaction sent with hash:', transactionResult.hash);
|
|
86
|
-
*/
|
|
87
|
-
async send(params: SendTransactionParameters): Promise<Transaction> {
|
|
88
|
-
const hash = await sendTransaction(this.client.rpc, params);
|
|
89
|
-
|
|
90
|
-
return await this.get({ hash });
|
|
80
|
+
const rawData = {
|
|
81
|
+
...parsed,
|
|
82
|
+
from: parsed.from.address,
|
|
83
|
+
to: parsed.to ? parsed.to.address : null,
|
|
91
84
|
};
|
|
92
|
-
|
|
85
|
+
|
|
86
|
+
return new RichTransaction(this.client, rawData as RawTransaction);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Sends a transaction to the blockchain network.
|
|
91
|
+
* @deprecated Use client.transactions.create() for new transactions
|
|
92
|
+
*/
|
|
93
|
+
async send(params: SendTransactionParameters): Promise<RichTransaction> {
|
|
94
|
+
const hash = await sendTransaction(this.client.rpc, params);
|
|
95
|
+
return await this.get({ hash });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -3,9 +3,7 @@ import {
|
|
|
3
3
|
getBalance,
|
|
4
4
|
getBlockNumber,
|
|
5
5
|
getCode,
|
|
6
|
-
getTransaction,
|
|
7
6
|
getTransactionCount,
|
|
8
|
-
sendTransaction,
|
|
9
7
|
traceFilter,
|
|
10
8
|
} from "@mentaproject/core/actions";
|
|
11
9
|
import type {
|
|
@@ -13,7 +11,8 @@ import type {
|
|
|
13
11
|
Hash,
|
|
14
12
|
onBlockRangeCallback,
|
|
15
13
|
} from "@mentaproject/core/types";
|
|
16
|
-
import { Transaction } from "./Transaction";
|
|
14
|
+
import { Transaction as RichTransaction } from "./Transaction";
|
|
15
|
+
import { Transaction } from "@mentaproject/transactions";
|
|
17
16
|
import { toHex } from "@mentaproject/core/utils";
|
|
18
17
|
import {
|
|
19
18
|
AccountData,
|
|
@@ -28,22 +27,11 @@ import { MentaClient } from "./MentaClient";
|
|
|
28
27
|
|
|
29
28
|
/**
|
|
30
29
|
* Represents a blockchain account with functionalities to interact with the Menta blockchain.
|
|
31
|
-
* This class provides methods to query account information, send transactions, and manage account-related data.
|
|
32
30
|
*/
|
|
33
31
|
export class Account implements AccountData {
|
|
34
|
-
/**
|
|
35
|
-
* The blockchain address of the account.
|
|
36
|
-
*/
|
|
37
32
|
public address: Address;
|
|
38
|
-
|
|
39
33
|
private persistenceManager?: PersistenceManager;
|
|
40
34
|
|
|
41
|
-
/**
|
|
42
|
-
* Creates an instance of the Account class.
|
|
43
|
-
* @param client.rpc The CoreClient instance used for blockchain interactions.
|
|
44
|
-
* @param address The blockchain address of the account.
|
|
45
|
-
* @param persistenceManager An optional PersistenceManager instance for caching and data synchronization.
|
|
46
|
-
*/
|
|
47
35
|
constructor(
|
|
48
36
|
public client: MentaClient,
|
|
49
37
|
data: AccountData,
|
|
@@ -53,99 +41,58 @@ export class Account implements AccountData {
|
|
|
53
41
|
this.persistenceManager = persistenceManager;
|
|
54
42
|
}
|
|
55
43
|
|
|
56
|
-
/**
|
|
57
|
-
* Checks if the account's address belongs to a smart contract.
|
|
58
|
-
* @description This method queries the blockchain for the code associated with the account's address.
|
|
59
|
-
* If code is found, it indicates that the account is a contract.
|
|
60
|
-
* @returns {Promise<boolean>} A promise that resolves to `true` if the account is a contract, `false` otherwise.
|
|
61
|
-
*/
|
|
62
44
|
async isContract(): Promise<boolean> {
|
|
63
45
|
const code = await getCode(this.client.rpc, { address: this.address });
|
|
64
|
-
|
|
65
46
|
if (!code || code === "0x") return false;
|
|
66
47
|
return true;
|
|
67
48
|
}
|
|
68
49
|
|
|
69
|
-
/**
|
|
70
|
-
* Retrieves the type of the contract if the account is a smart contract.
|
|
71
|
-
* @description This method first checks if the account is a contract using `isContract()`.
|
|
72
|
-
* If it is a contract, it then attempts to determine and return its type.
|
|
73
|
-
* @returns {Promise<any>} A promise that resolves to the contract type (e.g., 'ERC20', 'ERC721') or `undefined` if the account is not a contract or its type cannot be determined.
|
|
74
|
-
*/
|
|
75
50
|
async contractType(): Promise<any> {
|
|
76
51
|
const isContract = await this.isContract();
|
|
77
52
|
if (!isContract) return undefined;
|
|
78
|
-
|
|
79
53
|
return await getContractType(this.client.rpc, this.address);
|
|
80
54
|
}
|
|
81
55
|
|
|
82
56
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* @param
|
|
86
|
-
* @returns
|
|
57
|
+
* Creates a Transaction to send ETH to this account.
|
|
58
|
+
*
|
|
59
|
+
* @param amount The amount of ETH to send, in wei.
|
|
60
|
+
* @returns A Transaction with .call(), .simulate(), and .execute() methods.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* // Direct execution
|
|
65
|
+
* const pending = await account.sendEth(parseEther("1")).execute();
|
|
66
|
+
* const receipt = await pending.confirm();
|
|
67
|
+
*
|
|
68
|
+
* // Batch with MulticallTransaction
|
|
69
|
+
* multicall.addCall(account.sendEth(parseEther("1")));
|
|
70
|
+
* ```
|
|
87
71
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
to: this.address,
|
|
93
|
-
value: amount,
|
|
94
|
-
},
|
|
95
|
-
],
|
|
72
|
+
sendEth(amount: bigint): Transaction {
|
|
73
|
+
return new Transaction(this.client.rpc, {
|
|
74
|
+
to: this.address,
|
|
75
|
+
value: amount,
|
|
96
76
|
});
|
|
97
|
-
|
|
98
|
-
const data = await getTransaction(this.client.rpc, { hash });
|
|
99
|
-
return new Transaction(this.client, data);
|
|
100
77
|
}
|
|
101
78
|
|
|
102
|
-
/**
|
|
103
|
-
* Retrieves the current native cryptocurrency (ETH) balance of the account.
|
|
104
|
-
* @description This method queries the blockchain to get the balance associated with the account's address.
|
|
105
|
-
* @returns {Promise<bigint>} A promise that resolves to the ETH balance of the account, in wei.
|
|
106
|
-
*/
|
|
107
79
|
async ETHBalance(): Promise<bigint> {
|
|
108
|
-
return await getBalance(this.client.rpc, {
|
|
109
|
-
address: this.address,
|
|
110
|
-
});
|
|
80
|
+
return await getBalance(this.client.rpc, { address: this.address });
|
|
111
81
|
}
|
|
112
82
|
|
|
113
|
-
/**
|
|
114
|
-
* Retrieves the transaction count (nonce) for the account.
|
|
115
|
-
* @description The transaction count represents the number of transactions sent from this account,
|
|
116
|
-
* which is also used as the nonce for new transactions to prevent replay attacks.
|
|
117
|
-
* @returns {Promise<number>} A promise that resolves to the transaction count of the account.
|
|
118
|
-
*/
|
|
119
83
|
async transactionCount(): Promise<number> {
|
|
120
|
-
return await getTransactionCount(this.client.rpc, {
|
|
121
|
-
address: this.address,
|
|
122
|
-
});
|
|
84
|
+
return await getTransactionCount(this.client.rpc, { address: this.address });
|
|
123
85
|
}
|
|
124
86
|
|
|
125
|
-
/**
|
|
126
|
-
* Retrieves all transactions involving this account.
|
|
127
|
-
* @description If a `PersistenceManager` is configured, this method will first attempt to retrieve transactions from the local cache.
|
|
128
|
-
* If not found in cache or if no `PersistenceManager` is configured, it will fetch transactions directly from the remote RPC.
|
|
129
|
-
* @param {GetTransactionsOptions} [options] - Optional parameters for filtering, pagination, and sorting the transactions.
|
|
130
|
-
* @param {number} [options.startBlock] - The starting block number (inclusive) from which to retrieve transactions.
|
|
131
|
-
* @param {number} [options.endBlock] - The ending block number (inclusive) up to which to retrieve transactions.
|
|
132
|
-
* @param {number} [options.page] - The page number for paginated results.
|
|
133
|
-
* @param {number} [options.offset] - The number of items to skip from the beginning of the result set.
|
|
134
|
-
* @param {'asc' | 'desc'} [options.sort] - The sorting order for transactions based on block number ('asc' for ascending, 'desc' for descending).
|
|
135
|
-
* @param {boolean} [forceFetch=false] - Forces the method to fetch transactions from the remote source even if they are already cached. (mostly used internally)
|
|
136
|
-
* @returns {Promise<Transaction[]>} A promise that resolves to an array of transactions.
|
|
137
|
-
*/
|
|
138
87
|
async transactions(
|
|
139
88
|
params: GetTransactionsParams,
|
|
140
89
|
forceFetch = false,
|
|
141
|
-
): Promise<
|
|
90
|
+
): Promise<RichTransaction[]> {
|
|
142
91
|
if (!this.persistenceManager || forceFetch) {
|
|
143
|
-
// If persistence is not configured, fetch directly from remote
|
|
144
92
|
const hashes = await this._fetchTransactions(params);
|
|
145
93
|
const transactions = await Promise.all(
|
|
146
94
|
hashes.map((hash) => this.client.transactions.get({ hash })),
|
|
147
95
|
);
|
|
148
|
-
|
|
149
96
|
return transactions;
|
|
150
97
|
}
|
|
151
98
|
|
|
@@ -156,41 +103,18 @@ export class Account implements AccountData {
|
|
|
156
103
|
return jsons.map((j) => this.client.transactions.parse(j));
|
|
157
104
|
}
|
|
158
105
|
|
|
159
|
-
/**
|
|
160
|
-
* Synchronizes the account's transactions with the remote data source using the configured `PersistenceManager`.
|
|
161
|
-
* @description This method initiates a synchronization process to ensure that the local cache of transactions
|
|
162
|
-
* for this account is up-to-date with the blockchain.
|
|
163
|
-
* @param {number} [limit] The maximum number of transactions to synchronize.
|
|
164
|
-
* @returns {Promise<void>} A promise that resolves when the synchronization process is complete.
|
|
165
|
-
* @throws {Error} If the persistence module is not configured.
|
|
166
|
-
*/
|
|
167
106
|
async syncTransactions(limit: number = 1000): Promise<void> {
|
|
168
107
|
if (!this.persistenceManager)
|
|
169
108
|
throw new Error("The persistence module is not configured.");
|
|
170
109
|
await this.persistenceManager.syncTransactions(this, limit);
|
|
171
110
|
}
|
|
172
111
|
|
|
173
|
-
/**
|
|
174
|
-
* Retrieves transactions involving a specific token. (not implemented yet)
|
|
175
|
-
* @description This method queries the persistence adapter to retrieve transactions involving a specific token.
|
|
176
|
-
* @param {Address} tokenAddress The address of the token.
|
|
177
|
-
* @returns {Promise<any>} A promise that resolves to an array of transactions involving the token.
|
|
178
|
-
* @throws {Error} If the persistence module is not configured.
|
|
179
|
-
*/
|
|
180
112
|
async tokenTransactions(tokenAddress: Address): Promise<any> {
|
|
181
113
|
if (!this.persistenceManager)
|
|
182
114
|
throw new Error("The persistence module is not configured.");
|
|
183
|
-
|
|
184
115
|
return {};
|
|
185
116
|
}
|
|
186
117
|
|
|
187
|
-
/**
|
|
188
|
-
* Converts the Account instance into a JSON-serializable representation.
|
|
189
|
-
* @description This method leverages a utility function to convert the `Account` object,
|
|
190
|
-
* including its asynchronous properties (like `isContract`, `ETHBalance`), into a plain JSON object.
|
|
191
|
-
* @param {number} [depth=1] The depth to which nested objects should be converted. A depth of 1 means only direct properties are included.
|
|
192
|
-
* @returns {Promise<object>} A promise that resolves to the JSON representation of the account.
|
|
193
|
-
*/
|
|
194
118
|
async toJSON<D extends number = 1>(depth: D): Promise<JSONAccount<D>> {
|
|
195
119
|
return await toJSON({
|
|
196
120
|
obj: {
|
|
@@ -204,12 +128,6 @@ export class Account implements AccountData {
|
|
|
204
128
|
});
|
|
205
129
|
}
|
|
206
130
|
|
|
207
|
-
/**
|
|
208
|
-
* Fetches transactions from the account using a block range exploration with trace_filter calls.
|
|
209
|
-
*
|
|
210
|
-
* @param params - The parameters for the block range exploration.
|
|
211
|
-
* @returns A Promise that resolves to an array of transaction hashes.
|
|
212
|
-
*/
|
|
213
131
|
protected async _fetchTransactions({
|
|
214
132
|
fromBlock,
|
|
215
133
|
toBlock,
|
package/src/structures/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./Account";
|
|
2
|
+
export * from "./Block";
|
|
3
|
+
export * from "./MentaClient";
|
|
4
|
+
export * from "./Transaction";
|
|
5
|
+
export * from "./Cache";
|
package/src/types/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
1
|
+
export * from "./Account";
|
|
2
|
+
export * from "./Block";
|
|
3
|
+
export * from "./Transaction";
|
|
4
|
+
export * from "./Cache";
|
|
5
|
+
export * from "./PersistenceAdapter";
|
|
6
|
+
export * from "./Utils";
|
|
7
7
|
|
|
8
|
-
export * from "@mentaproject/core/types";
|
|
8
|
+
export * from "@mentaproject/core/types";
|