Skip to content

Commit 3a2037f

Browse files
OttoAllmendingerllm-git
andcommitted
fix(abstract-utxo): move toCanonicalTransactionRecipient to parseTransaction
Move toCanonicalTransactionRecipient out of the AbstractUtxoCoin class into the parseTransaction module where it's used, removing it from the public API. Issue: BTC-2962 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent 836cbda commit 3a2037f

2 files changed

Lines changed: 23 additions & 15 deletions

File tree

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -592,19 +592,6 @@ export abstract class AbstractUtxoCoin
592592
return this.decodeTransaction(string, decodeWith);
593593
}
594594

595-
toCanonicalTransactionRecipient(output: { valueString: string; address?: string }): {
596-
amount: bigint;
597-
address: string;
598-
} {
599-
const amount = BigInt(output.valueString);
600-
assertValidTransactionRecipient({ amount, address: output.address });
601-
assert(output.address, 'address is required');
602-
if (isScriptRecipient(output.address)) {
603-
return { amount, address: output.address };
604-
}
605-
return { amount, address: this.canonicalAddress(output.address) };
606-
}
607-
608595
/**
609596
* Extract and fill transaction details such as internal/change spend, external spend (explicit vs. implicit), etc.
610597
* @param params

modules/abstract-utxo/src/transaction/fixedScript/parseTransaction.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import type { AbstractUtxoCoin, ParseTransactionOptions } from '../../abstractUt
88
import type { FixedScriptWalletOutput, Output, ParsedTransaction } from '../types';
99
import { fetchKeychains, getKeySignatures, toKeychainTriple, UtxoKeychain, UtxoNamedKeychains } from '../../keychains';
1010
import { ComparableOutput, outputDifference } from '../outputDifference';
11-
import { fromExtendedAddressFormatToScript, toExtendedAddressFormat } from '../recipient';
11+
import {
12+
assertValidTransactionRecipient,
13+
fromExtendedAddressFormatToScript,
14+
isScriptRecipient,
15+
toExtendedAddressFormat,
16+
} from '../recipient';
1217

1318
import type { TransactionExplanation } from './explainTransaction';
1419
import { CustomChangeOptions, parseOutput } from './parseOutput';
@@ -17,6 +22,22 @@ export type ComparableOutputWithExternal<TValue> = ComparableOutput<TValue> & {
1722
external: boolean | undefined;
1823
};
1924

25+
function toCanonicalTransactionRecipient(
26+
coin: AbstractUtxoCoin,
27+
output: { valueString: string; address?: string }
28+
): {
29+
amount: bigint;
30+
address: string;
31+
} {
32+
const amount = BigInt(output.valueString);
33+
assertValidTransactionRecipient({ amount, address: output.address });
34+
assert(output.address, 'address is required');
35+
if (isScriptRecipient(output.address)) {
36+
return { amount, address: output.address };
37+
}
38+
return { amount, address: coin.canonicalAddress(output.address) };
39+
}
40+
2041
async function parseRbfTransaction<TNumber extends bigint | number>(
2142
coin: AbstractUtxoCoin,
2243
params: ParseTransactionOptions<TNumber>
@@ -33,7 +54,7 @@ async function parseRbfTransaction<TNumber extends bigint | number>(
3354
if (output.wallet === wallet.id()) {
3455
return [];
3556
}
36-
return [coin.toCanonicalTransactionRecipient(output)];
57+
return [toCanonicalTransactionRecipient(coin, output)];
3758
}
3859
);
3960

0 commit comments

Comments
 (0)