Skip to content

Commit bb66fb9

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): move transaction types to separate file
Refactor transaction-related types out of abstractUtxoCoin.ts into a new transaction/types.ts file. This helps organize code better and reduces coupling between modules. Move BaseOutput, FixedScriptWalletOutput, Output, BaseParsedTransactionOutputs, BaseParsedTransaction, and ParsedTransaction to the new file. Also moved isWalletOutput helper to its relevant module. Issue: BTC-2732 Co-authored-by: llm-git <[email protected]>
1 parent ba2343d commit bb66fb9

File tree

17 files changed

+88
-91
lines changed

17 files changed

+88
-91
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ import {
7474
import { assertDescriptorWalletAddress, getDescriptorMapFromWallet, isDescriptorWallet } from './descriptor';
7575
import { getChainFromNetwork, getFamilyFromNetwork, getFullNameFromNetwork } from './names';
7676
import { assertFixedScriptWalletAddress } from './address/fixedScript';
77-
import { CustomChangeOptions } from './transaction/fixedScript';
78-
import { toBip32Triple, UtxoKeychain, UtxoNamedKeychains } from './keychains';
77+
import { ParsedTransaction } from './transaction/types';
78+
import { toBip32Triple, UtxoKeychain } from './keychains';
7979
import { verifyKeySignature, verifyUserPublicKey } from './verifyKey';
8080
import { getPolicyForEnv } from './descriptor/validatePolicy';
8181
import { signTransaction } from './transaction/signTransaction';
@@ -186,33 +186,11 @@ export interface VerifyAddressOptions<TCoinSpecific extends UtxoCoinSpecific> ex
186186
coinSpecific?: TCoinSpecific;
187187
}
188188

189-
export interface BaseOutput<TAmount = string | number> {
190-
address: string;
191-
amount: TAmount;
192-
// Even though this external flag is redundant with the chain property, it is necessary for backwards compatibility
193-
// with legacy transaction format.
194-
external?: boolean;
195-
}
196-
197-
export interface FixedScriptWalletOutput<TAmount = string | number> extends BaseOutput<TAmount> {
198-
needsCustomChangeKeySignatureVerification?: boolean;
199-
chain: number;
200-
index: number;
201-
}
202-
203-
export type Output<TAmount = string | number> = BaseOutput<TAmount> | FixedScriptWalletOutput<TAmount>;
204-
205189
export type Bip322Message = {
206190
address: string;
207191
message: string;
208192
};
209193

210-
export function isWalletOutput(output: Output): output is FixedScriptWalletOutput {
211-
return (
212-
(output as FixedScriptWalletOutput).chain !== undefined && (output as FixedScriptWalletOutput).index !== undefined
213-
);
214-
}
215-
216194
export interface TransactionInfo<TNumber extends number | bigint = number> {
217195
/** Maps txid to txhex. Required for offline signing. */
218196
txHexes?: Record<string, string>;
@@ -255,42 +233,6 @@ export interface ParseTransactionOptions<TNumber extends number | bigint = numbe
255233
reqId?: IRequestTracer;
256234
}
257235

258-
export type BaseParsedTransactionOutputs<TNumber extends number | bigint, TOutput> = {
259-
/** all transaction outputs */
260-
outputs: TOutput[];
261-
/** transaction outputs that were specified as recipients but are missing from the transaction */
262-
missingOutputs: TOutput[];
263-
/** transaction outputs that were specified as recipients and are present in the transaction */
264-
explicitExternalOutputs: TOutput[];
265-
/** transaction outputs that were not specified as recipients but are present in the transaction */
266-
implicitExternalOutputs: TOutput[];
267-
/** transaction outputs that are change outputs */
268-
changeOutputs: TOutput[];
269-
/** sum of all explicit external outputs */
270-
explicitExternalSpendAmount: TNumber;
271-
/** sum of all implicit external outputs */
272-
implicitExternalSpendAmount: TNumber;
273-
};
274-
275-
export type BaseParsedTransaction<TNumber extends number | bigint, TOutput> = BaseParsedTransactionOutputs<
276-
TNumber,
277-
TOutput
278-
> /** Some extra properties that have nothing to do with an individual transaction */ & {
279-
keychains: UtxoNamedKeychains;
280-
keySignatures: {
281-
backupPub?: string;
282-
bitgoPub?: string;
283-
};
284-
needsCustomChangeKeySignatureVerification: boolean;
285-
customChange?: CustomChangeOptions;
286-
};
287-
288-
/**
289-
* This type is a bit silly because it allows the type for the aggregate amounts to be different from the type of
290-
* individual amounts.
291-
*/
292-
export type ParsedTransaction<TNumber extends number | bigint = number> = BaseParsedTransaction<TNumber, Output>;
293-
294236
export interface GenerateAddressOptions {
295237
addressType?: ScriptType2Of3;
296238
threshold?: number;

modules/abstract-utxo/src/impl/doge/doge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import {
77
SignTransactionOptions,
88
ExplainTransactionOptions,
99
ParseTransactionOptions,
10-
ParsedTransaction,
1110
VerifyTransactionOptions,
1211
RecoverFromWrongChainOptions,
1312
TransactionInfo,
1413
TransactionPrebuild,
1514
} from '../../abstractUtxoCoin';
15+
import { ParsedTransaction } from '../../transaction/types';
1616
import type { TransactionExplanation } from '../../transaction/fixedScript/explainTransaction';
1717
import type { CrossChainRecoverySigned, CrossChainRecoveryUnsigned } from '../../recovery/crossChainRecovery';
1818

modules/abstract-utxo/src/transaction/descriptor/parse.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@ import * as utxolib from '@bitgo/utxo-lib';
22
import { ITransactionRecipient } from '@bitgo/sdk-core';
33
import * as coreDescriptors from '@bitgo/utxo-core/descriptor';
44

5-
import {
6-
AbstractUtxoCoin,
7-
BaseOutput,
8-
BaseParsedTransaction,
9-
BaseParsedTransactionOutputs,
10-
ParseTransactionOptions,
11-
} from '../../abstractUtxoCoin';
5+
import { AbstractUtxoCoin, ParseTransactionOptions } from '../../abstractUtxoCoin';
6+
import { BaseOutput, BaseParsedTransaction, BaseParsedTransactionOutputs } from '../types';
127
import { getKeySignatures, toBip32Triple, UtxoNamedKeychains } from '../../keychains';
138
import { getDescriptorMapFromWallet, getPolicyForEnv } from '../../descriptor';
149
import { IDescriptorWallet } from '../../descriptor/descriptorWallet';

modules/abstract-utxo/src/transaction/descriptor/parseToAmountType.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { AbstractUtxoCoin, BaseOutput, BaseParsedTransaction, ParseTransactionOptions } from '../../abstractUtxoCoin';
1+
import { AbstractUtxoCoin, ParseTransactionOptions } from '../../abstractUtxoCoin';
2+
import { BaseOutput, BaseParsedTransaction } from '../types';
23
import { IDescriptorWallet } from '../../descriptor/descriptorWallet';
34

45
import { parse, ParsedDescriptorTransaction } from './parse';

modules/abstract-utxo/src/transaction/descriptor/verifyTransaction.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ import * as utxolib from '@bitgo/utxo-lib';
22
import { ITransactionRecipient, TxIntentMismatchError } from '@bitgo/sdk-core';
33
import { DescriptorMap } from '@bitgo/utxo-core/descriptor';
44

5-
import {
6-
AbstractUtxoCoin,
7-
BaseOutput,
8-
BaseParsedTransactionOutputs,
9-
VerifyTransactionOptions,
10-
} from '../../abstractUtxoCoin';
5+
import { AbstractUtxoCoin, VerifyTransactionOptions } from '../../abstractUtxoCoin';
6+
import { BaseOutput, BaseParsedTransactionOutputs } from '../types';
117

128
import { toBaseParsedTransactionOutputsFromPsbt } from './parse';
139

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fixedScriptWallet } from '@bitgo/wasm-utxo';
22
import { Triple } from '@bitgo/sdk-core';
33

4-
import type { Output, FixedScriptWalletOutput } from '../../abstractUtxoCoin';
4+
import type { FixedScriptWalletOutput, Output } from '../types';
55

66
import type { TransactionExplanationWasm } from './explainTransaction';
77

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { bitgo } from '@bitgo/utxo-lib';
55
import { ITransactionExplanation as BaseTransactionExplanation, Triple } from '@bitgo/sdk-core';
66
import * as utxocore from '@bitgo/utxo-core';
77

8-
import type { Output, Bip322Message, FixedScriptWalletOutput } from '../../abstractUtxoCoin';
8+
import type { Bip322Message } from '../../abstractUtxoCoin';
9+
import type { Output, FixedScriptWalletOutput } from '../types';
910
import { toExtendedAddressFormat } from '../recipient';
1011
import { getPayGoVerificationPubkey } from '../getPayGoVerificationPubkey';
1112

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ import {
1212
Triple,
1313
} from '@bitgo/sdk-core';
1414

15-
import { AbstractUtxoCoin, Output, isWalletOutput } from '../../abstractUtxoCoin';
15+
import { AbstractUtxoCoin } from '../../abstractUtxoCoin';
16+
import { Output, FixedScriptWalletOutput } from '../types';
1617

1718
const debug = debugLib('bitgo:v2:parseoutput');
1819

20+
export function isWalletOutput(output: Output): output is FixedScriptWalletOutput {
21+
return (
22+
(output as FixedScriptWalletOutput).chain !== undefined && (output as FixedScriptWalletOutput).index !== undefined
23+
);
24+
}
25+
1926
interface HandleVerifyAddressErrorResponse {
2027
external: boolean;
2128
needsCustomChangeKeySignatureVerification?: boolean;

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import _ from 'lodash';
44
import { Triple, VerificationOptions, Wallet } from '@bitgo/sdk-core';
55
import * as utxolib from '@bitgo/utxo-lib';
66

7-
import type {
8-
AbstractUtxoCoin,
9-
FixedScriptWalletOutput,
10-
Output,
11-
ParsedTransaction,
12-
ParseTransactionOptions,
13-
} from '../../abstractUtxoCoin';
7+
import type { AbstractUtxoCoin, ParseTransactionOptions } from '../../abstractUtxoCoin';
8+
import type { FixedScriptWalletOutput, Output, ParsedTransaction } from '../types';
149
import { fetchKeychains, getKeySignatures, toKeychainTriple, UtxoKeychain, UtxoNamedKeychains } from '../../keychains';
1510
import { ComparableOutput, outputDifference } from '../outputDifference';
1611
import { fromExtendedAddressFormatToScript, toExtendedAddressFormat } from '../recipient';

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import BigNumber from 'bignumber.js';
44
import { BitGoBase, TxIntentMismatchError } from '@bitgo/sdk-core';
55
import * as utxolib from '@bitgo/utxo-lib';
66

7-
import { AbstractUtxoCoin, Output, ParsedTransaction, VerifyTransactionOptions } from '../../abstractUtxoCoin';
7+
import { AbstractUtxoCoin, VerifyTransactionOptions } from '../../abstractUtxoCoin';
8+
import { Output, ParsedTransaction } from '../types';
89
import { verifyCustomChangeKeySignatures, verifyKeySignature, verifyUserPublicKey } from '../../verifyKey';
910
import { getPsbtTxInputs, getTxInputs } from '../fetchInputs';
1011

0 commit comments

Comments
 (0)