Skip to content

Commit 49179a2

Browse files
OttoAllmendingerllm-git
andcommitted
refactor(wasm-utxo)!: extract ITransactionCommon interface
BREAKING CHANGE: version and lockTime are now methods instead of getters. Update code from `tx.version` to `tx.version()` and `tx.lockTime` to `tx.lockTime()`. Extract shared transaction and PSBT properties into ITransactionCommon interface to reduce duplication between ITransaction and IPsbt. Convert version and lockTime from getters to methods for consistency with other interface methods. Issue: BTC-2976 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent 7ac35da commit 49179a2

3 files changed

Lines changed: 27 additions & 24 deletions

File tree

packages/wasm-utxo/js/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,11 @@ declare module "./wasm/wasm_utxo.js" {
116116
export { WrapDescriptor as Descriptor } from "./wasm/wasm_utxo.js";
117117
export { WrapMiniscript as Miniscript } from "./wasm/wasm_utxo.js";
118118
export { Psbt } from "./descriptorWallet/Psbt.js";
119-
export { DashTransaction, Transaction, ZcashTransaction, type ITransaction } from "./transaction.js";
119+
export {
120+
DashTransaction,
121+
Transaction,
122+
ZcashTransaction,
123+
type ITransaction,
124+
type ITransactionCommon,
125+
} from "./transaction.js";
120126
export { hasPsbtMagic, type IPsbt, type IPsbtWithAddress } from "./psbt.js";

packages/wasm-utxo/js/psbt.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import type { PsbtInputData, PsbtOutputData, PsbtOutputDataWithAddress } from "./wasm/wasm_utxo.js";
22
import type { BIP32 } from "./bip32.js";
3+
import type { ITransactionCommon } from "./transaction.js";
34

45
/** Common interface for PSBT types */
5-
export interface IPsbt {
6-
inputCount(): number;
7-
outputCount(): number;
8-
getInputs(): PsbtInputData[];
9-
getOutputs(): PsbtOutputData[];
6+
export interface IPsbt extends ITransactionCommon<PsbtInputData, PsbtOutputData> {
107
getGlobalXpubs(): BIP32[];
11-
version(): number;
12-
lockTime(): number;
138
unsignedTxId(): string;
149
addInputAtIndex(
1510
index: number,

packages/wasm-utxo/js/transaction.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ import {
88
} from "./wasm/wasm_utxo.js";
99
import type { CoinName } from "./coinName.js";
1010

11-
/**
12-
* Common interface for all transaction types
13-
*/
14-
export interface ITransaction {
15-
toBytes(): Uint8Array;
16-
getId(): string;
11+
/** Common read-only interface shared by transactions and PSBTs */
12+
export interface ITransactionCommon<TInput, TOutput> {
1713
inputCount(): number;
1814
outputCount(): number;
19-
get version(): number;
20-
get lockTime(): number;
21-
getInputs(): TxInputData[];
22-
getOutputs(): TxOutputData[];
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> {
23+
toBytes(): Uint8Array;
24+
getId(): string;
2325
getOutputsWithAddress(coin: CoinName): TxOutputDataWithAddress[];
2426
}
2527

@@ -105,11 +107,11 @@ export class Transaction implements ITransaction {
105107
return this._wasm.output_count();
106108
}
107109

108-
get version(): number {
110+
version(): number {
109111
return this._wasm.version();
110112
}
111113

112-
get lockTime(): number {
114+
lockTime(): number {
113115
return this._wasm.lock_time();
114116
}
115117

@@ -172,11 +174,11 @@ export class ZcashTransaction implements ITransaction {
172174
return this._wasm.output_count();
173175
}
174176

175-
get version(): number {
177+
version(): number {
176178
return this._wasm.version();
177179
}
178180

179-
get lockTime(): number {
181+
lockTime(): number {
180182
return this._wasm.lock_time();
181183
}
182184

@@ -239,11 +241,11 @@ export class DashTransaction implements ITransaction {
239241
return this._wasm.output_count();
240242
}
241243

242-
get version(): number {
244+
version(): number {
243245
return this._wasm.version();
244246
}
245247

246-
get lockTime(): number {
248+
lockTime(): number {
247249
return this._wasm.lock_time();
248250
}
249251

0 commit comments

Comments
 (0)