Skip to content

Commit 5225483

Browse files
committed
Update owner and signer check examples
1 parent 46e5ac9 commit 5225483

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

Diff for: not-so-smart-contracts/solana/ownership_check/README.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ Therefore, a malicious actor can set themselves as the new authority without bei
99

1010
### Example Contract
1111
```rust
12-
fn set_authority(program_id: &Pubkey, new_authority: Pubkey, accounts: &[AccountInfo]) -> ProgramResult {
13-
let account_info_iter = &mut accounts.iter();
14-
let market_info = next_account_info(account_info_iter)?;
15-
let current_authority = next_account_info(account_info_iter)?;
12+
fn pay_escrow(_program_id: &Pubkey, accounts: &[AccountInfo], _instruction_data: &[u8]) -> ProgramResult {
13+
let account_info_iter = &mut accounts.iter();
14+
let state_info = next_account_info(account_info_iter)?;
15+
let escrow_vault_info = next_account_info(account_info_iter)?;
16+
let escrow_receiver_info = next_account_info(account_info_iter)?;
1617

17-
let mut market = Market::unpack(&market_info.data.borrow())?;
18+
let state = State::deserialize(&mut &**state_info.data.borrow())?;
1819

19-
if &market.authority != current_authority.pubkey {
20-
return Err(InvalidMarketAuthority.into());
21-
}
22-
market.authority = new_authority;
23-
24-
...
20+
if state.escrow_state == EscrowState::Complete {
21+
**escrow_vault_info.try_borrow_mut_lamports()? -= state.amount;
22+
**escrow_receiver_info.try_borrow_mut_lamports()? += state.amount;
23+
}
2524

26-
Ok(())
25+
Ok(())
2726
}
2827
```
2928
*Inspired by [SPL Lending Program](https://github.com/solana-labs/solana-program-library/tree/master/token-lending/program)*

Diff for: not-so-smart-contracts/solana/signer_check/README.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ Therefore, a malicious actor can set themselves as the new authority without bei
99

1010
### Example Contract
1111
```rust
12-
fn set_authority(program_id: &Pubkey, new_authority: Pubkey, accounts: &[AccountInfo]) -> ProgramResult {
13-
let account_info_iter = &mut accounts.iter();
14-
let market_info = next_account_info(account_info_iter)?;
15-
let current_authority = next_account_info(account_info_iter)?;
12+
fn pay_escrow(_program_id: &Pubkey, accounts: &[AccountInfo], _instruction_data: &[u8]) -> ProgramResult {
13+
let account_info_iter = &mut accounts.iter();
14+
let state_info = next_account_info(account_info_iter)?;
15+
let escrow_vault_info = next_account_info(account_info_iter)?;
16+
let escrow_receiver_info = next_account_info(account_info_iter)?;
1617

17-
let mut market = Market::unpack(&market_info.data.borrow())?;
18+
let state = State::deserialize(&mut &**state_info.data.borrow())?;
1819

19-
if &market.authority != current_authority.pubkey {
20-
return Err(InvalidMarketAuthority.into());
21-
}
22-
market.authority = new_authority;
23-
24-
...
20+
if state.escrow_state == EscrowState::Complete {
21+
**escrow_vault_info.try_borrow_mut_lamports()? -= state.amount;
22+
**escrow_receiver_info.try_borrow_mut_lamports()? += state.amount;
23+
}
2524

26-
Ok(())
25+
Ok(())
2726
}
2827
```
2928
*Inspired by [SPL Lending Program](https://github.com/solana-labs/solana-program-library/tree/master/token-lending/program)*

0 commit comments

Comments
 (0)