Skip to content

Commit e537ed3

Browse files
authored
feat: add status and statusMessage to InstructionNode (#936)
* feat: add status and statusMessage to InstructionNode * feat: integrate InstructionStatusNode into InstructionNode and update related types * fix: correct function name in InstructionStatusNode documentation * refactor: rename instructionStatus to instructionStatusNode in documentation and tests * rename `InstructionStatusNode.status` to `lifecycle` * refactor: rename InstructionStatusNode field from status to lifecycle and simplify API signature * refactor: rename `InstructionStatus` to `InstructionLifecycle` * remove extraneous empty lines * fixed style * update changeset description
1 parent e60a73c commit e537ed3

20 files changed

+284
-11
lines changed

.changeset/wet-meals-work.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@codama/visitors-core': minor
3+
'@codama/node-types': minor
4+
'@codama/nodes': minor
5+
---
6+
7+
Add a new InstructionStatusNode to instructions

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,14 @@ Feel free to PR your own visitor here for others to discover. Note that they are
114114

115115
### Generates program clients
116116

117-
| Visitor | Description | Maintainer |
118-
| ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------- |
119-
| `@codama/renderers-js` ([docs](https://github.com/codama-idl/renderers-js)) | Generates a JavaScript client compatible with [Solana Kit](https://www.solanakit.com/). | [Anza](https://www.anza.xyz/) |
120-
| `@codama/renderers-js-umi` ([docs](https://github.com/codama-idl/renderers-js-umi)) | Generates a JavaScript client compatible with [the Umi framework](https://developers.metaplex.com/umi). | [Metaplex](https://www.metaplex.com/) |
121-
| `@codama/renderers-rust` ([docs](https://github.com/codama-idl/renderers-rust)) | Generates a Rust client compatible with [the Solana SDK](https://github.com/anza-xyz/solana-sdk). | [Anza](https://www.anza.xyz/) |
122-
| `@codama/renderers-vixen-parser` ([docs](https://github.com/codama-idl/renderers-vixen-parser)) | Generates [Yellowstone](https://github.com/rpcpool/yellowstone-grpc) account and instruction parsers. | [Triton One](https://triton.one/) |
123-
| `@limechain/codama-dart` ([docs](https://github.com/limechain/codama-dart))| Generates a Dart client. | [LimeChain](https://github.com/limechain/)|
124-
| `codama-py` ([docs](https://github.com/Solana-ZH/codama-py)) | Generates a Python client. | [Solar](https://github.com/Solana-ZH) |
125-
117+
| Visitor | Description | Maintainer |
118+
| ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
119+
| `@codama/renderers-js` ([docs](https://github.com/codama-idl/renderers-js)) | Generates a JavaScript client compatible with [Solana Kit](https://www.solanakit.com/). | [Anza](https://www.anza.xyz/) |
120+
| `@codama/renderers-js-umi` ([docs](https://github.com/codama-idl/renderers-js-umi)) | Generates a JavaScript client compatible with [the Umi framework](https://developers.metaplex.com/umi). | [Metaplex](https://www.metaplex.com/) |
121+
| `@codama/renderers-rust` ([docs](https://github.com/codama-idl/renderers-rust)) | Generates a Rust client compatible with [the Solana SDK](https://github.com/anza-xyz/solana-sdk). | [Anza](https://www.anza.xyz/) |
122+
| `@codama/renderers-vixen-parser` ([docs](https://github.com/codama-idl/renderers-vixen-parser)) | Generates [Yellowstone](https://github.com/rpcpool/yellowstone-grpc) account and instruction parsers. | [Triton One](https://triton.one/) |
123+
| `@limechain/codama-dart` ([docs](https://github.com/limechain/codama-dart)) | Generates a Dart client. | [LimeChain](https://github.com/limechain/) |
124+
| `codama-py` ([docs](https://github.com/Solana-ZH/codama-py)) | Generates a Python client. | [Solar](https://github.com/Solana-ZH) |
126125

127126
### Provides utility
128127

packages/node-types/src/InstructionNode.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { InstructionAccountNode } from './InstructionAccountNode';
33
import type { InstructionArgumentNode } from './InstructionArgumentNode';
44
import type { InstructionByteDeltaNode } from './InstructionByteDeltaNode';
55
import type { InstructionRemainingAccountsNode } from './InstructionRemainingAccountsNode';
6+
import type { InstructionStatusNode } from './InstructionStatusNode';
67
import type { CamelCaseString, Docs } from './shared';
78

89
type SubInstructionNode = InstructionNode;
@@ -34,5 +35,6 @@ export interface InstructionNode<
3435
readonly remainingAccounts?: TRemainingAccounts;
3536
readonly byteDeltas?: TByteDeltas;
3637
readonly discriminators?: TDiscriminators;
38+
readonly status?: InstructionStatusNode;
3739
readonly subInstructions?: TSubInstructions;
3840
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { InstructionLifecycle } from './shared';
2+
3+
export interface InstructionStatusNode {
4+
readonly kind: 'instructionStatusNode';
5+
6+
// Data.
7+
readonly lifecycle: InstructionLifecycle;
8+
readonly message?: string;
9+
}

packages/node-types/src/Node.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { InstructionArgumentNode } from './InstructionArgumentNode';
99
import type { InstructionByteDeltaNode } from './InstructionByteDeltaNode';
1010
import type { InstructionNode } from './InstructionNode';
1111
import type { InstructionRemainingAccountsNode } from './InstructionRemainingAccountsNode';
12+
import type { InstructionStatusNode } from './InstructionStatusNode';
1213
import type { RegisteredLinkNode } from './linkNodes/LinkNode';
1314
import type { PdaNode } from './PdaNode';
1415
import type { RegisteredPdaSeedNode } from './pdaSeedNodes/PdaSeedNode';
@@ -28,6 +29,7 @@ export type Node =
2829
| InstructionByteDeltaNode
2930
| InstructionNode
3031
| InstructionRemainingAccountsNode
32+
| InstructionStatusNode
3133
| PdaNode
3234
| ProgramNode
3335
| RegisteredContextualValueNode

packages/node-types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export * from './InstructionArgumentNode';
66
export * from './InstructionByteDeltaNode';
77
export * from './InstructionNode';
88
export * from './InstructionRemainingAccountsNode';
9+
export * from './InstructionStatusNode';
910
export * from './Node';
1011
export * from './PdaNode';
1112
export * from './ProgramNode';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './bytesEncoding';
22
export * from './docs';
3+
export * from './instructionLifecycle';
34
export * from './stringCases';
45
export * from './version';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type InstructionLifecycle = 'archived' | 'deprecated' | 'draft' | 'live';

packages/nodes/docs/InstructionNode.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This node represents an instruction in a program.
2525
| `remainingAccounts` | [`InstructionRemainingAccountsNode`](./InstructionRemainingAccountsNode.md)[] | (Optional) The list of dynamic remaining accounts requirements for the instruction. For instance, an instruction may have a variable number of signers at the end of the accounts list. |
2626
| `byteDeltas` | [`InstructionByteDeltaNode`](./InstructionByteDeltaNode.md)[] | (Optional) The list of byte variations that the instruction causes. They should all be added together unless the `subtract` attribute is used. |
2727
| `discriminators` | [`DiscriminatorNode`](./DiscriminatorNode.md)[] | (Optional) The nodes that distinguish this instruction from others in the program. If multiple discriminators are provided, they are combined using a logical AND operation. |
28+
| `status` | [`InstructionStatusNode`](./InstructionStatusNode.md) | (Optional) The status of the instruction and an optional message about that status. |
2829
| `subInstructions` | [`InstructionNode`](./InstructionNode.md)[] | (Optional) A list of nested instructions should this instruction be split into multiple sub-instructions to define distinct scenarios. |
2930

3031
## Functions
@@ -121,7 +122,7 @@ instructionNode({
121122
});
122123
```
123124

124-
### An instruction with nested versionned instructions
125+
### An instruction with nested versioned instructions
125126

126127
```ts
127128
instructionNode({
@@ -167,3 +168,45 @@ instructionNode({
167168
],
168169
});
169170
```
171+
172+
### A deprecated instruction
173+
174+
```ts
175+
instructionNode({
176+
name: 'oldIncrement',
177+
status: instructionStatusNode(
178+
'deprecated',
179+
'Use the `increment` instruction instead. This will be removed in v3.0.0.',
180+
),
181+
accounts: [instructionAccountNode({ name: 'counter', isWritable: true, isSigner: false })],
182+
arguments: [instructionArgumentNode({ name: 'amount', type: numberTypeNode('u8') })],
183+
});
184+
```
185+
186+
### An archived instruction
187+
188+
```ts
189+
instructionNode({
190+
name: 'legacyTransfer',
191+
status: instructionStatusNode(
192+
'archived',
193+
'This instruction was removed in v2.0.0. It is kept here for historical parsing.',
194+
),
195+
accounts: [
196+
instructionAccountNode({ name: 'source', isWritable: true, isSigner: true }),
197+
instructionAccountNode({ name: 'destination', isWritable: true, isSigner: false }),
198+
],
199+
arguments: [instructionArgumentNode({ name: 'amount', type: numberTypeNode('u64') })],
200+
});
201+
```
202+
203+
### A draft instruction
204+
205+
```ts
206+
instructionNode({
207+
name: 'experimentalFeature',
208+
status: instructionStatusNode('draft', 'This instruction is under development and may change.'),
209+
accounts: [instructionAccountNode({ name: 'config', isWritable: true, isSigner: true })],
210+
arguments: [],
211+
});
212+
```
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# `InstructionStatusNode`
2+
3+
This node represents the status of an instruction along with an optional message.
4+
5+
## Attributes
6+
7+
### Data
8+
9+
| Attribute | Type | Description |
10+
| ----------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
11+
| `kind` | `"instructionStatusNode"` | The node discriminator. |
12+
| `lifecycle` | `"live"` \| `"deprecated"` \| `"archived"` \| `"draft"` | The lifecycle status of the instruction. `"live"` means accessible (the default), `"deprecated"` means about to be archived, `"archived"` means no longer accessible but kept for historical parsing, `"draft"` means not fully implemented yet. |
13+
| `message` | `string` | (Optional) Additional information about the current status for program consumers. |
14+
15+
## Functions
16+
17+
### `instructionStatusNode(lifecycle, message?)`
18+
19+
Helper function that creates an `InstructionStatusNode` object.
20+
21+
```ts
22+
const statusNode = instructionStatusNode('deprecated', 'Use the newInstruction instead');
23+
```
24+
25+
## Examples
26+
27+
### A live instruction (no status needed)
28+
29+
For live instructions, you typically don't need to set a status at all:
30+
31+
```ts
32+
instructionNode({
33+
name: 'transfer',
34+
accounts: [...],
35+
arguments: [...],
36+
});
37+
```
38+
39+
### A deprecated instruction
40+
41+
```ts
42+
instructionNode({
43+
name: 'oldTransfer',
44+
status: instructionStatusNode('deprecated', 'Use the `transfer` instruction instead. This will be removed in v3.0.0.'),
45+
accounts: [...],
46+
arguments: [...],
47+
});
48+
```
49+
50+
### An archived instruction
51+
52+
```ts
53+
instructionNode({
54+
name: 'legacyTransfer',
55+
status: instructionStatusNode('archived', 'This instruction was removed in v2.0.0. It is kept here for historical parsing.'),
56+
accounts: [...],
57+
arguments: [...],
58+
});
59+
```
60+
61+
### A draft instruction
62+
63+
```ts
64+
instructionNode({
65+
name: 'experimentalFeature',
66+
status: instructionStatusNode('draft', 'This instruction is under development and may change.'),
67+
accounts: [...],
68+
arguments: [...],
69+
});
70+
```
71+
72+
### Status without a message
73+
74+
```ts
75+
instructionNode({
76+
name: 'someInstruction',
77+
status: instructionStatusNode('deprecated'),
78+
accounts: [...],
79+
arguments: [...],
80+
});
81+
```

0 commit comments

Comments
 (0)