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

PDAs: add snippet to remove has_one constraint #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/chapter_3/PDAs.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@ impl<'info> PullStrings<'info> {

The `authority` account is now an `UncheckedAccount` instead of a `Signer`. When the puppet-master is invoked, the `authority` pda is not a signer yet so we mustn't add a check for it. We just care about the puppet-master being able to sign so we don't add any additional seeds. Just a bump that is calculated off-chain and then passed to the function.

Then, adjust the puppet code. This is a simple change, we just want to remove the `has_one` constraint on the puppet account. The [`has_one` constraint](https://docs.rs/anchor-lang/latest/anchor_lang/derive.Accounts.html) checks if `puppet.owner == authority.key()`, which is no longer satisfied since we're passing a PDA as the authority.
```rust,ignore
#[derive(Accounts)]
pub struct SetData<'info> {
#[account(mut)]
pub puppet: Account<'info, Data>,
pub authority: Signer<'info>
}
```

Finally, this is the new `puppet.ts`:
```ts
import * as anchor from '@project-serum/anchor';
Expand Down