Skip to content

Commit 50e3073

Browse files
committed
Fix hooked configKeys type
1 parent 954a292 commit 50e3073

File tree

7 files changed

+118
-86
lines changed

7 files changed

+118
-86
lines changed

clients/js/src/generated/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
export * from './accounts';
1010
export * from './instructions';
1111
export * from './programs';
12+
export * from './types';
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* This code was AUTOGENERATED using the codama library.
3+
* Please DO NOT EDIT THIS FILE, instead use visitors
4+
* to add features, then rerun codama to update it.
5+
*
6+
* @see https://github.com/codama-idl/codama
7+
*/
8+
9+
import {
10+
combineCodec,
11+
getAddressDecoder,
12+
getAddressEncoder,
13+
getArrayDecoder,
14+
getArrayEncoder,
15+
getBooleanDecoder,
16+
getBooleanEncoder,
17+
getShortU16Decoder,
18+
getShortU16Encoder,
19+
getTupleDecoder,
20+
getTupleEncoder,
21+
type Address,
22+
type Codec,
23+
type Decoder,
24+
type Encoder,
25+
} from '@solana/web3.js';
26+
27+
/**
28+
* A collection of keys to be stored in Config account data.
29+
* Each key tuple comprises a unique `Pubkey` identifier,
30+
* and `bool` whether that key is a signer of the data.
31+
*/
32+
33+
export type ConfigKeys = Array<readonly [Address, boolean]>;
34+
35+
export type ConfigKeysArgs = ConfigKeys;
36+
37+
export function getConfigKeysEncoder(): Encoder<ConfigKeysArgs> {
38+
return getArrayEncoder(
39+
getTupleEncoder([getAddressEncoder(), getBooleanEncoder()]),
40+
{ size: getShortU16Encoder() }
41+
);
42+
}
43+
44+
export function getConfigKeysDecoder(): Decoder<ConfigKeys> {
45+
return getArrayDecoder(
46+
getTupleDecoder([getAddressDecoder(), getBooleanDecoder()]),
47+
{ size: getShortU16Decoder() }
48+
);
49+
}
50+
51+
export function getConfigKeysCodec(): Codec<ConfigKeysArgs, ConfigKeys> {
52+
return combineCodec(getConfigKeysEncoder(), getConfigKeysDecoder());
53+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* This code was AUTOGENERATED using the codama library.
3+
* Please DO NOT EDIT THIS FILE, instead use visitors
4+
* to add features, then rerun codama to update it.
5+
*
6+
* @see https://github.com/codama-idl/codama
7+
*/
8+
9+
export * from './configKeys';

clients/rust/src/generated/accounts/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! <https://github.com/codama-idl/codama>
66
77
use {
8-
crate::generated::types::ConfigKeys,
8+
crate::hooked::ConfigKeys,
99
borsh::{BorshDeserialize, BorshSerialize},
1010
kaigan::types::RemainderVec,
1111
};

clients/rust/src/generated/instructions/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! <https://github.com/codama-idl/codama>
66
77
use {
8-
crate::generated::types::ConfigKeys,
8+
crate::hooked::ConfigKeys,
99
borsh::{BorshDeserialize, BorshSerialize},
1010
kaigan::types::RemainderVec,
1111
};

program/idl.json

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,8 @@
1313
"kind": "structFieldTypeNode",
1414
"name": "keys",
1515
"type": {
16-
"kind": "arrayTypeNode",
17-
"item": {
18-
"kind": "tupleTypeNode",
19-
"items": [
20-
{
21-
"kind": "publicKeyTypeNode"
22-
},
23-
{
24-
"kind": "booleanTypeNode",
25-
"size": {
26-
"kind": "numberTypeNode",
27-
"format": "u8",
28-
"endian": "le"
29-
}
30-
}
31-
]
32-
},
33-
"count": {
34-
"kind": "prefixedCountNode",
35-
"prefix": {
36-
"kind": "numberTypeNode",
37-
"format": "shortU16",
38-
"endian": "le"
39-
}
40-
}
16+
"kind": "definedTypeLinkNode",
17+
"name": "configKeys"
4118
},
4219
"docs": [
4320
"List of pubkeys stored in the config account,",
@@ -80,31 +57,8 @@
8057
"kind": "instructionArgumentNode",
8158
"name": "keys",
8259
"type": {
83-
"kind": "arrayTypeNode",
84-
"item": {
85-
"kind": "tupleTypeNode",
86-
"items": [
87-
{
88-
"kind": "publicKeyTypeNode"
89-
},
90-
{
91-
"kind": "booleanTypeNode",
92-
"size": {
93-
"kind": "numberTypeNode",
94-
"format": "u8",
95-
"endian": "le"
96-
}
97-
}
98-
]
99-
},
100-
"count": {
101-
"kind": "prefixedCountNode",
102-
"prefix": {
103-
"kind": "numberTypeNode",
104-
"format": "shortU16",
105-
"endian": "le"
106-
}
107-
}
60+
"kind": "definedTypeLinkNode",
61+
"name": "configKeys"
10862
},
10963
"docs": [
11064
"List of pubkeys to store in the config account,",
@@ -141,9 +95,46 @@
14195
"optionalAccountStrategy": "omitted"
14296
}
14397
],
144-
"definedTypes": [],
98+
"definedTypes": [
99+
{
100+
"kind": "definedTypeNode",
101+
"name": "configKeys",
102+
"type": {
103+
"kind": "arrayTypeNode",
104+
"item": {
105+
"kind": "tupleTypeNode",
106+
"items": [
107+
{
108+
"kind": "publicKeyTypeNode"
109+
},
110+
{
111+
"kind": "booleanTypeNode",
112+
"size": {
113+
"kind": "numberTypeNode",
114+
"format": "u8",
115+
"endian": "le"
116+
}
117+
}
118+
]
119+
},
120+
"count": {
121+
"kind": "prefixedCountNode",
122+
"prefix": {
123+
"kind": "numberTypeNode",
124+
"format": "shortU16",
125+
"endian": "le"
126+
}
127+
}
128+
},
129+
"docs": [
130+
"A collection of keys to be stored in Config account data.",
131+
"Each key tuple comprises a unique `Pubkey` identifier,",
132+
"and `bool` whether that key is a signer of the data."
133+
]
134+
}
135+
],
145136
"errors": [],
146-
"name": "solanaConfigProgram",
137+
"name": "solanaConfig",
147138
"prefix": "",
148139
"publicKey": "Config1111111111111111111111111111111111111",
149140
"version": "0.0.1",

scripts/generate-clients.mjs

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,15 @@
11
#!/usr/bin/env zx
22
import 'zx/globals';
3-
import * as c from 'codama';
3+
import { createFromRoot, deleteNodesVisitor } from 'codama';
44
import { renderVisitor as renderJavaScriptVisitor } from '@codama/renderers-js';
55
import { renderVisitor as renderRustVisitor } from '@codama/renderers-rust';
66
import { getToolchainArgument, workingDirectory } from './utils.mjs';
77

88
// Instanciate Codama.
9-
const codama = c.createFromRoot(
9+
const codama = createFromRoot(
1010
require(path.join(workingDirectory, 'program', 'idl.json'))
1111
);
1212

13-
// Update programs.
14-
codama.update(
15-
c.updateProgramsVisitor({
16-
solanaConfigProgram: { name: 'solanaConfig' },
17-
})
18-
);
19-
20-
// Add missing types from the IDL.
21-
codama.update(
22-
c.bottomUpTransformerVisitor([
23-
{
24-
select: (node) => {
25-
const names = ['keys'];
26-
return (
27-
names.includes(node.name) &&
28-
(c.isNode(node, 'instructionArgumentNode') ||
29-
c.isNode(node, 'structFieldTypeNode')) &&
30-
c.isNode(node.type, 'arrayTypeNode')
31-
);
32-
},
33-
transform: (node) => {
34-
return {
35-
...node,
36-
type: c.definedTypeLinkNode('configKeys'),
37-
};
38-
},
39-
},
40-
])
41-
);
42-
4313
// Render JavaScript.
4414
const jsClient = path.join(__dirname, '..', 'clients', 'js');
4515
codama.accept(
@@ -48,12 +18,20 @@ codama.accept(
4818
})
4919
);
5020

21+
// FIXME(loris): Temporary fix until the Rust renderer fixes the missing semicolon.
22+
codama.update(deleteNodesVisitor(['[definedTypeNode]configKeys']));
23+
5124
// Render Rust.
5225
const rustClient = path.join(__dirname, '..', 'clients', 'rust');
5326
codama.accept(
5427
renderRustVisitor(path.join(rustClient, 'src', 'generated'), {
5528
formatCode: true,
5629
crateFolder: rustClient,
5730
toolchain: getToolchainArgument('format'),
31+
32+
// FIXME(loris): Temporary fix until the Rust renderer fixes the missing semicolon.
33+
linkOverrides: {
34+
definedTypes: { configKeys: 'hooked' },
35+
},
5836
})
5937
);

0 commit comments

Comments
 (0)