|
1 | 1 | import type { RpcRequest, RpcRequestTransformer } from '@solana/rpc-spec-types';
|
2 | 2 | import type { Commitment } from '@solana/rpc-types';
|
3 | 3 |
|
| 4 | +import { applyDefaultCommitment } from './request-transformer-default-commitment-internal'; |
| 5 | + |
4 | 6 | export function getDefaultCommitmentRequestTransformer({
|
5 | 7 | defaultCommitment,
|
6 | 8 | optionsObjectPositionByMethod,
|
@@ -33,60 +35,3 @@ export function getDefaultCommitmentRequestTransformer({
|
33 | 35 | });
|
34 | 36 | };
|
35 | 37 | }
|
36 |
| - |
37 |
| -export function applyDefaultCommitment({ |
38 |
| - commitmentPropertyName, |
39 |
| - params, |
40 |
| - optionsObjectPositionInParams, |
41 |
| - overrideCommitment, |
42 |
| -}: Readonly<{ |
43 |
| - commitmentPropertyName: string; |
44 |
| - optionsObjectPositionInParams: number; |
45 |
| - overrideCommitment?: Commitment; |
46 |
| - params: unknown[]; |
47 |
| -}>) { |
48 |
| - const paramInTargetPosition = params[optionsObjectPositionInParams]; |
49 |
| - if ( |
50 |
| - // There's no config. |
51 |
| - paramInTargetPosition === undefined || |
52 |
| - // There is a config object. |
53 |
| - (paramInTargetPosition && typeof paramInTargetPosition === 'object' && !Array.isArray(paramInTargetPosition)) |
54 |
| - ) { |
55 |
| - if ( |
56 |
| - // The config object already has a commitment set. |
57 |
| - paramInTargetPosition && |
58 |
| - commitmentPropertyName in paramInTargetPosition |
59 |
| - ) { |
60 |
| - if ( |
61 |
| - !paramInTargetPosition[commitmentPropertyName as keyof typeof paramInTargetPosition] || |
62 |
| - paramInTargetPosition[commitmentPropertyName as keyof typeof paramInTargetPosition] === 'finalized' |
63 |
| - ) { |
64 |
| - // Delete the commitment property; `finalized` is already the server default. |
65 |
| - const nextParams = [...params]; |
66 |
| - const { |
67 |
| - [commitmentPropertyName as keyof typeof paramInTargetPosition]: _, // eslint-disable-line @typescript-eslint/no-unused-vars |
68 |
| - ...rest |
69 |
| - } = paramInTargetPosition; |
70 |
| - if (Object.keys(rest).length > 0) { |
71 |
| - nextParams[optionsObjectPositionInParams] = rest; |
72 |
| - } else { |
73 |
| - if (optionsObjectPositionInParams === nextParams.length - 1) { |
74 |
| - nextParams.length--; |
75 |
| - } else { |
76 |
| - nextParams[optionsObjectPositionInParams] = undefined; |
77 |
| - } |
78 |
| - } |
79 |
| - return nextParams; |
80 |
| - } |
81 |
| - } else if (overrideCommitment !== 'finalized') { |
82 |
| - // Apply the default commitment. |
83 |
| - const nextParams = [...params]; |
84 |
| - nextParams[optionsObjectPositionInParams] = { |
85 |
| - ...paramInTargetPosition, |
86 |
| - [commitmentPropertyName]: overrideCommitment, |
87 |
| - }; |
88 |
| - return nextParams; |
89 |
| - } |
90 |
| - } |
91 |
| - return params; |
92 |
| -} |
0 commit comments