File tree 2 files changed +22
-24
lines changed
not-so-smart-contracts/solana
2 files changed +22
-24
lines changed Original file line number Diff line number Diff line change @@ -9,21 +9,20 @@ Therefore, a malicious actor can set themselves as the new authority without bei
9
9
10
10
### Example Contract
11
11
``` 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 )? ;
16
17
17
- let mut market = Market :: unpack ( & market_info . data. borrow ())? ;
18
+ let state = State :: deserialize ( & mut & * * state_info . data. borrow ())? ;
18
19
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
+ }
25
24
26
- Ok (())
25
+ Ok (())
27
26
}
28
27
```
29
28
* Inspired by [ SPL Lending Program] ( https://github.com/solana-labs/solana-program-library/tree/master/token-lending/program ) *
Original file line number Diff line number Diff line change @@ -9,21 +9,20 @@ Therefore, a malicious actor can set themselves as the new authority without bei
9
9
10
10
### Example Contract
11
11
``` 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 )? ;
16
17
17
- let mut market = Market :: unpack ( & market_info . data. borrow ())? ;
18
+ let state = State :: deserialize ( & mut & * * state_info . data. borrow ())? ;
18
19
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
+ }
25
24
26
- Ok (())
25
+ Ok (())
27
26
}
28
27
```
29
28
* Inspired by [ SPL Lending Program] ( https://github.com/solana-labs/solana-program-library/tree/master/token-lending/program ) *
You can’t perform that action at this time.
0 commit comments