Skip to content

Commit

Permalink
Updating to latest.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Jan 4, 2024
1 parent 607faae commit bf77667
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,41 @@
"name": "from",
"isMut": true,
"isSigner": true,
"desc": "Payer of the transaction"
"docs": [
"Payer of the transaction"
]
},
{
"name": "to",
"isMut": true,
"isSigner": false,
"desc": "The deterministically defined 'state' account being created via `create_account_with_seed`"
"docs": [
"The deterministically defined 'state' account being created via `create_account_with_seed`"
]
},
{
"name": "base",
"isMut": false,
"isSigner": false,
"desc": "The program-derived-address signing off on the account creation. Seeds = &[] + bump seed."
"docs": [
"The program-derived-address signing off on the account creation. Seeds = &[] + bump seed."
]
},
{
"name": "systemProgram",
"isMut": false,
"isSigner": false,
"desc": "The system program"
"docs": [
"The system program"
]
},
{
"name": "program",
"isMut": false,
"isSigner": false,
"desc": "The program whose state is being constructed"
"docs": [
"The program whose state is being constructed"
]
}
],
"args": [
Expand Down Expand Up @@ -74,13 +84,17 @@
"name": "buffer",
"isMut": true,
"isSigner": false,
"desc": "The buffer with the new idl data."
"docs": [
"The buffer with the new idl data."
]
},
{
"name": "idl",
"isMut": true,
"isSigner": false,
"desc": "The idl account to be updated with the buffer's data."
"docs": [
"The idl account to be updated with the buffer's data."
]
},
{
"name": "authority",
Expand Down
6 changes: 5 additions & 1 deletion shank-idl/tests/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn instruction_from_single_file_with_idl_instructions() {
let file = fixtures_dir()
.join("single_file")
.join("create_idl_instructions.rs");
let idl = parse_file(&file, &ParseIdlConfig::optional_program_address())
let idl = parse_file(file, &ParseIdlConfig::optional_program_address())
.expect("Parsing should not fail")
.expect("File contains IDL");

Expand All @@ -91,6 +91,10 @@ fn instruction_from_single_file_with_idl_instructions() {
))
.unwrap();

println!("IDL: {}", idl.try_into_json().unwrap());

println!("Expected: {}", expected_idl.try_into_json().unwrap());

assert_eq!(idl, expected_idl);
}

Expand Down
18 changes: 15 additions & 3 deletions shank-macro-impl/src/instruction/idl_instruction_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl IdlInstruction {
name: "from".to_string(),
desc: Some("Payer of the transaction".to_string()),
signer: true,
optional_signer: false,
writable: true,
optional: false,
}, InstructionAccount {
Expand All @@ -103,6 +104,7 @@ impl IdlInstruction {
name: "to".to_string(),
desc: Some("The deterministically defined 'state' account being created via `create_account_with_seed`".to_string()),
signer: false,
optional_signer: false,
writable: true,
optional: false,
}, InstructionAccount {
Expand All @@ -111,6 +113,7 @@ impl IdlInstruction {
name: "base".to_string(),
desc: Some("The program-derived-address signing off on the account creation. Seeds = &[] + bump seed.".to_string()),
signer: false,
optional_signer: false,
writable: false,
optional: false,
}, InstructionAccount {
Expand All @@ -119,6 +122,7 @@ impl IdlInstruction {
name: "system_program".to_string(),
desc: Some("The system program".to_string()),
signer: false,
optional_signer: false,
writable: false,
optional: false,
}, InstructionAccount {
Expand All @@ -127,6 +131,7 @@ impl IdlInstruction {
name: "program".to_string(),
desc: Some("The program whose state is being constructed".to_string()),
signer: false,
optional_signer: false,
writable: false,
optional: false,
}]),
Expand All @@ -137,6 +142,7 @@ impl IdlInstruction {
name: "buffer".to_string(),
desc: None,
signer: false,
optional_signer: false,
writable: true,
optional: false,
}, InstructionAccount {
Expand All @@ -145,6 +151,7 @@ impl IdlInstruction {
name: "authority".to_string(),
desc: None,
signer: true,
optional_signer: false,
writable: false,
optional: false,
}]),
Expand All @@ -155,6 +162,7 @@ impl IdlInstruction {
name: "buffer".to_string(),
desc: Some("The buffer with the new idl data.".to_string()),
signer: false,
optional_signer: false,
writable: true,
optional: false,
}, InstructionAccount {
Expand All @@ -163,6 +171,7 @@ impl IdlInstruction {
name: "idl".to_string(),
desc: Some("The idl account to be updated with the buffer's data.".to_string()),
signer: false,
optional_signer: false,
writable: true,
optional: false,
}, InstructionAccount {
Expand All @@ -171,6 +180,7 @@ impl IdlInstruction {
name: "authority".to_string(),
desc: None,
signer: true,
optional_signer: false,
writable: false,
optional: false,
}]),
Expand All @@ -181,6 +191,7 @@ impl IdlInstruction {
name: "idl".to_string(),
desc: None,
signer: false,
optional_signer: false,
writable: true,
optional: false,
}, InstructionAccount {
Expand All @@ -189,6 +200,7 @@ impl IdlInstruction {
name: "authority".to_string(),
desc: None,
signer: true,
optional_signer: false,
writable: false,
optional: false,
}]),
Expand All @@ -201,7 +213,7 @@ impl IdlInstruction {
vec![(
"data_len".to_string(),
RustType {
ident: ident.clone(),
ident,
kind: TypeKind::Primitive(Primitive::U64),
context: RustTypeContext::Default,
reference: crate::types::ParsedReference::Owned,
Expand All @@ -212,7 +224,7 @@ impl IdlInstruction {
vec![(
"new_authority".to_string(),
RustType {
ident: ident.clone(),
ident,
kind: TypeKind::Value(Value::Custom("Pubkey".to_string())),
context: RustTypeContext::Default,
reference: crate::types::ParsedReference::Owned
Expand All @@ -226,7 +238,7 @@ impl IdlInstruction {
ident: ident.clone(),
kind: TypeKind::Composite(Composite::Vec, vec![
RustType {
ident: ident.clone(),
ident,
kind: TypeKind::Primitive(Primitive::U8),
context: RustTypeContext::CollectionItem,
reference: crate::types::ParsedReference::Owned
Expand Down
37 changes: 24 additions & 13 deletions shank-macro-impl/src/instruction/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ impl Instruction {
skip_derive_attr_check: bool,
) -> ParseResult<Option<Instruction>> {
if skip_derive_attr_check
|| get_derive_attr(&item_enum.attrs, DERIVE_INSTRUCTION_ATTR).is_some()
|| get_derive_attr(&item_enum.attrs, DERIVE_INSTRUCTION_ATTR)
.is_some()
{
let parsed_enum = ParsedEnum::try_from(item_enum)?;
Instruction::try_from(&parsed_enum).map(Some)
Expand All @@ -47,7 +48,9 @@ impl TryFrom<&ParsedEnum> for Option<Instruction> {
type Error = ParseError;

fn try_from(parsed_enum: &ParsedEnum) -> ParseResult<Self> {
match get_derive_attr(&parsed_enum.attrs, DERIVE_INSTRUCTION_ATTR).map(|_| parsed_enum) {
match get_derive_attr(&parsed_enum.attrs, DERIVE_INSTRUCTION_ATTR)
.map(|_| parsed_enum)
{
Some(ix_enum) => ix_enum.try_into().map(Some),
None => Ok(None),
}
Expand Down Expand Up @@ -110,7 +113,12 @@ impl TryFrom<&ParsedEnumVariant> for InstructionVariant {
Some(_) => InstructionVariantFields::Named(
fields
.iter()
.map(|x| (x.ident.as_ref().unwrap().to_string(), x.rust_type.clone()))
.map(|x| {
(
x.ident.as_ref().unwrap().to_string(),
x.rust_type.clone(),
)
})
.collect(),
),
None => InstructionVariantFields::Unnamed(
Expand All @@ -126,16 +134,19 @@ impl TryFrom<&ParsedEnumVariant> for InstructionVariant {
let strategies: InstructionStrategies;

let idl_instruction = IdlInstruction::try_from(attrs);
if idl_instruction.is_ok() {
let idl_ix = idl_instruction.unwrap();
accounts = idl_ix.to_accounts(ident.clone());
field_tys = idl_ix.to_instruction_fields(ident.clone());
strategies = InstructionStrategies(HashSet::<InstructionStrategy>::new());
} else {
let err = idl_instruction.unwrap_err();
println!("{}", err);
accounts = attrs.try_into()?;
strategies = attrs.into();
match idl_instruction {
Ok(idl_ix) => {
accounts = idl_ix.to_accounts(ident.clone());
field_tys = idl_ix.to_instruction_fields(ident.clone());
strategies = InstructionStrategies(HashSet::<
InstructionStrategy,
>::new());
}
Err(err) => {
println!("{}", err);
accounts = attrs.try_into()?;
strategies = attrs.into();
}
}

Ok(Self {
Expand Down

0 comments on commit bf77667

Please sign in to comment.