Skip to content

Commit 75da414

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): refactor tx format decision into separate method
Extract logic to determine transaction format into a dedicated method to improve readability and maintainability. Now using explicit return values instead of relying on a boolean evaluation for PSBT format. Issue: BTC-2732 Co-authored-by: llm-git <[email protected]>
1 parent 2d51578 commit 75da414

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -982,14 +982,14 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
982982
};
983983
}
984984

985-
private shouldDefaultToPsbtTxFormat(buildParams: ExtraPrebuildParamsOptions & { wallet: Wallet }) {
986-
const walletFlagMusigKp = buildParams.wallet.flag('musigKp') === 'true';
987-
const isHotWallet = buildParams.wallet.type() === 'hot';
985+
private getTxFormat(wallet: Wallet, requestedTxFormat: unknown): TxFormat | undefined {
986+
const walletFlagMusigKp = wallet.flag('musigKp') === 'true';
987+
const isHotWallet = wallet.type() === 'hot';
988988

989989
// if not txFormat is already specified figure out if we should default to psbt format
990-
return (
991-
buildParams.txFormat === undefined &&
992-
(buildParams.wallet.subType() === 'distributedCustody' ||
990+
if (
991+
requestedTxFormat === undefined &&
992+
(wallet.subType() === 'distributedCustody' ||
993993
// default to testnet for all utxo coins except zcash
994994
(isTestnet(this.network) &&
995995
// FIXME(BTC-1322): fix zcash PSBT support
@@ -999,20 +999,19 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
999999
(isMainnet(this.network) && getMainnet(this.network) === utxolib.networks.bitcoin && isHotWallet) ||
10001000
// default to psbt if it has the wallet flag
10011001
walletFlagMusigKp)
1002-
);
1002+
) {
1003+
return 'psbt';
1004+
}
1005+
1006+
return requestedTxFormat as TxFormat;
10031007
}
10041008

10051009
async getExtraPrebuildParams(buildParams: ExtraPrebuildParamsOptions & { wallet: Wallet }): Promise<{
10061010
txFormat?: TxFormat;
10071011
changeAddressType?: ScriptType2Of3[] | ScriptType2Of3;
10081012
}> {
1009-
let txFormat = buildParams.txFormat as TxFormat | undefined;
10101013
let changeAddressType = buildParams.changeAddressType as ScriptType2Of3[] | ScriptType2Of3 | undefined;
10111014

1012-
if (this.shouldDefaultToPsbtTxFormat(buildParams)) {
1013-
txFormat = 'psbt';
1014-
}
1015-
10161015
// if the addressType is not specified, we need to default to p2trMusig2 for testnet hot wallets for staged rollout of p2trMusig2
10171016
if (
10181017
buildParams.addressType === undefined && // addressType is deprecated and replaced by `changeAddress`
@@ -1024,7 +1023,7 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
10241023
}
10251024

10261025
return {
1027-
txFormat,
1026+
txFormat: this.getTxFormat(buildParams.wallet, buildParams.txFormat),
10281027
changeAddressType,
10291028
};
10301029
}

0 commit comments

Comments
 (0)