1- import { WasmDashTransaction , WasmTransaction , WasmZcashTransaction } from "./wasm/wasm_utxo.js" ;
1+ import {
2+ WasmDashTransaction ,
3+ WasmTransaction ,
4+ WasmZcashTransaction ,
5+ type TxInputData ,
6+ type TxOutputData ,
7+ type TxOutputDataWithAddress ,
8+ } from "./wasm/wasm_utxo.js" ;
9+ import type { CoinName } from "./coinName.js" ;
210
3- /**
4- * Common interface for all transaction types
5- */
6- export interface ITransaction {
11+ /** Common read-only interface shared by transactions and PSBTs */
12+ export interface ITransactionCommon < TInput , TOutput > {
13+ inputCount ( ) : number ;
14+ outputCount ( ) : number ;
15+ version ( ) : number ;
16+ lockTime ( ) : number ;
17+ getInputs ( ) : TInput [ ] ;
18+ getOutputs ( ) : TOutput [ ] ;
19+ }
20+
21+ /** Common interface for all transaction types */
22+ export interface ITransaction extends ITransactionCommon < TxInputData , TxOutputData > {
723 toBytes ( ) : Uint8Array ;
824 getId ( ) : string ;
25+ getOutputsWithAddress ( coin : CoinName ) : TxOutputDataWithAddress [ ] ;
926}
1027
1128/**
@@ -27,9 +44,7 @@ export class Transaction implements ITransaction {
2744 return new Transaction ( WasmTransaction . from_bytes ( bytes ) ) ;
2845 }
2946
30- /**
31- * @internal Create from WASM instance directly (avoids re-parsing bytes)
32- */
47+ /** @internal Create from WASM instance directly (avoids re-parsing bytes) */
3348 static fromWasm ( wasm : WasmTransaction ) : Transaction {
3449 return new Transaction ( wasm ) ;
3550 }
@@ -84,9 +99,35 @@ export class Transaction implements ITransaction {
8499 return this . _wasm . get_vsize ( ) ;
85100 }
86101
87- /**
88- * @internal
89- */
102+ inputCount ( ) : number {
103+ return this . _wasm . input_count ( ) ;
104+ }
105+
106+ outputCount ( ) : number {
107+ return this . _wasm . output_count ( ) ;
108+ }
109+
110+ version ( ) : number {
111+ return this . _wasm . version ( ) ;
112+ }
113+
114+ lockTime ( ) : number {
115+ return this . _wasm . lock_time ( ) ;
116+ }
117+
118+ getInputs ( ) : TxInputData [ ] {
119+ return this . _wasm . get_inputs ( ) as TxInputData [ ] ;
120+ }
121+
122+ getOutputs ( ) : TxOutputData [ ] {
123+ return this . _wasm . get_outputs ( ) as TxOutputData [ ] ;
124+ }
125+
126+ getOutputsWithAddress ( coin : CoinName ) : TxOutputDataWithAddress [ ] {
127+ return this . _wasm . get_outputs_with_address ( coin ) as TxOutputDataWithAddress [ ] ;
128+ }
129+
130+ /** @internal */
90131 get wasm ( ) : WasmTransaction {
91132 return this . _wasm ;
92133 }
@@ -104,9 +145,7 @@ export class ZcashTransaction implements ITransaction {
104145 return new ZcashTransaction ( WasmZcashTransaction . from_bytes ( bytes ) ) ;
105146 }
106147
107- /**
108- * @internal Create from WASM instance directly (avoids re-parsing bytes)
109- */
148+ /** @internal Create from WASM instance directly (avoids re-parsing bytes) */
110149 static fromWasm ( wasm : WasmZcashTransaction ) : ZcashTransaction {
111150 return new ZcashTransaction ( wasm ) ;
112151 }
@@ -127,9 +166,35 @@ export class ZcashTransaction implements ITransaction {
127166 return this . _wasm . get_txid ( ) ;
128167 }
129168
130- /**
131- * @internal
132- */
169+ inputCount ( ) : number {
170+ return this . _wasm . input_count ( ) ;
171+ }
172+
173+ outputCount ( ) : number {
174+ return this . _wasm . output_count ( ) ;
175+ }
176+
177+ version ( ) : number {
178+ return this . _wasm . version ( ) ;
179+ }
180+
181+ lockTime ( ) : number {
182+ return this . _wasm . lock_time ( ) ;
183+ }
184+
185+ getInputs ( ) : TxInputData [ ] {
186+ return this . _wasm . get_inputs ( ) as TxInputData [ ] ;
187+ }
188+
189+ getOutputs ( ) : TxOutputData [ ] {
190+ return this . _wasm . get_outputs ( ) as TxOutputData [ ] ;
191+ }
192+
193+ getOutputsWithAddress ( coin : CoinName ) : TxOutputDataWithAddress [ ] {
194+ return this . _wasm . get_outputs_with_address ( coin ) as TxOutputDataWithAddress [ ] ;
195+ }
196+
197+ /** @internal */
133198 get wasm ( ) : WasmZcashTransaction {
134199 return this . _wasm ;
135200 }
@@ -147,9 +212,7 @@ export class DashTransaction implements ITransaction {
147212 return new DashTransaction ( WasmDashTransaction . from_bytes ( bytes ) ) ;
148213 }
149214
150- /**
151- * @internal Create from WASM instance directly (avoids re-parsing bytes)
152- */
215+ /** @internal Create from WASM instance directly (avoids re-parsing bytes) */
153216 static fromWasm ( wasm : WasmDashTransaction ) : DashTransaction {
154217 return new DashTransaction ( wasm ) ;
155218 }
@@ -170,9 +233,35 @@ export class DashTransaction implements ITransaction {
170233 return this . _wasm . get_txid ( ) ;
171234 }
172235
173- /**
174- * @internal
175- */
236+ inputCount ( ) : number {
237+ return this . _wasm . input_count ( ) ;
238+ }
239+
240+ outputCount ( ) : number {
241+ return this . _wasm . output_count ( ) ;
242+ }
243+
244+ version ( ) : number {
245+ return this . _wasm . version ( ) ;
246+ }
247+
248+ lockTime ( ) : number {
249+ return this . _wasm . lock_time ( ) ;
250+ }
251+
252+ getInputs ( ) : TxInputData [ ] {
253+ return this . _wasm . get_inputs ( ) as TxInputData [ ] ;
254+ }
255+
256+ getOutputs ( ) : TxOutputData [ ] {
257+ return this . _wasm . get_outputs ( ) as TxOutputData [ ] ;
258+ }
259+
260+ getOutputsWithAddress ( coin : CoinName ) : TxOutputDataWithAddress [ ] {
261+ return this . _wasm . get_outputs_with_address ( coin ) as TxOutputDataWithAddress [ ] ;
262+ }
263+
264+ /** @internal */
176265 get wasm ( ) : WasmDashTransaction {
177266 return this . _wasm ;
178267 }
0 commit comments