Solana

Solana

References:
programming-on-solana-an-introduction

The reason we have accounts is because Solana programs are stateless. Programs themselves are stored in accounts which are marked executable. Each account can hold data and SOL (opens new window). Each account also has an owner and only the owner may debit the account and adjust its data.

Accounts can only be owned by programs.

In theory, programs have full autonomy over the accounts they own. It is up to the program’s creator to limit this autonomy and up to the users of the program to verify the program’s creator has really done so.

All accounts to be read or written to must be passed into the entrypoint function

1
2
3
4
5
6
7
8
9
10
11
12
.
├─ src
│  ├─ lib.rs -> registering modules
│  ├─ entrypoint.rs -> entrypoint to the program
│  ├─ instruction.rs -> program API, (de)serializing instruction data
│  ├─ processor.rs -> program logic
│  ├─ state.rs -> program objects, (de)serializing state
│  ├─ error.rs -> program specific errors
├─ .gitignore
├─ Cargo.lock
├─ Cargo.toml
├─ Xargo.toml

The flow of a program using this structure looks like this:

  1. Someone calls the entrypoint
  2. The entrypoint forwards the arguments to the processor
  3. The processor asks instruction.rs to decode the instruction_data argument from the entrypoint function.
  4. Using the decoded data, the processor will now decide which processing function to use to process the request.
  5. The processor may use state.rs to encode state into or decode the state of an account which has been passed into the entrypoint.