Skip to content

Commit c2c1676

Browse files
committed
cleanup
1 parent 2d3868a commit c2c1676

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

scripts/generate-clients.mts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ const idl = JSON.parse(
1111
);
1212
const codama = c.createFromRoot(idl);
1313

14-
// Rename the program from solanaStakeInterface to stake
14+
// Rename the program.
1515
codama.update(
1616
c.updateProgramsVisitor({
1717
solanaStakeInterface: { name: 'stake' },
1818
})
1919
);
2020

21-
// Delete deprecated/disabled instructions
2221
codama.update(
2322
c.updateInstructionsVisitor({
23+
// Deprecated instruction.
2424
redelegate: { delete: true },
2525
})
2626
);
@@ -89,24 +89,19 @@ codama.update(
8989
},
9090
},
9191
{
92-
// instruction: use omitted optional accounts + fix discriminator u8 -> u32
93-
select: '[instructionNode]',
92+
// enum discriminator -> u32
93+
select: '[definedTypeNode]stakeState.[enumTypeNode]',
9494
transform: (node) => {
95-
c.assertIsNode(node, 'instructionNode');
95+
c.assertIsNode(node, 'enumTypeNode');
9696
return {
9797
...node,
98-
optionalAccountStrategy: 'omitted',
99-
arguments: node.arguments.map((arg) =>
100-
arg.name === 'discriminator'
101-
? { ...arg, type: c.numberTypeNode('u32') }
102-
: arg
103-
),
98+
size: c.numberTypeNode('u32'),
10499
};
105100
},
106101
},
107102
{
108103
// enum discriminator -> u32
109-
select: '[definedTypeNode]stakeState.[enumTypeNode]',
104+
select: '[definedTypeNode]stakeStateV2.[enumTypeNode]',
110105
transform: (node) => {
111106
c.assertIsNode(node, 'enumTypeNode');
112107
return {
@@ -116,20 +111,26 @@ codama.update(
116111
},
117112
},
118113
{
119-
// enum discriminator -> u32
120-
select: '[definedTypeNode]stakeStateV2.[enumTypeNode]',
114+
// Use omitted optional account strategy for all instructions.
115+
// + fix discriminator u8 -> u32.
116+
select: '[instructionNode]',
121117
transform: (node) => {
122-
c.assertIsNode(node, 'enumTypeNode');
118+
c.assertIsNode(node, 'instructionNode');
123119
return {
124120
...node,
125-
size: c.numberTypeNode('u32'),
121+
optionalAccountStrategy: 'omitted',
122+
arguments: node.arguments.map((arg) =>
123+
arg.name === 'discriminator'
124+
? { ...arg, type: c.numberTypeNode('u32') }
125+
: arg
126+
),
126127
};
127128
},
128129
},
129130
])
130131
);
131132

132-
// Render JavaScript client
133+
// Render JavaScript.
133134
const jsClient = path.join(workingDirectory, 'clients', 'js');
134135
codama.accept(
135136
renderJavaScriptVisitor(path.join(jsClient, 'src', 'generated'), {
@@ -140,14 +141,14 @@ codama.accept(
140141
);
141142

142143
// Remove the stake account from the accounts since the Rust client
143-
// provides its own implementation in the hooked module
144+
// provides its own implementation.
144145
codama.update(
145146
c.updateAccountsVisitor({
146147
stakeStateAccount: { delete: true },
147148
})
148149
);
149150

150-
// Render Rust client
151+
// Render Rust.
151152
const rustClient = path.join(workingDirectory, 'clients', 'rust');
152153
codama.accept(
153154
renderRustVisitor(path.join(rustClient, 'src', 'generated'), {
@@ -163,6 +164,7 @@ codama.accept(
163164
'serde::Deserialize',
164165
'Clone',
165166
'Debug',
167+
// 'Eq', <- Remove 'Eq' from the default traits.
166168
'PartialEq',
167169
],
168170
},

0 commit comments

Comments
 (0)