@anywalletkit/wallet-tron 0.0.0-stage → 0.2.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.
@@ -0,0 +1,160 @@
1
+ import { ChainTx, HistoryPage, HistorySource, HistoryQuery } from '@anywalletkit/core';
2
+
3
+ /**
4
+ * Activity history for Tron: a `HistorySource` over TronGrid's account
5
+ * endpoints (`/v1/accounts/{a}/transactions` and `/transactions/trc20`),
6
+ * merged into one `ChainTx` per txID, with the full-node
7
+ * `/wallet/gettransactionbyid` + `/wallet/gettransactioninfobyid` for a single
8
+ * transaction (exact fee, TRC-20 Transfer logs).
9
+ *
10
+ * Both lists page by `max_timestamp` (inclusive, ms), so a page is a time
11
+ * window that is complete across both lists; the cursor carries the window's
12
+ * lower edge plus the txIDs already emitted at exactly that timestamp. Keyless
13
+ * TronGrid allows ~1 request/s per endpoint; pass `apiKey` for more.
14
+ * `fetch` + `AbortSignal.timeout` only — Hermes-safe.
15
+ */
16
+
17
+ /** The `fetch` shape the history source uses; pass your own for proxies or tests. */
18
+ type HistoryFetch = (input: string, init?: {
19
+ method?: string;
20
+ headers?: Record<string, string>;
21
+ body?: string;
22
+ signal?: AbortSignal;
23
+ }) => Promise<{
24
+ ok: boolean;
25
+ status: number;
26
+ json(): Promise<unknown>;
27
+ }>;
28
+ /** Tron mainnet or the Shasta and Nile testnets. */
29
+ type TronNetwork = 'mainnet' | 'shasta' | 'nile';
30
+ /** Options for {@link createTronHistory}. */
31
+ interface TronHistoryOptions {
32
+ /** TronGrid-compatible root. Default by network: `https://api.trongrid.io`, `https://api.shasta.trongrid.io`, `https://nile.trongrid.io`. */
33
+ apiUrl?: string;
34
+ /** `TRON-PRO-API-KEY`. */
35
+ apiKey?: string;
36
+ network?: TronNetwork;
37
+ fetch?: HistoryFetch;
38
+ /** Requests per second. Default 1 without a key (TronGrid's keyless limit), 10 with one. */
39
+ rateLimit?: number;
40
+ /** Per request, ms. Default 15 000. */
41
+ timeoutMs?: number;
42
+ }
43
+ interface TronHistoryRaw {
44
+ /** The `/transactions` row (absent when only a TRC-20 transfer to the address was indexed). */
45
+ tx?: unknown;
46
+ /** `/transactions/trc20` rows for this txID. */
47
+ trc20: unknown[];
48
+ /** `/wallet/gettransactioninfobyid` (single-transaction reads only). */
49
+ info?: unknown;
50
+ spam?: true;
51
+ spamReason?: string;
52
+ }
53
+ interface TronChainTx extends ChainTx {
54
+ raw: TronHistoryRaw;
55
+ }
56
+ interface TronHistoryPage extends HistoryPage {
57
+ items: TronChainTx[];
58
+ }
59
+ /**
60
+ * Tron history from TronGrid's account endpoints (TRX and TRC-20). Build it with {@link
61
+ * createTronHistory}.
62
+ */
63
+ interface TronHistorySource extends HistorySource {
64
+ listActivity(address: string, query?: HistoryQuery): Promise<TronHistoryPage>;
65
+ getTransaction(hash: string, address: string): Promise<TronChainTx | undefined>;
66
+ }
67
+ /** Every configured TronGrid endpoint failed. */
68
+ declare class HistoryUnavailableError extends Error {
69
+ readonly chain: string;
70
+ readonly reason: string;
71
+ readonly attempts: readonly string[];
72
+ constructor(chain: string, reason: string, attempts?: readonly string[]);
73
+ }
74
+ /** keccak256("Transfer(address,address,uint256)") */
75
+ declare const TRANSFER_TOPIC = "ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
76
+ interface TronHistoryCursor {
77
+ v: 1;
78
+ /** `max_timestamp` (ms, inclusive) for the next page. */
79
+ w: number;
80
+ /** txIDs already emitted at exactly `w`. */
81
+ x: string[];
82
+ /** Lists that returned their last row. */
83
+ e: Array<'tx' | 'trc20'>;
84
+ }
85
+ declare function encodeCursor(c: TronHistoryCursor): string;
86
+ declare function decodeCursor(s: string): TronHistoryCursor;
87
+ interface Contract {
88
+ type: string;
89
+ parameter: {
90
+ value: Record<string, unknown>;
91
+ };
92
+ }
93
+ interface TronGridTx {
94
+ txID: string;
95
+ ret?: Array<{
96
+ contractRet?: string;
97
+ fee?: number;
98
+ }>;
99
+ net_fee?: number;
100
+ energy_fee?: number;
101
+ blockNumber?: number;
102
+ block_timestamp?: number;
103
+ internal_transactions?: Array<{
104
+ caller_address?: string;
105
+ transferTo_address?: string;
106
+ callValueInfo?: Array<{
107
+ callValue?: number;
108
+ tokenId?: string;
109
+ }>;
110
+ rejected?: boolean;
111
+ }>;
112
+ raw_data: {
113
+ contract: Contract[];
114
+ data?: string;
115
+ timestamp?: number;
116
+ };
117
+ }
118
+ interface TronGridTrc20 {
119
+ transaction_id: string;
120
+ token_info: {
121
+ symbol?: string;
122
+ address: string;
123
+ decimals?: number;
124
+ name?: string;
125
+ };
126
+ block_timestamp: number;
127
+ from: string;
128
+ to: string;
129
+ type: string;
130
+ value: string;
131
+ }
132
+ interface FullNodeTxInfo {
133
+ id?: string;
134
+ fee?: number;
135
+ blockNumber?: number;
136
+ blockTimeStamp?: number;
137
+ receipt?: {
138
+ result?: string;
139
+ net_fee?: number;
140
+ energy_fee?: number;
141
+ };
142
+ log?: Array<{
143
+ address: string;
144
+ topics: string[];
145
+ data?: string;
146
+ }>;
147
+ }
148
+ /** Decode what a TronGrid / full-node transaction row says on its own (no TRC-20 list rows yet). */
149
+ declare function mapTransactionRow(chain: string, address: string, tx: TronGridTx, extra?: {
150
+ trc20?: TronGridTrc20[];
151
+ info?: FullNodeTxInfo;
152
+ }): TronChainTx;
153
+ /** A transaction seen only through the TRC-20 list (someone else's call that moved tokens to / from the address). */
154
+ declare function mapTrc20Only(chain: string, address: string, rows: TronGridTrc20[]): TronChainTx;
155
+ /** Tronscan link for a transaction. */
156
+ declare function tronExplorerTxUrl(hash: string, network?: TronNetwork): string;
157
+ /** A history source for Tron addresses backed by TronGrid or a compatible API. */
158
+ declare function createTronHistory(options?: TronHistoryOptions): TronHistorySource;
159
+
160
+ export { type FullNodeTxInfo, type HistoryFetch, HistoryUnavailableError, TRANSFER_TOPIC, type TronChainTx, type TronGridTrc20, type TronGridTx, type TronHistoryCursor, type TronHistoryOptions, type TronHistoryPage, type TronHistoryRaw, type TronHistorySource, type TronNetwork, createTronHistory, decodeCursor, encodeCursor, mapTransactionRow, mapTrc20Only, tronExplorerTxUrl };
@@ -0,0 +1,21 @@
1
+ import {
2
+ HistoryUnavailableError,
3
+ TRANSFER_TOPIC,
4
+ createTronHistory,
5
+ decodeCursor,
6
+ encodeCursor,
7
+ mapTransactionRow,
8
+ mapTrc20Only,
9
+ tronExplorerTxUrl
10
+ } from "./chunk-4XN4VJDG.js";
11
+ export {
12
+ HistoryUnavailableError,
13
+ TRANSFER_TOPIC,
14
+ createTronHistory,
15
+ decodeCursor,
16
+ encodeCursor,
17
+ mapTransactionRow,
18
+ mapTrc20Only,
19
+ tronExplorerTxUrl
20
+ };
21
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}