Skip to content

Commit cfd5d5f

Browse files
committed
fix(express): consolidateUnspents v1 type codec
Ticket: WP-6717
1 parent c82d952 commit cfd5d5f

File tree

2 files changed

+308
-156
lines changed

2 files changed

+308
-156
lines changed

modules/express/src/typedRoutes/api/v1/consolidateUnspents.ts

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export const ConsolidateUnspentsRequestBody = {
2323
/** Target number of unspents to maintain (defaults to 1) */
2424
target: optional(t.number),
2525
/** Minimum size of unspents to consolidate */
26-
minSize: optional(t.union([t.number, t.string])),
26+
minSize: optional(t.number),
2727
/** Maximum size of unspents to consolidate */
28-
maxSize: optional(t.union([t.number, t.string])),
28+
maxSize: optional(t.number),
2929
/** Maximum number of inputs per consolidation transaction (defaults to 200, must be ≥ 2) */
3030
maxInputCountPerConsolidation: optional(t.number),
3131
/** Maximum number of consolidation iterations (defaults to -1) */
@@ -34,35 +34,62 @@ export const ConsolidateUnspentsRequestBody = {
3434
minConfirms: optional(t.number),
3535
/** Custom fee rate in satoshis per kilobyte */
3636
feeRate: optional(t.number),
37+
/** One-time password for 2FA authentication */
38+
otp: optional(t.string),
39+
/** Optional message to attach to the transaction */
40+
message: optional(t.string),
41+
/** Whether to use instant transaction (BitGo Instant) */
42+
instant: optional(t.boolean),
43+
/** Sequence ID for transaction ordering */
44+
sequenceId: optional(t.string),
45+
/** Target number of blocks for fee estimation */
46+
numBlocks: optional(t.number),
47+
/** Whether minConfirms also applies to change outputs */
48+
enforceMinConfirmsForChange: optional(t.boolean),
49+
/** Target number of unspents for the wallet */
50+
targetWalletUnspents: optional(t.number),
51+
/** Minimum value of unspents to include (in satoshis) - accepts number or string */
52+
minValue: optional(t.union([t.number, t.string])),
53+
/** Maximum value of unspents to include (in satoshis) - accepts number or string */
54+
maxValue: optional(t.union([t.number, t.string])),
55+
/** Comment to attach to the transaction */
56+
comment: optional(t.string),
3757
};
3858

3959
/**
4060
* Response for consolidating unspents in a wallet
61+
*
62+
* Returns an array of transaction objects when consolidation occurs,
63+
* or an empty object {} when no consolidation is needed (target already reached).
64+
* The empty object is how Express serializes an undefined return from the V1 SDK.
4165
*/
42-
export const ConsolidateUnspentsResponse = t.array(
43-
t.type({
44-
/** The status of the transaction ('accepted', 'pendingApproval', or 'otp') */
45-
status: t.string,
46-
/** The transaction hex */
47-
tx: t.string,
48-
/** The transaction hash/ID */
49-
hash: t.string,
50-
/** Whether the transaction is instant */
51-
instant: t.boolean,
52-
/** The instant ID (if applicable) */
53-
instantId: optional(t.string),
54-
/** The fee amount in satoshis */
55-
fee: t.number,
56-
/** The fee rate in satoshis per kilobyte */
57-
feeRate: t.number,
58-
/** Travel rule information */
59-
travelInfos: t.unknown,
60-
/** BitGo fee information (if applicable) */
61-
bitgoFee: optional(t.unknown),
62-
/** Travel rule result (if applicable) */
63-
travelResult: optional(t.unknown),
64-
})
65-
);
66+
export const ConsolidateUnspentsResponse = t.union([
67+
t.array(
68+
t.type({
69+
/** The status of the transaction ('accepted', 'pendingApproval', or 'otp') */
70+
status: t.union([t.literal('accepted'), t.literal('pendingApproval'), t.literal('otp')]),
71+
/** The transaction hex */
72+
tx: t.string,
73+
/** The transaction hash/ID */
74+
hash: t.string,
75+
/** Whether the transaction is instant */
76+
instant: t.boolean,
77+
/** The instant ID (if applicable) */
78+
instantId: optional(t.string),
79+
/** The fee amount in satoshis */
80+
fee: t.number,
81+
/** The fee rate in satoshis per kilobyte */
82+
feeRate: t.number,
83+
/** Travel rule information */
84+
travelInfos: t.unknown,
85+
/** BitGo fee information (if applicable) */
86+
bitgoFee: optional(t.unknown),
87+
/** Travel rule result (if applicable) */
88+
travelResult: optional(t.unknown),
89+
})
90+
),
91+
t.type({}), // Empty object when SDK returns undefined
92+
]);
6693

6794
/**
6895
* Consolidate unspents in a wallet

0 commit comments

Comments
 (0)