Skip to content

Commit 9aa6cb8

Browse files
authored
Add node documentation — Part 3: ContextualValueNodes (#98)
1 parent 5c8ad48 commit 9aa6cb8

12 files changed

+488
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# `AccountBumpValueNode`
2+
3+
A node that refers to the seed bump of a PDA account.
4+
5+
## Attributes
6+
7+
### Data
8+
9+
| Attribute | Type | Description |
10+
| --------- | ------------------------ | ------------------------ |
11+
| `kind` | `"accountBumpValueNode"` | The node discriminator. |
12+
| `name` | `CamelCaseString` | The name of the account. |
13+
14+
### Children
15+
16+
_This node has no children._
17+
18+
## Functions
19+
20+
### `accountBumpValueNode(name)`
21+
22+
Helper function that creates a `AccountBumpValueNode` object from the account name.
23+
24+
```ts
25+
const node = accountBumpValueNode('associatedTokenAccount');
26+
```
27+
28+
## Examples
29+
30+
### An instruction argument defaulting to the bump derivation of an instruction account
31+
32+
```ts
33+
instructionNode({
34+
name: 'transfer',
35+
accounts: [
36+
instructionAccountNode({
37+
name: 'associatedTokenAccount',
38+
isSigner: false,
39+
isWritable: true,
40+
}),
41+
// ...
42+
],
43+
arguments: [
44+
instructionArgumentNode({
45+
name: 'bump',
46+
type: numberTypeNode('u8'),
47+
defaultValue: accountBumpValueNode('associatedTokenAccount'),
48+
}),
49+
// ...
50+
],
51+
});
52+
```
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# `AccountValueNode`
2+
3+
A node that refers to an account — e.g. an instruction account in the context of an instruction.
4+
5+
## Attributes
6+
7+
### Data
8+
9+
| Attribute | Type | Description |
10+
| --------- | -------------------- | ------------------------ |
11+
| `kind` | `"accountValueNode"` | The node discriminator. |
12+
| `name` | `CamelCaseString` | The name of the account. |
13+
14+
### Children
15+
16+
_This node has no children._
17+
18+
## Functions
19+
20+
### `accountValueNode(name)`
21+
22+
Helper function that creates a `AccountValueNode` object from the account name.
23+
24+
```ts
25+
const node = accountValueNode('mint');
26+
```
27+
28+
## Examples
29+
30+
### An instruction account defaulting to another account
31+
32+
```ts
33+
instructionNode({
34+
name: 'mint',
35+
accounts: [
36+
instructionAccountNode({
37+
name: 'payer',
38+
isSigner: true,
39+
isWritable: false,
40+
}),
41+
instructionAccountNode({
42+
name: 'authority',
43+
isSigner: false,
44+
isWritable: true,
45+
defaultValue: accountValueNode('payer'),
46+
}),
47+
// ...
48+
],
49+
});
50+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# `ArgumentValueNode`
2+
3+
A node that refers to an argument — e.g. an instruction argument in the context of an instruction.
4+
5+
## Attributes
6+
7+
### Data
8+
9+
| Attribute | Type | Description |
10+
| --------- | --------------------- | ------------------------- |
11+
| `kind` | `"argumentValueNode"` | The node discriminator. |
12+
| `name` | `CamelCaseString` | The name of the argument. |
13+
14+
### Children
15+
16+
_This node has no children._
17+
18+
## Functions
19+
20+
### `argumentValueNode(name)`
21+
22+
Helper function that creates a `ArgumentValueNode` object from the argument name.
23+
24+
```ts
25+
const node = argumentValueNode('amount');
26+
```
27+
28+
## Examples
29+
30+
### An instruction argument defaulting to another argument
31+
32+
```ts
33+
instructionNode({
34+
name: 'mint',
35+
arguments: [
36+
instructionArgumentNode({
37+
name: 'amount',
38+
type: numberTypeNode('u64'),
39+
}),
40+
instructionArgumentNode({
41+
name: 'amountToDelegate',
42+
type: numberTypeNode('u64'),
43+
defaultValue: argumentValueNode('amount'),
44+
}),
45+
// ...
46+
],
47+
});
48+
```
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# `ConditionalValueNode`
2+
3+
A value node that differs based on a condition.
4+
5+
## Attributes
6+
7+
### Data
8+
9+
| Attribute | Type | Description |
10+
| --------- | ------------------------ | ----------------------- |
11+
| `kind` | `"conditionalValueNode"` | The node discriminator. |
12+
13+
### Children
14+
15+
| Attribute | Type | Description |
16+
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
17+
| `condition` | [`AccountValueNode`](./AccountValueNode.md) \| [`ArgumentValueNode`](./ArgumentValueNode.md) \| [`ResolverValueNode`](./ResolverValueNode.md) | The condition that must be met. If it is an argument or value node, the `value` attribute may be used to assert on a specific value. |
18+
| `value` | [`ValueNode`](../valueNodes/README.md) | (Optional) If provided, the `condition` must be equal to this value. Otherwise, the `condition` must simply exist. |
19+
| `ifTrue` | [`InstructionInputValueNode`](./InstructionInputValueNode.md) | (Optional) The value to use if the condition is true. |
20+
| `ifFalse` | [`InstructionInputValueNode`](./InstructionInputValueNode.md) | (Optional) The value to use if the condition is false. |
21+
22+
## Functions
23+
24+
### `conditionalValueNode(input)`
25+
26+
Helper function that creates a `ConditionalValueNode` object from an input object.
27+
28+
```ts
29+
const node = conditionalValueNode({
30+
condition: argumentValueNode('amount'),
31+
value: numberValueNode(0),
32+
ifTrue: accountValueNode('mint'),
33+
ifFalse: programIdValueNode(),
34+
});
35+
```
36+
37+
## Examples
38+
39+
### An instruction account that defaults to another account if a condition is met
40+
41+
```ts
42+
instructionNode({
43+
name: 'transfer',
44+
accounts: [
45+
instructionAccountNode({
46+
name: 'source',
47+
isSigner: false,
48+
isWritable: true,
49+
}),
50+
instructionAccountNode({
51+
name: 'destination',
52+
isSigner: false,
53+
isWritable: true,
54+
isOptional: true,
55+
defaultValue: conditionalValueNode({
56+
condition: argumentValueNode('amount'),
57+
value: numberValueNode(0),
58+
ifTrue: accountValueNode('source'),
59+
}),
60+
}),
61+
// ...
62+
],
63+
arguments: [
64+
instructionArgumentNode({
65+
name: 'amount',
66+
type: numberTypeNode('u64'),
67+
}),
68+
],
69+
});
70+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# `IdentityValueNode`
2+
3+
A node that represents the main wallet that should **own things**.
4+
5+
For instance, in an web application, the identity would be the user's wallet; in a terminal, the identity would be the wallet identitied by `solana address`; etc.
6+
7+
Note that a similar node exists for representing the main wallet that should **pay for things** — the [`PayerValueNode`](./PayerValueNode.md). In practice, the identity and the payer are often the same but allowing the program maintainer to offer this distinction can be useful should they be different.
8+
9+
## Attributes
10+
11+
### Data
12+
13+
| Attribute | Type | Description |
14+
| --------- | --------------------- | ----------------------- |
15+
| `kind` | `"identityValueNode"` | The node discriminator. |
16+
17+
### Children
18+
19+
_This node has no children._
20+
21+
## Functions
22+
23+
### `identityValueNode()`
24+
25+
Helper function that creates a `IdentityValueNode` object.
26+
27+
```ts
28+
const node = identityValueNode();
29+
```
30+
31+
## Examples
32+
33+
### An instruction account defaulting to the identity value
34+
35+
```ts
36+
instructionNode({
37+
name: 'transfer',
38+
accounts: [
39+
instructionAccountNode({
40+
name: 'authority',
41+
isSigner: true,
42+
isWritable: false,
43+
defaultValue: identityValueNode(),
44+
}),
45+
// ...
46+
],
47+
});
48+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# `InstructionInputValueNode` (abstract)
2+
3+
The `InstructionInputValueNode` type helper represents all values that can be used as a default value for an instruction account or an instruction argument. Note that `InstructionInputValueNode` is a type alias and cannot be used directly as a node. Instead you may use one of the following nodes:
4+
5+
- [`ContextualValueNode`](./README.md) (abstract)
6+
- [`ProgramLinkNode`](../linkNodes/ProgramLinkNode.md)
7+
- [`ValueNode`](../valueNodes/README.md) (abstract)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# `PayerValueNode`
2+
3+
A node that represents the main wallet that should **pay for things**.
4+
5+
For instance, in an web application, the payer would be the user's wallet; in a terminal, the payer would be the wallet identitied by `solana address`; etc.
6+
7+
Note that a similar node exists for representing the main wallet that should **own things** — the [`IdentityValueNode`](./IdentityValueNode.md). In practice, the payer and the identity are often the same but allowing the program maintainer to offer this distinction can be useful should they be different.
8+
9+
## Attributes
10+
11+
### Data
12+
13+
| Attribute | Type | Description |
14+
| --------- | ------------------ | ----------------------- |
15+
| `kind` | `"payerValueNode"` | The node discriminator. |
16+
17+
### Children
18+
19+
_This node has no children._
20+
21+
## Functions
22+
23+
### `payerValueNode()`
24+
25+
Helper function that creates a `PayerValueNode` object.
26+
27+
```ts
28+
const node = payerValueNode();
29+
```
30+
31+
## Examples
32+
33+
### An instruction account defaulting to the payer value
34+
35+
```ts
36+
instructionNode({
37+
name: 'transfer',
38+
accounts: [
39+
instructionAccountNode({
40+
name: 'payer',
41+
isSigner: true,
42+
isWritable: false,
43+
defaultValue: payerValueNode(),
44+
}),
45+
// ...
46+
],
47+
});
48+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# `PdaSeedValueNode`
2+
3+
A node that represents the value of a variable PDA seed.
4+
5+
## Attributes
6+
7+
### Data
8+
9+
| Attribute | Type | Description |
10+
| --------- | -------------------- | ------------------------------ |
11+
| `kind` | `"pdaSeedValueNode"` | The node discriminator. |
12+
| `name` | `CamelCaseString` | The name of the variable seed. |
13+
14+
### Children
15+
16+
| Attribute | Type | Description |
17+
| --------- | -------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
18+
| `value` | [`AccountValueNode`](./AccountValueNode.md) \| [`ArgumentValueNode`](./ArgumentValueNode.md) \| [`ValueNode`](../valueNodes/README.md) | The value of the variable PDA seed. This can be a simple `ValueNode` or a contextual value pointing to another account or argument. |
19+
20+
## Functions
21+
22+
### `pdaSeedValueNode(name, value)`
23+
24+
Helper function that creates a `PdaSeedValueNode` object from the name of the variable seed and its value.
25+
26+
```ts
27+
const node = pdaSeedValueNode('mint', accountValueNode('mint'));
28+
```

0 commit comments

Comments
 (0)