Skip to content

Commit

Permalink
Merge pull request #4836 from BitGo/BTC-000
Browse files Browse the repository at this point in the history
feat: default to psbt format for btc hot wallets
  • Loading branch information
lcovar authored Aug 19, 2024
2 parents e415178 + 0e12c94 commit 619a2df
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions modules/abstract-utxo/src/abstractUtxoCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @prettier
*/
import * as utxolib from '@bitgo/utxo-lib';
import { bip32, BIP32Interface, bitgo, getMainnet, isTestnet } from '@bitgo/utxo-lib';
import { bip32, BIP32Interface, bitgo, getMainnet, isMainnet, isTestnet } from '@bitgo/utxo-lib';
import * as assert from 'assert';
import * as bitcoinMessage from 'bitcoinjs-message';
import { randomBytes } from 'crypto';
Expand Down Expand Up @@ -1512,26 +1512,34 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
};
}

async getExtraPrebuildParams(buildParams: ExtraPrebuildParamsOptions & { wallet: Wallet }): Promise<{
txFormat?: 'legacy' | 'psbt';
changeAddressType?: ScriptType2Of3[] | ScriptType2Of3;
}> {
let txFormat = buildParams.txFormat as 'legacy' | 'psbt' | undefined;
let changeAddressType = buildParams.changeAddressType as ScriptType2Of3[] | ScriptType2Of3 | undefined;

private shouldDefaultToPsbtTxFormat(buildParams: ExtraPrebuildParamsOptions & { wallet: Wallet }) {
const walletFlagMusigKp = buildParams.wallet.flag('musigKp') === 'true';
const isHotWallet = buildParams.wallet.type() === 'hot';

// if the txFormat is not specified, we need to default to psbt for distributed custody wallets or testnet hot wallets
if (
// if not txFormat is already specified figure out if we should default to psbt format
return (
buildParams.txFormat === undefined &&
(buildParams.wallet.subType() === 'distributedCustody' ||
// default to testnet for all utxo coins except zcash
(isTestnet(this.network) &&
// FIXME(BTC-1322): fix zcash PSBT support
getMainnet(this.network) !== utxolib.networks.zcash &&
buildParams.wallet.type() === 'hot') ||
// FIXME(BTC-776): default to psbt for all mainnet wallets in the future
isHotWallet) ||
// if mainnet, only default to psbt for btc hot wallets
(isMainnet(this.network) && getMainnet(this.network) === utxolib.networks.bitcoin && isHotWallet) ||
// default to psbt if it has the wallet flag
walletFlagMusigKp)
) {
);
}

async getExtraPrebuildParams(buildParams: ExtraPrebuildParamsOptions & { wallet: Wallet }): Promise<{
txFormat?: 'legacy' | 'psbt';
changeAddressType?: ScriptType2Of3[] | ScriptType2Of3;
}> {
let txFormat = buildParams.txFormat as 'legacy' | 'psbt' | undefined;
let changeAddressType = buildParams.changeAddressType as ScriptType2Of3[] | ScriptType2Of3 | undefined;

if (this.shouldDefaultToPsbtTxFormat(buildParams)) {
txFormat = 'psbt';
}

Expand Down

0 comments on commit 619a2df

Please sign in to comment.