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

Local Build #7

Open
olasunkanmi-SE opened this issue Sep 2, 2024 · 2 comments
Open

Local Build #7

olasunkanmi-SE opened this issue Sep 2, 2024 · 2 comments

Comments

@olasunkanmi-SE
Copy link
Collaborator

When I ran anchor build on my local. This is how the generated IDL looks like.

{
  "version": "0.1.0",
  "name": "solana_academy",
  "instructions": [
    {
      "name": "initializeAcademy",
      "accounts": [
        {
          "name": "academy",
          "isMut": true,
          "isSigner": true
        },
        {
          "name": "admin",
          "isMut": true,
          "isSigner": true
        },
        {
          "name": "systemProgram",
          "isMut": false,
          "isSigner": false
        }
      ],
      "args": [
        {
          "name": "name",
          "type": "string"
        }
      ]
    },
    {
      "name": "createCourse",
      "accounts": [
        {
          "name": "academy",
          "isMut": true,
          "isSigner": false
        },
        {
          "name": "course",
          "isMut": true,
          "isSigner": true
        },
        {
          "name": "admin",
          "isMut": true,
          "isSigner": true
        },
        {
          "name": "mint",
          "isMut": true,
          "isSigner": false
        },
        {
          "name": "systemProgram",
          "isMut": false,
          "isSigner": false
        },
        {
          "name": "tokenProgram",
          "isMut": false,
          "isSigner": false
        },
        {
          "name": "rent",
          "isMut": false,
          "isSigner": false
        }
      ],
      "args": [
        {
          "name": "courseData",
          "type": {
            "defined": "CourseData"
          }
        }
      ]
    },
    {
      "name": "enrollInCourse",
      "accounts": [
        {
          "name": "academy",
          "isMut": true,
          "isSigner": false
        },
        {
          "name": "course",
          "isMut": true,
          "isSigner": false
        },
        {
          "name": "enrollment",
          "isMut": true,
          "isSigner": false
        },
        {
          "name": "student",
          "isMut": true,
          "isSigner": true
        },
        {
          "name": "systemProgram",
          "isMut": false,
          "isSigner": false
        }
      ],
      "args": [
        {
          "name": "courseId",
          "type": "u64"
        }
      ]
    }
  ],
  "accounts": [
    {
      "name": "Academy",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "name",
            "type": "string"
          },
          {
            "name": "admin",
            "type": "publicKey"
          },
          {
            "name": "courseCount",
            "type": "u64"
          }
        ]
      }
    },
    {
      "name": "Course",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "id",
            "type": "u64"
          },
          {
            "name": "name",
            "type": "string"
          },
          {
            "name": "description",
            "type": "string"
          },
          {
            "name": "startDate",
            "type": "i64"
          },
          {
            "name": "endDate",
            "type": "i64"
          },
          {
            "name": "tuitionFee",
            "type": "u64"
          },
          {
            "name": "enrollmentCount",
            "type": "u64"
          },
          {
            "name": "mint",
            "type": "publicKey"
          }
        ]
      }
    },
    {
      "name": "Enrollment",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "student",
            "type": "publicKey"
          },
          {
            "name": "course",
            "type": "publicKey"
          },
          {
            "name": "enrolledAt",
            "type": "i64"
          },
          {
            "name": "completed",
            "type": "bool"
          }
        ]
      }
    }
  ],
  "types": [
    {
      "name": "CourseData",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "name",
            "type": "string"
          },
          {
            "name": "description",
            "type": "string"
          },
          {
            "name": "startDate",
            "type": "i64"
          },
          {
            "name": "endDate",
            "type": "i64"
          },
          {
            "name": "tuitionFee",
            "type": "u64"
          }
        ]
      }
    }
  ],
  "errors": [
    {
      "code": 6000,
      "name": "InvalidCourseId",
      "msg": "The provided course ID is invalid"
    },
    {
      "code": 6001,
      "name": "CourseIsFull",
      "msg": "The course is already full"
    },
    {
      "code": 6002,
      "name": "AlreadyEnrolled",
      "msg": "The student is already enrolled in this course"
    },
    {
      "code": 6003,
      "name": "InsufficientBalance",
      "msg": "Insufficient balance to pay tuition fee"
    }
  ]
}

This is more like I was expecting the IDL to look like. Can you give this command a try on your local and see if we generate the same JSON file. @maplerichie @somthn0somthn

anchor build
@olasunkanmi-SE olasunkanmi-SE added question Further information is requested and removed question Further information is requested labels Sep 2, 2024
@somthn0somthn
Copy link
Collaborator

{
  "address": "79zUy3DKMd4xfFpjnzBVyxaaEzD6vV6aAVzHS8U7JS1Y",
  "metadata": {
    "name": "solana_academy",
    "version": "0.1.0",
    "spec": "0.1.0",
    "description": "Created with Anchor"
  },
  "instructions": [
    {
      "name": "create_course",
      "discriminator": [
        120,
        121,
        154,
        164,
        107,
        180,
        167,
        241
      ],
      "accounts": [
        {
          "name": "academy",
          "writable": true
        },
        {
          "name": "course",
          "writable": true,
          "signer": true
        },
        {
          "name": "admin",
          "writable": true,
          "signer": true,
          "relations": [
            "academy"
          ]
        },
        {
          "name": "system_program",
          "address": "11111111111111111111111111111111"
        }
      ],
      "args": [
        {
          "name": "course_data",
          "type": {
            "defined": {
              "name": "CourseData"
            }
          }
        }
      ]
    },
    {
      "name": "enroll_in_course",
      "discriminator": [
        148,
        151,
        118,
        109,
        223,
        161,
        90,
        172
      ],
      "accounts": [
        {
          "name": "academy",
          "writable": true
        },
        {
          "name": "course",
          "writable": true
        },
        {
          "name": "enrollment",
          "writable": true,
          "pda": {
            "seeds": [
              {
                "kind": "const",
                "value": [
                  101,
                  110,
                  114,
                  111,
                  108,
                  108,
                  109,
                  101,
                  110,
                  116
                ]
              },
              {
                "kind": "account",
                "path": "course"
              },
              {
                "kind": "account",
                "path": "student"
              }
            ]
          }
        },
        {
          "name": "student",
          "writable": true,
          "signer": true
        },
        {
          "name": "system_program",
          "address": "11111111111111111111111111111111"
        }
      ],
      "args": [
        {
          "name": "course_id",
          "type": "u64"
        }
      ]
    },
    {
      "name": "initialize_academy",
      "discriminator": [
        255,
        97,
        73,
        10,
        91,
        205,
        27,
        133
      ],
      "accounts": [
        {
          "name": "academy",
          "writable": true,
          "signer": true
        },
        {
          "name": "admin",
          "writable": true,
          "signer": true
        },
        {
          "name": "system_program",
          "address": "11111111111111111111111111111111"
        }
      ],
      "args": [
        {
          "name": "name",
          "type": "string"
        }
      ]
    }
  ],
  "accounts": [
    {
      "name": "Academy",
      "discriminator": [
        110,
        0,
        104,
        223,
        115,
        197,
        131,
        156
      ]
    },
    {
      "name": "Course",
      "discriminator": [
        206,
        6,
        78,
        228,
        163,
        138,
        241,
        106
      ]
    },
    {
      "name": "Enrollment",
      "discriminator": [
        249,
        210,
        64,
        145,
        197,
        241,
        57,
        51
      ]
    }
  ],
  "errors": [
    {
      "code": 6000,
      "name": "InvalidCourseId",
      "msg": "The provided course ID is invalid"
    },
    {
      "code": 6001,
      "name": "CourseIsFull",
      "msg": "The course is already full"
    },
    {
      "code": 6002,
      "name": "AlreadyEnrolled",
      "msg": "The student is already enrolled in this course"
    },
    {
      "code": 6003,
      "name": "InsufficientBalance",
      "msg": "Insufficient balance to pay tuition fee"
    }
  ],
  "types": [
    {
      "name": "Academy",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "name",
            "type": "string"
          },
          {
            "name": "admin",
            "type": "pubkey"
          },
          {
            "name": "course_count",
            "type": "u64"
          }
        ]
      }
    },
    {
      "name": "Course",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "id",
            "type": "u64"
          },
          {
            "name": "name",
            "type": "string"
          },
          {
            "name": "description",
            "type": "string"
          },
          {
            "name": "start_date",
            "type": "i64"
          },
          {
            "name": "end_date",
            "type": "i64"
          },
          {
            "name": "tuition_fee",
            "type": "u64"
          },
          {
            "name": "enrollment_count",
            "type": "u64"
          }
        ]
      }
    },
    {
      "name": "CourseData",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "name",
            "type": "string"
          },
          {
            "name": "description",
            "type": "string"
          },
          {
            "name": "start_date",
            "type": "i64"
          },
          {
            "name": "end_date",
            "type": "i64"
          },
          {
            "name": "tuition_fee",
            "type": "u64"
          }
        ]
      }
    },
    {
      "name": "Enrollment",
      "type": {
        "kind": "struct",
        "fields": [
          {
            "name": "student",
            "type": "pubkey"
          },
          {
            "name": "course",
            "type": "pubkey"
          },
          {
            "name": "enrolled_at",
            "type": "i64"
          },
          {
            "name": "completed",
            "type": "bool"
          }
        ]
      }
    }
  ]
}

@somthn0somthn
Copy link
Collaborator

somthn0somthn commented Sep 3, 2024

What's your anchor version? Mine is 0.30.1 . If you have a version earlier than 0.30 you'll be generating a legacy IDL type which is notably less verbose, like the one you shared. See Convert Legacy IDLs here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants