|
5 | 5 | * matching BitGoJS's TxData format. |
6 | 6 | * |
7 | 7 | * All monetary amounts (amount, fee, lamports, poolTokens) are returned as bigint. |
8 | | - * Accepts both raw bytes and Transaction objects for convenience. |
9 | 8 | */ |
10 | 9 |
|
11 | 10 | import { ParserNamespace } from "./wasm/wasm_solana.js"; |
12 | | -import type { Transaction } from "./transaction.js"; |
13 | | -import type { VersionedTransaction } from "./versioned.js"; |
14 | | - |
15 | | -/** |
16 | | - * Input type for parseTransaction - accepts bytes or Transaction objects. |
17 | | - */ |
18 | | -export type TransactionInput = Uint8Array | Transaction | VersionedTransaction; |
19 | 11 |
|
20 | 12 | // ============================================================================= |
21 | 13 | // Instruction Types - matching BitGoJS InstructionParams. |
@@ -277,48 +269,19 @@ export interface ParsedTransaction { |
277 | 269 | } |
278 | 270 |
|
279 | 271 | // ============================================================================= |
280 | | -// parseTransaction function |
| 272 | +// parseTransactionData function |
281 | 273 | // ============================================================================= |
282 | 274 |
|
283 | 275 | /** |
284 | | - * Parse a Solana transaction into structured data. |
285 | | - * |
286 | | - * This is the main entry point for transaction parsing. It deserializes the |
287 | | - * transaction and decodes all instructions into semantic types. |
288 | | - * |
289 | | - * All monetary amounts (amount, fee, lamports, poolTokens) are returned as bigint |
290 | | - * directly from WASM - no post-processing needed. |
| 276 | + * Parse raw transaction bytes into a plain data object with decoded instructions. |
291 | 277 | * |
292 | | - * Note: This returns the raw parsed data including NonceAdvance instructions. |
293 | | - * Consumers (like BitGoJS) may choose to filter NonceAdvance from instructionsData |
294 | | - * since that info is also available in durableNonce. |
| 278 | + * This is the low-level parsing function. Most callers should use the top-level |
| 279 | + * `parseTransaction(bytes)` which returns a `Transaction` instance with both |
| 280 | + * inspection (`.parse()`) and signing (`.addSignature()`) capabilities. |
295 | 281 | * |
296 | | - * @param input - Raw transaction bytes, Transaction, or VersionedTransaction |
| 282 | + * @param bytes - Raw transaction bytes |
297 | 283 | * @returns A ParsedTransaction with all instructions decoded |
298 | | - * @throws Error if the transaction cannot be parsed |
299 | | - * |
300 | | - * @example |
301 | | - * ```typescript |
302 | | - * import { parseTransaction, buildTransaction, Transaction } from '@bitgo/wasm-solana'; |
303 | | - * |
304 | | - * // From bytes |
305 | | - * const txBytes = Buffer.from(base64EncodedTx, 'base64'); |
306 | | - * const parsed = parseTransaction(txBytes); |
307 | | - * |
308 | | - * // Directly from a Transaction object (no roundtrip through bytes) |
309 | | - * const tx = buildTransaction(intent); |
310 | | - * const parsed = parseTransaction(tx); |
311 | | - * |
312 | | - * console.log(parsed.feePayer); |
313 | | - * for (const instr of parsed.instructionsData) { |
314 | | - * if (instr.type === 'Transfer') { |
315 | | - * console.log(`Transfer ${instr.amount} from ${instr.fromAddress} to ${instr.toAddress}`); |
316 | | - * } |
317 | | - * } |
318 | | - * ``` |
319 | 284 | */ |
320 | | -export function parseTransaction(input: TransactionInput): ParsedTransaction { |
321 | | - // If input is a Transaction or VersionedTransaction, extract bytes |
322 | | - const bytes = input instanceof Uint8Array ? input : input.toBytes(); |
| 285 | +export function parseTransactionData(bytes: Uint8Array): ParsedTransaction { |
323 | 286 | return ParserNamespace.parse_transaction(bytes) as ParsedTransaction; |
324 | 287 | } |
0 commit comments