Skip to content

Commit 6466226

Browse files
authored
[renderers-js] Use fixed-size codec return types when possible (#718)
1 parent ab43e0e commit 6466226

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+323
-290
lines changed

.changeset/shaky-gifts-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codama/renderers-js': patch
3+
---
4+
5+
Use fixed size return types — e.g. `FixedSizeCodec` or `FixedSizeEncoder` — whenever possible. This avoid fixed-size codecs to be wrongly interpreted as variable-size codecs when wrapped in other codecs.

packages/renderers-js/e2e/anchor/src/generated/instructions/execute.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import {
2121
transformEncoder,
2222
type AccountMeta,
2323
type Address,
24-
type Codec,
25-
type Decoder,
26-
type Encoder,
24+
type FixedSizeCodec,
25+
type FixedSizeDecoder,
26+
type FixedSizeEncoder,
2727
type Instruction,
2828
type InstructionWithAccounts,
2929
type InstructionWithData,
@@ -93,7 +93,7 @@ export type ExecuteInstructionData = {
9393

9494
export type ExecuteInstructionDataArgs = { amount: number | bigint };
9595

96-
export function getExecuteInstructionDataEncoder(): Encoder<ExecuteInstructionDataArgs> {
96+
export function getExecuteInstructionDataEncoder(): FixedSizeEncoder<ExecuteInstructionDataArgs> {
9797
return transformEncoder(
9898
getStructEncoder([
9999
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
@@ -103,14 +103,14 @@ export function getExecuteInstructionDataEncoder(): Encoder<ExecuteInstructionDa
103103
);
104104
}
105105

106-
export function getExecuteInstructionDataDecoder(): Decoder<ExecuteInstructionData> {
106+
export function getExecuteInstructionDataDecoder(): FixedSizeDecoder<ExecuteInstructionData> {
107107
return getStructDecoder([
108108
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
109109
['amount', getU64Decoder()],
110110
]);
111111
}
112112

113-
export function getExecuteInstructionDataCodec(): Codec<
113+
export function getExecuteInstructionDataCodec(): FixedSizeCodec<
114114
ExecuteInstructionDataArgs,
115115
ExecuteInstructionData
116116
> {

packages/renderers-js/e2e/anchor/src/generated/instructions/initialize.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import {
2020
type AccountMeta,
2121
type AccountSignerMeta,
2222
type Address,
23-
type Codec,
24-
type Decoder,
25-
type Encoder,
23+
type FixedSizeCodec,
24+
type FixedSizeDecoder,
25+
type FixedSizeEncoder,
2626
type Instruction,
2727
type InstructionWithAccounts,
2828
type InstructionWithData,
@@ -90,20 +90,20 @@ export type InitializeInstructionData = { discriminator: ReadonlyUint8Array };
9090

9191
export type InitializeInstructionDataArgs = {};
9292

93-
export function getInitializeInstructionDataEncoder(): Encoder<InitializeInstructionDataArgs> {
93+
export function getInitializeInstructionDataEncoder(): FixedSizeEncoder<InitializeInstructionDataArgs> {
9494
return transformEncoder(
9595
getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]),
9696
(value) => ({ ...value, discriminator: INITIALIZE_DISCRIMINATOR })
9797
);
9898
}
9999

100-
export function getInitializeInstructionDataDecoder(): Decoder<InitializeInstructionData> {
100+
export function getInitializeInstructionDataDecoder(): FixedSizeDecoder<InitializeInstructionData> {
101101
return getStructDecoder([
102102
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
103103
]);
104104
}
105105

106-
export function getInitializeInstructionDataCodec(): Codec<
106+
export function getInitializeInstructionDataCodec(): FixedSizeCodec<
107107
InitializeInstructionDataArgs,
108108
InitializeInstructionData
109109
> {

packages/renderers-js/e2e/dummy/src/generated/instructions/instruction3.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import {
1515
transformEncoder,
1616
type AccountMeta,
1717
type Address,
18-
type Codec,
19-
type Decoder,
20-
type Encoder,
18+
type FixedSizeCodec,
19+
type FixedSizeDecoder,
20+
type FixedSizeEncoder,
2121
type Instruction,
2222
type InstructionWithAccounts,
2323
type InstructionWithData,
@@ -42,18 +42,18 @@ export type Instruction3InstructionData = { discriminator: number };
4242

4343
export type Instruction3InstructionDataArgs = {};
4444

45-
export function getInstruction3InstructionDataEncoder(): Encoder<Instruction3InstructionDataArgs> {
45+
export function getInstruction3InstructionDataEncoder(): FixedSizeEncoder<Instruction3InstructionDataArgs> {
4646
return transformEncoder(
4747
getStructEncoder([['discriminator', getU32Encoder()]]),
4848
(value) => ({ ...value, discriminator: INSTRUCTION3_DISCRIMINATOR })
4949
);
5050
}
5151

52-
export function getInstruction3InstructionDataDecoder(): Decoder<Instruction3InstructionData> {
52+
export function getInstruction3InstructionDataDecoder(): FixedSizeDecoder<Instruction3InstructionData> {
5353
return getStructDecoder([['discriminator', getU32Decoder()]]);
5454
}
5555

56-
export function getInstruction3InstructionDataCodec(): Codec<
56+
export function getInstruction3InstructionDataCodec(): FixedSizeCodec<
5757
Instruction3InstructionDataArgs,
5858
Instruction3InstructionData
5959
> {

packages/renderers-js/e2e/dummy/src/generated/instructions/instruction4.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import {
1414
getU64Encoder,
1515
type AccountMeta,
1616
type Address,
17-
type Codec,
18-
type Decoder,
19-
type Encoder,
17+
type FixedSizeCodec,
18+
type FixedSizeDecoder,
19+
type FixedSizeEncoder,
2020
type Instruction,
2121
type InstructionWithAccounts,
2222
type InstructionWithData,
@@ -35,15 +35,15 @@ export type Instruction4InstructionData = { myArgument: bigint };
3535

3636
export type Instruction4InstructionDataArgs = { myArgument: number | bigint };
3737

38-
export function getInstruction4InstructionDataEncoder(): Encoder<Instruction4InstructionDataArgs> {
38+
export function getInstruction4InstructionDataEncoder(): FixedSizeEncoder<Instruction4InstructionDataArgs> {
3939
return getStructEncoder([['myArgument', getU64Encoder()]]);
4040
}
4141

42-
export function getInstruction4InstructionDataDecoder(): Decoder<Instruction4InstructionData> {
42+
export function getInstruction4InstructionDataDecoder(): FixedSizeDecoder<Instruction4InstructionData> {
4343
return getStructDecoder([['myArgument', getU64Decoder()]]);
4444
}
4545

46-
export function getInstruction4InstructionDataCodec(): Codec<
46+
export function getInstruction4InstructionDataCodec(): FixedSizeCodec<
4747
Instruction4InstructionDataArgs,
4848
Instruction4InstructionData
4949
> {

packages/renderers-js/e2e/dummy/src/generated/instructions/instruction5.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import {
1515
transformEncoder,
1616
type AccountMeta,
1717
type Address,
18-
type Codec,
19-
type Decoder,
20-
type Encoder,
18+
type FixedSizeCodec,
19+
type FixedSizeDecoder,
20+
type FixedSizeEncoder,
2121
type Instruction,
2222
type InstructionWithAccounts,
2323
type InstructionWithData,
@@ -36,18 +36,18 @@ export type Instruction5InstructionData = { myArgument: bigint };
3636

3737
export type Instruction5InstructionDataArgs = { myArgument?: number | bigint };
3838

39-
export function getInstruction5InstructionDataEncoder(): Encoder<Instruction5InstructionDataArgs> {
39+
export function getInstruction5InstructionDataEncoder(): FixedSizeEncoder<Instruction5InstructionDataArgs> {
4040
return transformEncoder(
4141
getStructEncoder([['myArgument', getU64Encoder()]]),
4242
(value) => ({ ...value, myArgument: value.myArgument ?? 42 })
4343
);
4444
}
4545

46-
export function getInstruction5InstructionDataDecoder(): Decoder<Instruction5InstructionData> {
46+
export function getInstruction5InstructionDataDecoder(): FixedSizeDecoder<Instruction5InstructionData> {
4747
return getStructDecoder([['myArgument', getU64Decoder()]]);
4848
}
4949

50-
export function getInstruction5InstructionDataCodec(): Codec<
50+
export function getInstruction5InstructionDataCodec(): FixedSizeCodec<
5151
Instruction5InstructionDataArgs,
5252
Instruction5InstructionData
5353
> {

packages/renderers-js/e2e/system/src/generated/accounts/nonce.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import {
2323
getU64Encoder,
2424
type Account,
2525
type Address,
26-
type Codec,
27-
type Decoder,
2826
type EncodedAccount,
29-
type Encoder,
3027
type FetchAccountConfig,
3128
type FetchAccountsConfig,
29+
type FixedSizeCodec,
30+
type FixedSizeDecoder,
31+
type FixedSizeEncoder,
3232
type Lamports,
3333
type MaybeAccount,
3434
type MaybeEncodedAccount,
@@ -60,7 +60,7 @@ export type NonceArgs = {
6060
lamportsPerSignature: Lamports;
6161
};
6262

63-
export function getNonceEncoder(): Encoder<NonceArgs> {
63+
export function getNonceEncoder(): FixedSizeEncoder<NonceArgs> {
6464
return getStructEncoder([
6565
['version', getNonceVersionEncoder()],
6666
['state', getNonceStateEncoder()],
@@ -70,7 +70,7 @@ export function getNonceEncoder(): Encoder<NonceArgs> {
7070
]);
7171
}
7272

73-
export function getNonceDecoder(): Decoder<Nonce> {
73+
export function getNonceDecoder(): FixedSizeDecoder<Nonce> {
7474
return getStructDecoder([
7575
['version', getNonceVersionDecoder()],
7676
['state', getNonceStateDecoder()],
@@ -80,7 +80,7 @@ export function getNonceDecoder(): Decoder<Nonce> {
8080
]);
8181
}
8282

83-
export function getNonceCodec(): Codec<NonceArgs, Nonce> {
83+
export function getNonceCodec(): FixedSizeCodec<NonceArgs, Nonce> {
8484
return combineCodec(getNonceEncoder(), getNonceDecoder());
8585
}
8686

packages/renderers-js/e2e/system/src/generated/instructions/advanceNonceAccount.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import {
1616
type AccountMeta,
1717
type AccountSignerMeta,
1818
type Address,
19-
type Codec,
20-
type Decoder,
21-
type Encoder,
19+
type FixedSizeCodec,
20+
type FixedSizeDecoder,
21+
type FixedSizeEncoder,
2222
type Instruction,
2323
type InstructionWithAccounts,
2424
type InstructionWithData,
@@ -67,7 +67,7 @@ export type AdvanceNonceAccountInstructionData = { discriminator: number };
6767

6868
export type AdvanceNonceAccountInstructionDataArgs = {};
6969

70-
export function getAdvanceNonceAccountInstructionDataEncoder(): Encoder<AdvanceNonceAccountInstructionDataArgs> {
70+
export function getAdvanceNonceAccountInstructionDataEncoder(): FixedSizeEncoder<AdvanceNonceAccountInstructionDataArgs> {
7171
return transformEncoder(
7272
getStructEncoder([['discriminator', getU32Encoder()]]),
7373
(value) => ({
@@ -77,11 +77,11 @@ export function getAdvanceNonceAccountInstructionDataEncoder(): Encoder<AdvanceN
7777
);
7878
}
7979

80-
export function getAdvanceNonceAccountInstructionDataDecoder(): Decoder<AdvanceNonceAccountInstructionData> {
80+
export function getAdvanceNonceAccountInstructionDataDecoder(): FixedSizeDecoder<AdvanceNonceAccountInstructionData> {
8181
return getStructDecoder([['discriminator', getU32Decoder()]]);
8282
}
8383

84-
export function getAdvanceNonceAccountInstructionDataCodec(): Codec<
84+
export function getAdvanceNonceAccountInstructionDataCodec(): FixedSizeCodec<
8585
AdvanceNonceAccountInstructionDataArgs,
8686
AdvanceNonceAccountInstructionData
8787
> {

packages/renderers-js/e2e/system/src/generated/instructions/allocate.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import {
1818
type AccountMeta,
1919
type AccountSignerMeta,
2020
type Address,
21-
type Codec,
22-
type Decoder,
23-
type Encoder,
21+
type FixedSizeCodec,
22+
type FixedSizeDecoder,
23+
type FixedSizeEncoder,
2424
type Instruction,
2525
type InstructionWithAccounts,
2626
type InstructionWithData,
@@ -57,7 +57,7 @@ export type AllocateInstructionData = { discriminator: number; space: bigint };
5757

5858
export type AllocateInstructionDataArgs = { space: number | bigint };
5959

60-
export function getAllocateInstructionDataEncoder(): Encoder<AllocateInstructionDataArgs> {
60+
export function getAllocateInstructionDataEncoder(): FixedSizeEncoder<AllocateInstructionDataArgs> {
6161
return transformEncoder(
6262
getStructEncoder([
6363
['discriminator', getU32Encoder()],
@@ -67,14 +67,14 @@ export function getAllocateInstructionDataEncoder(): Encoder<AllocateInstruction
6767
);
6868
}
6969

70-
export function getAllocateInstructionDataDecoder(): Decoder<AllocateInstructionData> {
70+
export function getAllocateInstructionDataDecoder(): FixedSizeDecoder<AllocateInstructionData> {
7171
return getStructDecoder([
7272
['discriminator', getU32Decoder()],
7373
['space', getU64Decoder()],
7474
]);
7575
}
7676

77-
export function getAllocateInstructionDataCodec(): Codec<
77+
export function getAllocateInstructionDataCodec(): FixedSizeCodec<
7878
AllocateInstructionDataArgs,
7979
AllocateInstructionData
8080
> {

packages/renderers-js/e2e/system/src/generated/instructions/assign.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import {
1818
type AccountMeta,
1919
type AccountSignerMeta,
2020
type Address,
21-
type Codec,
22-
type Decoder,
23-
type Encoder,
21+
type FixedSizeCodec,
22+
type FixedSizeDecoder,
23+
type FixedSizeEncoder,
2424
type Instruction,
2525
type InstructionWithAccounts,
2626
type InstructionWithData,
@@ -60,7 +60,7 @@ export type AssignInstructionData = {
6060

6161
export type AssignInstructionDataArgs = { programAddress: Address };
6262

63-
export function getAssignInstructionDataEncoder(): Encoder<AssignInstructionDataArgs> {
63+
export function getAssignInstructionDataEncoder(): FixedSizeEncoder<AssignInstructionDataArgs> {
6464
return transformEncoder(
6565
getStructEncoder([
6666
['discriminator', getU32Encoder()],
@@ -70,14 +70,14 @@ export function getAssignInstructionDataEncoder(): Encoder<AssignInstructionData
7070
);
7171
}
7272

73-
export function getAssignInstructionDataDecoder(): Decoder<AssignInstructionData> {
73+
export function getAssignInstructionDataDecoder(): FixedSizeDecoder<AssignInstructionData> {
7474
return getStructDecoder([
7575
['discriminator', getU32Decoder()],
7676
['programAddress', getAddressDecoder()],
7777
]);
7878
}
7979

80-
export function getAssignInstructionDataCodec(): Codec<
80+
export function getAssignInstructionDataCodec(): FixedSizeCodec<
8181
AssignInstructionDataArgs,
8282
AssignInstructionData
8383
> {

0 commit comments

Comments
 (0)