@lukso/transaction-decoder 1.0.1-dev.0f1bea5
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/LICENSE +201 -0
- package/README.md +486 -0
- package/dist/browser.cjs +6912 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +6 -0
- package/dist/browser.d.ts +6 -0
- package/dist/browser.js +131 -0
- package/dist/browser.js.map +1 -0
- package/dist/cdn/transaction-decoder.global.js +296 -0
- package/dist/cdn/transaction-decoder.global.js.map +1 -0
- package/dist/chunk-GGBHTWJL.js +437 -0
- package/dist/chunk-GGBHTWJL.js.map +1 -0
- package/dist/chunk-GXZOF3QY.js +839 -0
- package/dist/chunk-GXZOF3QY.js.map +1 -0
- package/dist/chunk-LJ6ES5XF.js +776 -0
- package/dist/chunk-LJ6ES5XF.js.map +1 -0
- package/dist/chunk-XVHJWV5U.js +4925 -0
- package/dist/chunk-XVHJWV5U.js.map +1 -0
- package/dist/data.cjs +5518 -0
- package/dist/data.cjs.map +1 -0
- package/dist/data.d.cts +43 -0
- package/dist/data.d.ts +43 -0
- package/dist/data.js +55 -0
- package/dist/data.js.map +1 -0
- package/dist/index-BzXh7poJ.d.cts +524 -0
- package/dist/index-BzXh7poJ.d.ts +524 -0
- package/dist/index.cjs +6912 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +756 -0
- package/dist/index.d.ts +756 -0
- package/dist/index.js +131 -0
- package/dist/index.js.map +1 -0
- package/dist/server.cjs +5644 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +217 -0
- package/dist/server.d.ts +217 -0
- package/dist/server.js +644 -0
- package/dist/server.js.map +1 -0
- package/dist/utils-CBAkjQh3.d.cts +108 -0
- package/dist/utils-xT9-km0r.d.ts +108 -0
- package/package.json +101 -0
- package/src/browser.ts +13 -0
- package/src/client/resolveAddresses.ts +157 -0
- package/src/core/addressCollector.ts +153 -0
- package/src/core/addressResolver.ts +135 -0
- package/src/core/dataModel.ts +888 -0
- package/src/core/instance.ts +33 -0
- package/src/core/integrateDecoder.ts +325 -0
- package/src/data.ts +70 -0
- package/src/decoder/GENERATOR_PROPOSAL.md +182 -0
- package/src/decoder/THREE_PHASE_EXAMPLE.md +108 -0
- package/src/decoder/aggregation.ts +218 -0
- package/src/decoder/browserCache.ts +237 -0
- package/src/decoder/cache/README.md +126 -0
- package/src/decoder/cache/index.ts +44 -0
- package/src/decoder/cache.ts +139 -0
- package/src/decoder/constants.ts +125 -0
- package/src/decoder/decodeTransaction.ts +292 -0
- package/src/decoder/errors.ts +95 -0
- package/src/decoder/events.ts +192 -0
- package/src/decoder/functionSignature.ts +344 -0
- package/src/decoder/getDataFromExternalSources.ts +248 -0
- package/src/decoder/graphqlWS.ts +22 -0
- package/src/decoder/interfaces.ts +185 -0
- package/src/decoder/keyValue.ts +5 -0
- package/src/decoder/kvCache.ts +241 -0
- package/src/decoder/lruCache.ts +184 -0
- package/src/decoder/lsp7Mint.test.ts +179 -0
- package/src/decoder/lsp7TransferBatch.test.ts +105 -0
- package/src/decoder/plugins/RegistryAbi.ts +562 -0
- package/src/decoder/plugins/enhanceBurntPix.ts +132 -0
- package/src/decoder/plugins/enhanceGraffiti.ts +70 -0
- package/src/decoder/plugins/enhanceLSP0ERC725Account.ts +179 -0
- package/src/decoder/plugins/enhanceLSP26FollowerSystem.ts +88 -0
- package/src/decoder/plugins/enhanceLSP6KeyManager.ts +231 -0
- package/src/decoder/plugins/enhanceLSP7DigitalAsset.ts +165 -0
- package/src/decoder/plugins/enhanceLSP8IdentifiableDigitalAsset.ts +170 -0
- package/src/decoder/plugins/enhanceLSP9Vault.ts +57 -0
- package/src/decoder/plugins/enhanceRetrieveAbi.ts +85 -0
- package/src/decoder/plugins/enhanceSetData.ts +135 -0
- package/src/decoder/plugins/index.ts +99 -0
- package/src/decoder/plugins/schemaDefault.ts +318 -0
- package/src/decoder/plugins/standardPlugin.ts +202 -0
- package/src/decoder/registry.ts +322 -0
- package/src/decoder/singleGQL.ts +293 -0
- package/src/decoder/transaction.ts +198 -0
- package/src/decoder/types.ts +465 -0
- package/src/decoder/utils.ts +212 -0
- package/src/example/usage.ts +172 -0
- package/src/index.ts +174 -0
- package/src/server/addressResolver.ts +68 -0
- package/src/server/caches.ts +209 -0
- package/src/server/decodeTransactionSync.ts +156 -0
- package/src/server/decodeTransactionsBatch.ts +207 -0
- package/src/server/finishDecoding.ts +116 -0
- package/src/server/index.ts +81 -0
- package/src/server/lsp23Resolver.test.ts +46 -0
- package/src/server/lsp23Resolver.ts +419 -0
- package/src/server/types.ts +168 -0
- package/src/server.ts +22 -0
- package/src/shared/addressResolver.ts +651 -0
- package/src/shared/cache.ts +144 -0
- package/src/shared/constants.ts +21 -0
- package/src/stubs/tty.ts +13 -0
- package/src/stubs/util.ts +42 -0
- package/src/types/index.ts +154 -0
- package/src/types/provider.ts +46 -0
- package/src/umd.ts +13 -0
- package/src/utils/debug.ts +49 -0
- package/src/utils/json-bigint.ts +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
# @lukso/transaction-decoder
|
|
2
|
+
|
|
3
|
+
A modern, progressive transaction decoder for LUKSO and EVM blockchains with reactive state management, multi-level caching, and three-phase enhancement.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Progressive Enhancement** - Show results immediately, enhance progressively
|
|
8
|
+
- ⚡ **Reactive State Management** - Framework-agnostic signals for real-time updates
|
|
9
|
+
- 🔄 **Smart Batching** - Minimize API calls with intelligent request batching
|
|
10
|
+
- 💾 **Multi-Level Caching** - Transaction, address, ABI, and schema caches
|
|
11
|
+
- 🔌 **Plugin System** - Extensible architecture with auto-registration
|
|
12
|
+
- 🛡️ **Security First** - Frozen plugins, immutable data, prototype protection
|
|
13
|
+
- 🌐 **Universal** - Works in Node.js, browsers, and all major frameworks
|
|
14
|
+
- ⏱️ **Time-Bounded Server Mode** - Get the best result within your time budget
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @lukso/transaction-decoder
|
|
20
|
+
# or
|
|
21
|
+
yarn add @lukso/transaction-decoder
|
|
22
|
+
# or
|
|
23
|
+
pnpm add @lukso/transaction-decoder
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### Client-Side (React, Vue, etc.)
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { decodeTransaction } from '@lukso/transaction-decoder'
|
|
32
|
+
|
|
33
|
+
// Decode a transaction with progressive enhancement
|
|
34
|
+
const result = await decodeTransaction(transaction)
|
|
35
|
+
|
|
36
|
+
// Access immediate result
|
|
37
|
+
console.log(result.immediate)
|
|
38
|
+
|
|
39
|
+
// Subscribe to updates
|
|
40
|
+
result.signal.subscribe(state => {
|
|
41
|
+
console.log(state.decodingStatus) // 'decoded' → 'enhanced' → 'complete'
|
|
42
|
+
console.log(state.data) // Progressively enhanced data
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Server-Side (Node.js)
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { createServerDecoder } from '@lukso/transaction-decoder/server'
|
|
50
|
+
|
|
51
|
+
// Create a decoder instance with caching
|
|
52
|
+
const decoder = createServerDecoder({
|
|
53
|
+
graphqlEndpoint: 'https://api.universalprofile.cloud/graphql',
|
|
54
|
+
defaultChain: lukso,
|
|
55
|
+
transactionCacheSize: 10000,
|
|
56
|
+
addressCacheSize: 50000,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// Decode with time budget (returns best result within 800ms)
|
|
60
|
+
const result = await decoder.decodeTransaction(transaction, {
|
|
61
|
+
timeoutMs: 800,
|
|
62
|
+
enableEnhancement: true,
|
|
63
|
+
enableAddressResolution: true,
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
console.log(result.phase) // 'immediate' | 'enhanced' | 'complete'
|
|
67
|
+
console.log(result.cached) // true if from cache
|
|
68
|
+
console.log(result.data) // Decoded transaction data
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Three-Phase Decoding
|
|
72
|
+
|
|
73
|
+
The decoder uses a progressive enhancement approach:
|
|
74
|
+
|
|
75
|
+
### Phase 1: Immediate Decode (10ms)
|
|
76
|
+
- Synchronous decoding using known ABIs
|
|
77
|
+
- Returns function names, arguments, basic info
|
|
78
|
+
- Available immediately for UI rendering
|
|
79
|
+
|
|
80
|
+
### Phase 2: Enhancement (200ms)
|
|
81
|
+
- Fetches unknown ABIs from blockchain
|
|
82
|
+
- Adds contract verification status
|
|
83
|
+
- Provides human-readable context
|
|
84
|
+
- Batches ABI requests across transactions
|
|
85
|
+
|
|
86
|
+
### Phase 3: Address Resolution (100ms)
|
|
87
|
+
- Resolves profile metadata
|
|
88
|
+
- Fetches asset information
|
|
89
|
+
- Adds token details
|
|
90
|
+
- Batches all address lookups
|
|
91
|
+
|
|
92
|
+
## Architecture
|
|
93
|
+
|
|
94
|
+
### API Layers
|
|
95
|
+
|
|
96
|
+
1. **Consumer API** (`@lukso/transaction-decoder`) - Read-only reactive access
|
|
97
|
+
2. **Data Provider API** (`@lukso/transaction-decoder/data`) - Data management
|
|
98
|
+
3. **Server API** (`@lukso/transaction-decoder/server`) - Server-side optimized
|
|
99
|
+
4. **Browser API** (`@lukso/transaction-decoder/browser`) - Browser global
|
|
100
|
+
|
|
101
|
+
### Data Flow
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
Raw Transaction → Decoder → Data Model → Consumer API → UI
|
|
105
|
+
↓ ↓
|
|
106
|
+
Progressive Address
|
|
107
|
+
Enhancement Resolution
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Reactive State Management
|
|
111
|
+
|
|
112
|
+
Using Preact signals for framework-agnostic reactivity:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
// Get reactive transaction state
|
|
116
|
+
const txSignal = getTransaction(hash)
|
|
117
|
+
|
|
118
|
+
// Vue
|
|
119
|
+
const transaction = computed(() => txSignal.value)
|
|
120
|
+
|
|
121
|
+
// React
|
|
122
|
+
const [state, setState] = useState(txSignal.value)
|
|
123
|
+
useEffect(() => effect(() => setState(txSignal.value)), [])
|
|
124
|
+
|
|
125
|
+
// Svelte
|
|
126
|
+
$: state = $txSignal.value
|
|
127
|
+
|
|
128
|
+
// Vanilla JS
|
|
129
|
+
txSignal.subscribe(state => {
|
|
130
|
+
console.log('Transaction updated:', state)
|
|
131
|
+
})
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## API Reference
|
|
135
|
+
|
|
136
|
+
### Consumer API (Client-Side)
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import {
|
|
140
|
+
decodeTransaction,
|
|
141
|
+
getTransaction,
|
|
142
|
+
getAddress,
|
|
143
|
+
subscribe
|
|
144
|
+
} from '@lukso/transaction-decoder'
|
|
145
|
+
|
|
146
|
+
// Decode single or multiple transactions
|
|
147
|
+
const result = await decodeTransaction(tx, options)
|
|
148
|
+
const results = await decodeTransaction([tx1, tx2, tx3], options)
|
|
149
|
+
|
|
150
|
+
// Access transaction by hash
|
|
151
|
+
const txSignal = getTransaction(hash)
|
|
152
|
+
|
|
153
|
+
// Access address metadata
|
|
154
|
+
const addressSignal = getAddress(address)
|
|
155
|
+
|
|
156
|
+
// Subscribe to any data changes
|
|
157
|
+
const unsubscribe = subscribe(key, (state) => {
|
|
158
|
+
console.log('Data updated:', state)
|
|
159
|
+
})
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Server API
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { createServerDecoder } from '@lukso/transaction-decoder/server'
|
|
166
|
+
|
|
167
|
+
const decoder = createServerDecoder({
|
|
168
|
+
graphqlEndpoint: string,
|
|
169
|
+
defaultChain: Chain,
|
|
170
|
+
transactionCacheSize?: number, // Default: 10000
|
|
171
|
+
addressCacheSize?: number, // Default: 50000
|
|
172
|
+
abiCacheSize?: number, // Default: 5000
|
|
173
|
+
schemaCacheSize?: number, // Default: 10000
|
|
174
|
+
defaultTimeout?: number, // Default: 800ms
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
// Decode with time budget
|
|
178
|
+
const result = await decoder.decodeTransaction(tx, {
|
|
179
|
+
timeoutMs: 800,
|
|
180
|
+
enableEnhancement: true,
|
|
181
|
+
enableAddressResolution: true,
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
// Batch decode for efficiency
|
|
185
|
+
const results = await decoder.decodeTransactionsBatch(transactions, options)
|
|
186
|
+
|
|
187
|
+
// Cache management
|
|
188
|
+
decoder.clearCaches()
|
|
189
|
+
const stats = decoder.getCacheStats()
|
|
190
|
+
await decoder.warmAddressCache(addresses)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Data Provider API
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
import {
|
|
197
|
+
addTransactions,
|
|
198
|
+
injectData,
|
|
199
|
+
updateData
|
|
200
|
+
} from '@lukso/transaction-decoder/data'
|
|
201
|
+
|
|
202
|
+
// Add transactions to be decoded
|
|
203
|
+
addTransactions(transactions)
|
|
204
|
+
|
|
205
|
+
// Inject address metadata
|
|
206
|
+
injectData(addresses)
|
|
207
|
+
|
|
208
|
+
// Update existing data
|
|
209
|
+
updateData(key, data)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Plugin System
|
|
213
|
+
|
|
214
|
+
### Using Plugins
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
// Import plugins - they auto-register
|
|
218
|
+
import '@lukso/decoder-plugin-defi'
|
|
219
|
+
import '@lukso/decoder-plugin-nft'
|
|
220
|
+
|
|
221
|
+
// Plugins are automatically available
|
|
222
|
+
const result = await decodeTransaction(tx)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Creating Plugins
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
import { standardPlugin, registerPlugin } from '@lukso/transaction-decoder'
|
|
229
|
+
|
|
230
|
+
const myPlugin = standardPlugin(
|
|
231
|
+
CONTRACT_ABI,
|
|
232
|
+
{
|
|
233
|
+
name: 'my-plugin',
|
|
234
|
+
abiName: 'MyContract',
|
|
235
|
+
required: true, // Can't be overridden
|
|
236
|
+
priority: 1000, // Higher runs first
|
|
237
|
+
},
|
|
238
|
+
async (result, options) => {
|
|
239
|
+
// Enhance the decoded result
|
|
240
|
+
return enhancedResult
|
|
241
|
+
}
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
// Auto-register the plugin
|
|
245
|
+
registerPlugin('my-plugin', myPlugin)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Schema Plugins
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import { standardSchemaPlugin } from '@lukso/transaction-decoder'
|
|
252
|
+
|
|
253
|
+
const schemaPlugin = standardSchemaPlugin(
|
|
254
|
+
ERC725_SCHEMAS,
|
|
255
|
+
{ name: 'custom-schema' },
|
|
256
|
+
async (info) => {
|
|
257
|
+
// Process decoded schema data
|
|
258
|
+
return enhancedInfo
|
|
259
|
+
}
|
|
260
|
+
)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Caching Architecture
|
|
264
|
+
|
|
265
|
+
### Client-Side
|
|
266
|
+
- Reactive signals cache decoded data
|
|
267
|
+
- Automatic deduplication of requests
|
|
268
|
+
- Memory-based with configurable limits
|
|
269
|
+
|
|
270
|
+
### Server-Side
|
|
271
|
+
- **Transaction Cache**: Complete decoded results (1hr TTL)
|
|
272
|
+
- **Address Cache**: Profile/asset metadata (24hr TTL)
|
|
273
|
+
- **ABI Cache**: Contract interfaces (7 day TTL)
|
|
274
|
+
- **Schema Cache**: Decoded values (1hr TTL)
|
|
275
|
+
|
|
276
|
+
Cache statistics available for monitoring:
|
|
277
|
+
```typescript
|
|
278
|
+
const stats = decoder.getCacheStats()
|
|
279
|
+
// {
|
|
280
|
+
// transactions: { size: 5420, hitRate: 0.89, ... },
|
|
281
|
+
// addresses: { size: 12453, hitRate: 0.94, ... },
|
|
282
|
+
// ...
|
|
283
|
+
// }
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Framework Integration
|
|
287
|
+
|
|
288
|
+
### React
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
function useTransaction(hash: string) {
|
|
292
|
+
const signal = getTransaction(hash)
|
|
293
|
+
const [state, setState] = useState(signal.value)
|
|
294
|
+
|
|
295
|
+
useEffect(() => {
|
|
296
|
+
const unsubscribe = signal.subscribe(setState)
|
|
297
|
+
return unsubscribe
|
|
298
|
+
}, [hash])
|
|
299
|
+
|
|
300
|
+
return state
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Vue
|
|
305
|
+
|
|
306
|
+
```vue
|
|
307
|
+
<script setup>
|
|
308
|
+
import { computed } from 'vue'
|
|
309
|
+
import { getTransaction } from '@lukso/transaction-decoder'
|
|
310
|
+
|
|
311
|
+
const props = defineProps(['hash'])
|
|
312
|
+
const signal = getTransaction(props.hash)
|
|
313
|
+
const transaction = computed(() => signal.value)
|
|
314
|
+
</script>
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Svelte
|
|
318
|
+
|
|
319
|
+
```svelte
|
|
320
|
+
<script>
|
|
321
|
+
import { onDestroy } from 'svelte'
|
|
322
|
+
import { effect } from '@preact/signals-core'
|
|
323
|
+
import { getAddress } from '@lukso/transaction-decoder'
|
|
324
|
+
|
|
325
|
+
export let address
|
|
326
|
+
|
|
327
|
+
let state = getAddress(address).value
|
|
328
|
+
|
|
329
|
+
const unsubscribe = effect(() => {
|
|
330
|
+
state = getAddress(address).value
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
onDestroy(unsubscribe)
|
|
334
|
+
</script>
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## Security
|
|
338
|
+
|
|
339
|
+
- 🔒 **Frozen Plugins** - Plugins are immutable after creation
|
|
340
|
+
- 🛡️ **Read-Only API** - Consumer API prevents data tampering
|
|
341
|
+
- 🧊 **Immutable Data** - All returned data is deeply frozen
|
|
342
|
+
- 🔐 **Prototype Protection** - Classes protected against pollution
|
|
343
|
+
|
|
344
|
+
## Performance
|
|
345
|
+
|
|
346
|
+
- **Immediate results** in ~10ms
|
|
347
|
+
- **Enhanced results** in ~200ms
|
|
348
|
+
- **Complete with addresses** in ~300ms
|
|
349
|
+
- **Batch processing** reduces API calls by 90%+
|
|
350
|
+
- **Server caching** provides sub-millisecond responses
|
|
351
|
+
|
|
352
|
+
## Types
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
// Address key - can be just address or address + tokenId
|
|
356
|
+
type DataKey = Hex | { address: Hex; tokenId: Hex }
|
|
357
|
+
|
|
358
|
+
// Transaction state during decoding
|
|
359
|
+
interface TransactionState {
|
|
360
|
+
loading: boolean
|
|
361
|
+
data: DecoderResult
|
|
362
|
+
decodingStatus: 'decoded' | 'enhanced' | 'complete' | 'failed'
|
|
363
|
+
addresses: DataKey[]
|
|
364
|
+
addressesResolved: boolean
|
|
365
|
+
resolvedData?: DecoderResult // Transaction with addresses replaced by metadata
|
|
366
|
+
error?: string
|
|
367
|
+
lastUpdated: number
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Server decoding result
|
|
371
|
+
interface ServerDecoderResult {
|
|
372
|
+
data: DecoderResult
|
|
373
|
+
phase: 'immediate' | 'enhanced'
|
|
374
|
+
cached: boolean
|
|
375
|
+
timeTaken: number
|
|
376
|
+
addressesResolved?: number
|
|
377
|
+
addressesCached?: number
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Decoder plugin
|
|
381
|
+
interface DecoderPlugin {
|
|
382
|
+
enhance: (transaction, options) => Promise<DecoderResult | undefined>
|
|
383
|
+
decodeEvent: (log, options) => Promise<DecodeEventResult>
|
|
384
|
+
async?: boolean
|
|
385
|
+
name?: string
|
|
386
|
+
required?: boolean
|
|
387
|
+
priority?: number
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
## Browser Support
|
|
392
|
+
|
|
393
|
+
### CDN
|
|
394
|
+
```html
|
|
395
|
+
<script src="https://unpkg.com/@lukso/transaction-decoder"></script>
|
|
396
|
+
<script>
|
|
397
|
+
const { decodeTransaction } = window.TransactionDecoder
|
|
398
|
+
</script>
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### ES Modules
|
|
402
|
+
```javascript
|
|
403
|
+
import { decodeTransaction } from '@lukso/transaction-decoder'
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### CommonJS
|
|
407
|
+
```javascript
|
|
408
|
+
const { decodeTransaction } = require('@lukso/transaction-decoder')
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
## Advanced Usage
|
|
412
|
+
|
|
413
|
+
### Custom Address Resolver
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
import { AddressResolver } from '@lukso/transaction-decoder'
|
|
417
|
+
|
|
418
|
+
const resolver = new AddressResolver({
|
|
419
|
+
dataModel,
|
|
420
|
+
graphqlEndpoint: 'https://custom-api.com/graphql',
|
|
421
|
+
batchSize: 100,
|
|
422
|
+
batchDelay: 50,
|
|
423
|
+
})
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### Integration with Data Model
|
|
427
|
+
|
|
428
|
+
```typescript
|
|
429
|
+
import { DecoderIntegration, createDataModel } from '@lukso/transaction-decoder'
|
|
430
|
+
|
|
431
|
+
const dataModel = createDataModel({
|
|
432
|
+
onMissingKeys: (keys) => {
|
|
433
|
+
// Trigger address resolution
|
|
434
|
+
},
|
|
435
|
+
onNewTransaction: (tx) => {
|
|
436
|
+
// Handle new transaction
|
|
437
|
+
},
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
const decoder = new DecoderIntegration({
|
|
441
|
+
dataModel,
|
|
442
|
+
chain: lukso,
|
|
443
|
+
})
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
### TypeScript Augmentation
|
|
447
|
+
|
|
448
|
+
```typescript
|
|
449
|
+
// Augment types for custom fields
|
|
450
|
+
declare module '@lukso/transaction-decoder' {
|
|
451
|
+
interface DecoderResult {
|
|
452
|
+
myCustomField?: string
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
interface EnhancedInfo {
|
|
456
|
+
myCustomData?: any
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
## Migration from lib/decoder
|
|
462
|
+
|
|
463
|
+
If migrating from the old `lib/decoder`:
|
|
464
|
+
|
|
465
|
+
1. Install the npm package
|
|
466
|
+
2. Update imports:
|
|
467
|
+
```typescript
|
|
468
|
+
// Old
|
|
469
|
+
import { decodeTransaction } from '~/lib/decoder/transaction'
|
|
470
|
+
|
|
471
|
+
// New - Client
|
|
472
|
+
import { decodeTransaction } from '@lukso/transaction-decoder'
|
|
473
|
+
|
|
474
|
+
// New - Server
|
|
475
|
+
import { createServerDecoder } from '@lukso/transaction-decoder/server'
|
|
476
|
+
```
|
|
477
|
+
3. Update API calls for new return format
|
|
478
|
+
4. Delete the old `lib/decoder` folder
|
|
479
|
+
|
|
480
|
+
## Contributing
|
|
481
|
+
|
|
482
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup and guidelines.
|
|
483
|
+
|
|
484
|
+
## License
|
|
485
|
+
|
|
486
|
+
MIT
|