Skip to content

Commit 9ac9d85

Browse files
authored
Chore: simplify readme example (#287)
* simplify readme example * absolute markdown paths * Update README.md
1 parent a63160e commit 9ac9d85

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

README.md

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616

1717
Star Frame is a modern Solana program framework designed to make developing on-chain programs more ergonomic, safe, and performant. Built with a trait-based architecture, it provides:
1818

19-
- **Performance**: Optimized for Solana's compute unit constraints by utilizing Pinocchio and our `unsized_type` system (check out the [Compute Units](example_programs/bench/COMPUTE_UNITS.md) benchmark vs Anchor).
20-
- **Developer Experience**: Intuitive APIs with comprehensive compile-time validation (traits and types all the way down!).
21-
- **Modularity**: Everything is a trait or a type, so you can use what you need when you need it. For example, the entrypoint is a method on the `StarFrameProgram` trait, and client/cpi account sets are associated types of the `ClientAccountSet` and `CpiAccountSet` traits.
19+
- **Performance**: Optimized for Solana's compute unit constraints by utilizing Pinocchio and our `unsized_type` system (check out the [Compute Units](/example_programs/bench/COMPUTE_UNITS.md) benchmark vs Anchor).
20+
- **Developer Experience**: Intuitive APIs with comprehensive compile-time validation (traits and types all the way down!).
21+
- **Modularity**: Everything is a trait or a type, so you can use what you need when you need it. For example, the entrypoint is a method on the `StarFrameProgram` trait, and client/cpi account sets are associated types of the `ClientAccountSet` and `CpiAccountSet` traits.
2222

2323
## Getting Help
2424

2525
Star Frame is in active development (and improving our docs is a main priority now!). If you need help:
2626

27-
- Check out the [API documentation](https://docs.rs/star_frame)
28-
- Browse the [examples](example_programs/) in this repository
29-
- Open an [issue](https://github.com/staratlasmeta/star_frame/issues) for bug reports or feature requests
30-
- Join our [Star Atlas Discord](https://discord.gg/gahmBHsc) and chat in our `#community-developers` channel
27+
- Check out the [API documentation](https://docs.rs/star_frame)
28+
- Browse the [examples](/example_programs/) in this repository
29+
- Open an [issue](https://github.com/staratlasmeta/star_frame/issues) for bug reports or feature requests
30+
- Join our [Star Atlas Discord](https://discord.gg/gahmBHsc) and chat in our `#community-developers` channel
3131

3232
## Getting Started
3333

@@ -59,6 +59,7 @@ use star_frame::prelude::*;
5959
## Example
6060

6161
Below is a simple counter program demonstrating the basic features of Star Frame. In this example, only the designated authority can increment the counter.
62+
See the [full example](/example_programs/simple_counter/src/lib.rs) for additional useful features.
6263

6364
```rust
6465
use star_frame::prelude::*;
@@ -78,71 +79,51 @@ pub enum CounterInstructionSet {
7879

7980
#[zero_copy(pod)]
8081
#[derive(ProgramAccount, Default, Debug, Eq, PartialEq)]
81-
#[program_account(seeds = CounterSeeds)]
8282
pub struct CounterAccount {
8383
pub authority: Pubkey,
8484
pub count: u64,
8585
}
8686

87-
#[derive(Debug, GetSeeds, Clone)]
88-
#[get_seeds(seed_const = b"COUNTER")]
89-
pub struct CounterSeeds {
90-
pub authority: Pubkey,
91-
}
92-
93-
#[derive(Debug)]
94-
pub struct Authority(Pubkey);
95-
96-
impl AccountValidate<Authority> for CounterAccount {
97-
fn validate_account(self_ref: &Self::Ref<'_>, arg: Authority) -> Result<()> {
98-
ensure!(arg.0 == self_ref.authority, "Incorrect authority", ProgramError::IncorrectAuthority);
99-
Ok(())
100-
}
101-
}
102-
103-
/// Initialize the counter
10487
#[derive(BorshSerialize, BorshDeserialize, Debug, InstructionArgs)]
10588
pub struct Initialize {
106-
#[ix_args(&run)]
107-
pub start_at: Option<u64>,
89+
#[ix_args(run)]
90+
pub start_at: u64,
10891
}
10992

11093
#[derive(AccountSet)]
11194
pub struct InitializeAccounts {
11295
#[validate(funder)]
11396
pub authority: Signer<Mut<SystemAccount>>,
114-
#[validate(arg = (
115-
Create(()),
116-
Seeds(CounterSeeds { authority: *self.authority.pubkey() }),
117-
))]
118-
#[idl(arg = Seeds(FindCounterSeeds { authority: seed_path("authority") }))]
119-
pub counter: Init<Seeded<Account<CounterAccount>>>,
97+
#[validate(arg = Create(()))]
98+
pub counter: Init<Signer<Account<CounterAccount>>>,
12099
pub system_program: Program<System>,
121100
}
122101

123102
#[star_frame_instruction]
124-
fn Initialize(account_set: &mut InitializeAccounts, start_at: &Option<u64>) -> Result<()> {
103+
fn Initialize(account_set: &mut InitializeAccounts, start_at: u64) -> Result<()> {
125104
**account_set.counter.data_mut()? = CounterAccount {
126105
authority: *account_set.authority.pubkey(),
127-
count: start_at.unwrap_or(0),
106+
count: start_at,
128107
};
129108
Ok(())
130109
}
131110

132-
/// Increment the counter by 1
133111
#[derive(BorshSerialize, BorshDeserialize, Debug, Copy, Clone, InstructionArgs)]
134112
pub struct Increment;
135113

136114
#[derive(AccountSet, Debug)]
137115
pub struct IncrementAccounts {
138116
pub authority: Signer,
139-
#[validate(arg = Authority(*self.authority.pubkey()))]
140-
pub counter: Mut<ValidatedAccount<CounterAccount>>,
117+
pub counter: Mut<Account<CounterAccount>>,
141118
}
142119

143120
#[star_frame_instruction]
144-
fn Increment(account_set: &mut IncrementAccounts) -> Result<()> {
145-
let mut counter = account_set.counter.data_mut()?;
121+
fn Increment(accounts: &mut IncrementAccounts) -> Result<()> {
122+
ensure!(
123+
*accounts.authority.pubkey() == accounts.counter.data()?.authority,
124+
ProgramError::IncorrectAuthority
125+
);
126+
let mut counter = accounts.counter.data_mut()?;
146127
counter.count += 1;
147128
Ok(())
148129
}

0 commit comments

Comments
 (0)