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

lang, ts: decamelize idl #912

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9ad1812
remove camel/mixed case from IDL
kevinheavey Oct 22, 2021
d574829
add camelizedIdl to client code
kevinheavey Oct 22, 2021
dd1dc03
fix accountDiscriminator
kevinheavey Oct 22, 2021
e713ed3
fix idl names
kevinheavey Oct 22, 2021
3c9447a
fix camelcasing
kevinheavey Oct 22, 2021
c0685cc
take pascal case back out of acc disc
kevinheavey Oct 22, 2021
b629c67
run prettier
kevinheavey Oct 22, 2021
864b585
fix array idl type
kevinheavey Oct 22, 2021
9950b44
remove unused param i forgot to take out
kevinheavey Oct 31, 2021
e11cae2
run prettier
kevinheavey Oct 31, 2021
05c8919
Merge branch 'master' into decamelize-idl
kevinheavey Dec 3, 2021
ba21e65
Merge branch 'master' into decamelize-idl
kevinheavey Dec 5, 2021
c3b9c23
handle camel case for constants
kevinheavey Dec 5, 2021
1e0aee9
add missing constant field to RawIdl
kevinheavey Dec 5, 2021
26bd4d3
run prettier
kevinheavey Dec 5, 2021
c1539c3
try fix property name
kevinheavey Dec 5, 2021
4b7a40b
add print
kevinheavey Dec 5, 2021
786c4ca
use camelized idl in misc tests
kevinheavey Dec 5, 2021
568ff66
remove print
kevinheavey Dec 5, 2021
f94b699
Merge branch 'master' into decamelize-idl
kevinheavey Dec 8, 2021
75c5a67
update idl.ts after replacing .ty with .type
kevinheavey Dec 9, 2021
2b73de1
Merge branch 'master' into decamelize-idl
kevinheavey Dec 9, 2021
ffa8316
Merge branch 'master' into decamelize-idl
kevinheavey Dec 28, 2021
ad5f04b
fix accidental dupe fields
kevinheavey Dec 28, 2021
b8387f1
Merge branch 'master' into decamelize-idl
kevinheavey Jan 10, 2022
9d72e17
Merge branch 'master' into decamelize-idl
kevinheavey Jan 29, 2022
20f9135
Merge branch 'master' into decamelize-idl
kevinheavey Feb 20, 2022
425432c
Merge branch 'master' into decamelize-idl
paul-schaaf Apr 19, 2022
01b9c5c
remove camelcase serde from rust idl structs and add new raw type toi…
paul-schaaf Apr 19, 2022
8556cb9
lint:fix
paul-schaaf Apr 19, 2022
8ee9c8b
tests: add ts-expect-error to make tsc compile and add comment to mis…
paul-schaaf Apr 19, 2022
cf424a1
ts: add metadata field
paul-schaaf Apr 19, 2022
62c0567
ts: fix import
paul-schaaf Apr 21, 2022
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
21 changes: 10 additions & 11 deletions lang/syn/src/idl/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::parser::{self, accounts, error, program};
use crate::Ty;
use crate::{AccountField, AccountsStruct, StateIx};
use anyhow::Result;
use heck::MixedCase;
use quote::ToTokens;
use std::collections::{HashMap, HashSet};
use std::path::Path;
Expand Down Expand Up @@ -44,7 +43,7 @@ pub fn parse(
methods
.iter()
.map(|method: &StateIx| {
let name = method.ident.to_string().to_mixed_case();
let name = method.ident.to_string();
let args = method
.args
.iter()
Expand All @@ -53,7 +52,7 @@ pub fn parse(
arg.raw_arg.ty.to_tokens(&mut tts);
let ty = tts.to_string().parse().unwrap();
IdlField {
name: arg.name.to_string().to_mixed_case(),
name: arg.name.to_string(),
ty,
}
})
Expand Down Expand Up @@ -93,7 +92,7 @@ pub fn parse(
arg_typed.ty.to_tokens(&mut tts);
let ty = tts.to_string().parse().unwrap();
IdlField {
name: parser::tts_to_string(&arg_typed.pat).to_mixed_case(),
name: parser::tts_to_string(&arg_typed.pat),
ty,
}
}
Expand Down Expand Up @@ -122,7 +121,7 @@ pub fn parse(
f.ty.to_tokens(&mut tts);
let ty = tts.to_string().parse().unwrap();
IdlField {
name: f.ident.as_ref().unwrap().to_string().to_mixed_case(),
name: f.ident.as_ref().unwrap().to_string(),
ty,
}
})
Expand Down Expand Up @@ -159,7 +158,7 @@ pub fn parse(
.args
.iter()
.map(|arg| IdlField {
name: arg.name.to_string().to_mixed_case(),
name: arg.name.to_string(),
ty: to_idl_type(&ctx, &arg.raw_arg.ty),
})
.collect::<Vec<_>>();
Expand All @@ -172,7 +171,7 @@ pub fn parse(
_ => Some(ret_type_str.parse().unwrap()),
};
IdlInstruction {
name: ix.ident.to_string().to_mixed_case(),
name: ix.ident.to_string(),
accounts,
args,
returns,
Expand All @@ -196,7 +195,7 @@ pub fn parse(
Some(i) => parser::tts_to_string(&i.path) == "index",
};
IdlEventField {
name: f.ident.clone().unwrap().to_string().to_mixed_case(),
name: f.ident.clone().unwrap().to_string(),
ty: to_idl_type(&ctx, &f.ty),
index,
}
Expand Down Expand Up @@ -413,7 +412,7 @@ fn parse_ty_defs(ctx: &CrateContext) -> Result<Vec<IdlTypeDefinition>> {
.iter()
.map(|f: &syn::Field| {
Ok(IdlField {
name: f.ident.as_ref().unwrap().to_string().to_mixed_case(),
name: f.ident.as_ref().unwrap().to_string(),
ty: to_idl_type(ctx, &f.ty),
})
})
Expand Down Expand Up @@ -552,12 +551,12 @@ fn idl_accounts(
});
let accounts = idl_accounts(ctx, accs_strct, global_accs, seeds_feature);
IdlAccountItem::IdlAccounts(IdlAccounts {
name: comp_f.ident.to_string().to_mixed_case(),
name: comp_f.ident.to_string(),
accounts,
})
}
AccountField::Field(acc) => IdlAccountItem::IdlAccount(IdlAccount {
name: acc.ident.to_string().to_mixed_case(),
name: acc.ident.to_string(),
is_mut: acc.constraints.is_mutable(),
is_signer: match acc.ty {
Ty::Signer => true,
Expand Down
11 changes: 3 additions & 8 deletions lang/syn/src/idl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct IdlInstruction {
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]

pub struct IdlAccounts {
pub name: String,
pub accounts: Vec<IdlAccountItem>,
Expand All @@ -64,7 +64,7 @@ pub enum IdlAccountItem {
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]

pub struct IdlAccount {
pub name: String,
pub is_mut: bool,
Expand All @@ -74,23 +74,20 @@ pub struct IdlAccount {
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct IdlPda {
pub seeds: Vec<IdlSeed>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub program_id: Option<IdlSeed>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase", tag = "kind")]
pub enum IdlSeed {
Const(IdlSeedConst),
Arg(IdlSeedArg),
Account(IdlSeedAccount),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct IdlSeedAccount {
#[serde(rename = "type")]
pub ty: IdlType,
Expand All @@ -102,15 +99,13 @@ pub struct IdlSeedAccount {
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct IdlSeedArg {
#[serde(rename = "type")]
pub ty: IdlType,
pub path: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct IdlSeedConst {
#[serde(rename = "type")]
pub ty: IdlType,
Expand Down Expand Up @@ -167,7 +162,7 @@ pub enum EnumFields {
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]

pub enum IdlType {
Bool,
U8,
Expand Down
5 changes: 5 additions & 0 deletions tests/misc/tests/misc/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("misc", () => {
const wallet = provider.wallet as Wallet;
anchor.setProvider(provider);
const program = anchor.workspace.Misc as Program<Misc>;
const miscIdl = program.idl;
const misc2Program = anchor.workspace.Misc2 as Program<Misc2>;

it("Can allocate extra space for a state constructor", async () => {
Expand Down Expand Up @@ -965,6 +966,10 @@ describe("misc", () => {
});

it("Should not include NO_IDL const in IDL", async () => {
// The type system sees that this constant does not exist and the
// ts-expect-error makes sure that ts compilation fails if that ever
// changes.
// @ts-expect-error
assert.isUndefined(miscIdl.constants.find((c) => c.name === "NO_IDL"));
});

Expand Down
Loading