Writing an instruction: create

In the previous sections, we have defined our program's main data structure VestingContract. The next step is to write our program's one of two main primitives: create.

We'll start by renaming the src/processor/example_instr.rs file to create.rs. Similarly we'll rename the ExampleInstr variant of the instruction::ProgramInstruction enum to Create, and the instruction::example binding to create. We should also alter the log message in processor.rs from "Instruction: Example Instruction" to "Instruction: Create", and update the instruction comment at the top of create.rs to //! Create a new token vesting contract.

This primitive will perform several operations:

  • Initialize a new VestingContract account/object.
  • Configure the VestingContract with user-provided parameters.
  • Transfer funds into the program vault.

An instruction's specification is defined by its Accounts and Params objects. Let's start by thinking about what kinds of accounts we'll need, and then we'll take a look at the associated parameters.