Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
branches:
- master
env:
SOLANA_CLI_VERSION: 1.14.17
NODE_VERSION: 18
SOLANA_CLI_VERSION: 1.17.18
NODE_VERSION: 22

jobs:
example-program-tests:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "anchor-client-gen",
"description": "A tool for generating solana web3 clients from anchor IDLs.",
"version": "1.29.5",
"version": "1.29.0",
"bin": "dist/main.js",
"license": "MIT",
"homepage": "https://github.com/kklas/anchor-client-gen",
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.74.1"
13 changes: 12 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function jsonInterfaceName(typeName: string) {
export function isComplexType(
ty: IdlType
): ty is
| IdlTypeDefined
| IdlTypeArray
| IdlTypeVec
| IdlTypeOption
Expand Down Expand Up @@ -125,6 +124,9 @@ export function tsTypeFromIdl(
const name = kindInterfaceName(ty.defined)
return `${definedTypesPrefix}${name}`
}
case "alias": {
throw new Error("alias layout support not implemented")
}
}
}
if (isComplexType(ty) && "array" in ty) {
Expand Down Expand Up @@ -306,6 +308,9 @@ export function fieldToEncodable(
case "enum": {
return `${valPrefix}${ty.name}.toEncodable()`
}
case "alias": {
throw new Error("alias layout support not implemented")
}
}
}
if (isComplexType(ty.type) && "array" in ty.type) {
Expand Down Expand Up @@ -402,6 +407,8 @@ export function fieldFromDecoded(
case "struct":
case "enum":
return `${definedTypesPrefix}${ty.type.defined}.fromDecoded(${valPrefix}${ty.name})`
case "alias":
throw new Error("alias layout support not implemented")
default: {
unreachable(filtered[0].type)
throw new Error("Unreachable.")
Expand Down Expand Up @@ -469,6 +476,8 @@ export function structFieldInitializer(
case "enum":
filtered[0].type.kind
return `${prefix}${field.name}`
case "alias":
throw new Error("alias layout support not implemented")
default:
unreachable(filtered[0].type)
return
Expand Down Expand Up @@ -618,6 +627,8 @@ export function fieldToJSON(idl: Idl, ty: IdlField, valPrefix = ""): string {
case "struct":
case "enum":
return `${valPrefix}${ty.name}.toJSON()`
case "alias":
throw new Error("alias layout support not implemented")
default: {
unreachable(filtered[0].type)
throw new Error("Unreachable.")
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
return `${ty.name}.${variant.name}`
})
.join(" | "),
docs: (ty as any).docs && [(ty as any).docs.join("\n")],

Check warning on line 75 in src/types.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unexpected any. Specify a different type

Check warning on line 75 in src/types.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unexpected any. Specify a different type
})
src.addTypeAlias({
isExported: true,
Expand All @@ -84,6 +84,8 @@
.join(" | "),
})
return
case "alias":
throw new Error("alias layout support not implemented")
default:
unreachable(ty.type)
}
Expand All @@ -102,13 +104,15 @@

switch (ty.type.kind) {
case "struct": {
genStruct(idl, src, ty.name, ty.type.fields, (ty as any).docs)

Check warning on line 107 in src/types.ts

View workflow job for this annotation

GitHub Actions / Run linters

Unexpected any. Specify a different type
return
}
case "enum": {
genEnum(idl, src, ty.name, ty.type.variants)
return
}
case "alias":
throw new Error("alias layout support not implemented")
default:
unreachable(ty.type)
}
Expand Down
5 changes: 3 additions & 2 deletions tests/example-program-gen/exp/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as FooEnum from "./FooEnum"

export { BarStruct } from "./BarStruct"
export type { BarStructFields, BarStructJSON } from "./BarStruct"
export { FooStruct } from "./FooStruct"
export type { FooStructFields, FooStructJSON } from "./FooStruct"
export { FooEnum }

/** Enum type */
Expand All @@ -23,3 +21,6 @@ export type FooEnumJSON =
| FooEnum.OptionStructJSON
| FooEnum.VecStructJSON
| FooEnum.NoFieldsJSON

export { FooStruct } from "./FooStruct"
export type { FooStructFields, FooStructJSON } from "./FooStruct"
96 changes: 48 additions & 48 deletions tests/example-program-gen/idl.json
Original file line number Diff line number Diff line change
Expand Up @@ -450,54 +450,6 @@
]
}
},
{
"name": "FooStruct",
"type": {
"kind": "struct",
"fields": [
{
"name": "field1",
"type": "u8"
},
{
"name": "field2",
"type": "u16"
},
{
"name": "nested",
"type": {
"defined": "BarStruct"
}
},
{
"name": "vecNested",
"type": {
"vec": {
"defined": "BarStruct"
}
}
},
{
"name": "optionNested",
"type": {
"option": {
"defined": "BarStruct"
}
}
},
{
"name": "enumField",
"type": {
"defined": "FooEnum"
}
},
{
"name": "pubkeyField",
"type": "publicKey"
}
]
}
},
{
"name": "FooEnum",
"docs": [
Expand Down Expand Up @@ -579,6 +531,54 @@
}
]
}
},
{
"name": "FooStruct",
"type": {
"kind": "struct",
"fields": [
{
"name": "field1",
"type": "u8"
},
{
"name": "field2",
"type": "u16"
},
{
"name": "nested",
"type": {
"defined": "BarStruct"
}
},
{
"name": "vecNested",
"type": {
"vec": {
"defined": "BarStruct"
}
}
},
{
"name": "optionNested",
"type": {
"option": {
"defined": "BarStruct"
}
}
},
{
"name": "enumField",
"type": {
"defined": "FooEnum"
}
},
{
"name": "pubkeyField",
"type": "publicKey"
}
]
}
}
],
"errors": [
Expand Down
5 changes: 3 additions & 2 deletions tests/example-program/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/example-program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
members = [
"programs/*"
]

[profile.release]
overflow-checks = true
1 change: 1 addition & 0 deletions tests/example-program/programs/example-program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "^0.29.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ it("tx error", async () => {
"Program 3rTQ3R4B2PxZrAyx7EUefySPgZY8RhJf16cZajbmrzp8 invoke [1]",
"Program log: Instruction: CauseError",
"Program log: AnchorError thrown in programs/example-program/src/lib.rs:90. Error Code: SomeError. Error Number: 6000. Error Message: Example error..",
"Program 3rTQ3R4B2PxZrAyx7EUefySPgZY8RhJf16cZajbmrzp8 consumed 2293 of 200000 compute units",
"Program 3rTQ3R4B2PxZrAyx7EUefySPgZY8RhJf16cZajbmrzp8 consumed 2304 of 200000 compute units",
"Program 3rTQ3R4B2PxZrAyx7EUefySPgZY8RhJf16cZajbmrzp8 failed: custom program error: 0x1770",
])

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"sourceMap": true,
"moduleResolution": "node",
"noEmit": true,
"isolatedModules": true
"isolatedModules": true,
"skipLibCheck": true
},
"include": ["src", "tests", "examples"],
}
Loading