use cpi context
This commit is contained in:
@@ -90,7 +90,6 @@ create_escrow (seller) → deposit (buyer) → complete (buyer)
|
|||||||
cancel (seller, only from AwaitingDeposit)
|
cancel (seller, only from AwaitingDeposit)
|
||||||
```
|
```
|
||||||
|
|
||||||
**SOL transfers** use raw `invoke` / `invoke_signed` (not Anchor's CPI helpers) because Anchor 1.0.x changed `CpiContext::new` to take `Pubkey` instead of `AccountInfo`.
|
|
||||||
|
|
||||||
### Resolver Registry (`descro_ext_resolvers`)
|
### Resolver Registry (`descro_ext_resolvers`)
|
||||||
|
|
||||||
@@ -102,7 +101,7 @@ cancel (seller, only from AwaitingDeposit)
|
|||||||
|
|
||||||
### Anchor / SDK Notes
|
### Anchor / SDK Notes
|
||||||
|
|
||||||
- **Anchor 1.0.x:** `CpiContext::new` takes `Pubkey` not `AccountInfo`; use `UncheckedAccount<'info>` with `/// CHECK:` instead of `AccountInfo<'info>` in account structs; `#[derive(InitSpace)]` + `#[max_len(N)]` for strings.
|
- **Anchor 1.0.x:** use `UncheckedAccount<'info>` with `/// CHECK:` instead of `AccountInfo<'info>` in account structs; `#[derive(InitSpace)]` + `#[max_len(N)]` for strings.
|
||||||
- **`@coral-xyz/anchor@0.32.x`:** Use `new Program(idl, provider)` — the IDL's `address` field provides the program ID. The 3-argument form `new Program(idl, programId, provider)` is broken in 0.32.x.
|
- **`@coral-xyz/anchor@0.32.x`:** Use `new Program(idl, provider)` — the IDL's `address` field provides the program ID. The 3-argument form `new Program(idl, programId, provider)` is broken in 0.32.x.
|
||||||
- **LiteSVM tests:** each `tests/common/mod.rs` has `setup()`, PDA helpers, `send()`/`try_send()`, `ix_*` builders, and `read_*` deserializers. `test_resolve_with_registry.rs` loads both `.so` files to test the full CPI flow.
|
- **LiteSVM tests:** each `tests/common/mod.rs` has `setup()`, PDA helpers, `send()`/`try_send()`, `ix_*` builders, and `read_*` deserializers. `test_resolve_with_registry.rs` loads both `.so` files to test the full CPI flow.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use anchor_lang::prelude::*;
|
use anchor_lang::prelude::*;
|
||||||
use anchor_lang::solana_program::{program::invoke_signed, system_instruction};
|
use anchor_lang::system_program::{self, Transfer};
|
||||||
use crate::state::{EscrowAccount, EscrowState};
|
use crate::state::{EscrowAccount, EscrowState};
|
||||||
use crate::error::EscrowError;
|
use crate::error::EscrowError;
|
||||||
|
|
||||||
@@ -42,17 +42,16 @@ pub fn handler(ctx: Context<Complete>) -> Result<()> {
|
|||||||
let vault_bump = ctx.accounts.escrow_account.vault_bump;
|
let vault_bump = ctx.accounts.escrow_account.vault_bump;
|
||||||
let vault_balance = ctx.accounts.vault.to_account_info().lamports();
|
let vault_balance = ctx.accounts.vault.to_account_info().lamports();
|
||||||
|
|
||||||
invoke_signed(
|
system_program::transfer(
|
||||||
&system_instruction::transfer(
|
CpiContext::new_with_signer(
|
||||||
ctx.accounts.vault.to_account_info().key,
|
system_program::ID,
|
||||||
ctx.accounts.seller.to_account_info().key,
|
Transfer {
|
||||||
vault_balance,
|
from: ctx.accounts.vault.to_account_info(),
|
||||||
),
|
to: ctx.accounts.seller.to_account_info(),
|
||||||
&[
|
},
|
||||||
ctx.accounts.vault.to_account_info(),
|
|
||||||
ctx.accounts.seller.to_account_info(),
|
|
||||||
],
|
|
||||||
&[&[b"vault", escrow_key.as_ref(), &[vault_bump]]],
|
&[&[b"vault", escrow_key.as_ref(), &[vault_bump]]],
|
||||||
|
),
|
||||||
|
vault_balance,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use anchor_lang::prelude::*;
|
use anchor_lang::prelude::*;
|
||||||
use anchor_lang::solana_program::{program::invoke, system_instruction};
|
use anchor_lang::system_program::{self, Transfer};
|
||||||
use crate::state::{EscrowAccount, EscrowState};
|
use crate::state::{EscrowAccount, EscrowState};
|
||||||
use crate::error::EscrowError;
|
use crate::error::EscrowError;
|
||||||
|
|
||||||
@@ -31,16 +31,15 @@ pub struct Deposit<'info> {
|
|||||||
pub fn handler(ctx: Context<Deposit>) -> Result<()> {
|
pub fn handler(ctx: Context<Deposit>) -> Result<()> {
|
||||||
let amount = ctx.accounts.escrow_account.amount;
|
let amount = ctx.accounts.escrow_account.amount;
|
||||||
|
|
||||||
invoke(
|
system_program::transfer(
|
||||||
&system_instruction::transfer(
|
CpiContext::new(
|
||||||
ctx.accounts.buyer.to_account_info().key,
|
system_program::ID,
|
||||||
ctx.accounts.vault.to_account_info().key,
|
Transfer {
|
||||||
amount,
|
from: ctx.accounts.buyer.to_account_info(),
|
||||||
|
to: ctx.accounts.vault.to_account_info(),
|
||||||
|
},
|
||||||
),
|
),
|
||||||
&[
|
amount,
|
||||||
ctx.accounts.buyer.to_account_info(),
|
|
||||||
ctx.accounts.vault.to_account_info(),
|
|
||||||
],
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
ctx.accounts.escrow_account.state = EscrowState::Active;
|
ctx.accounts.escrow_account.state = EscrowState::Active;
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
use crate::error::EscrowError;
|
use crate::error::EscrowError;
|
||||||
use crate::state::{EscrowAccount, EscrowState, Winner};
|
use crate::state::{EscrowAccount, EscrowState, Winner};
|
||||||
use anchor_lang::solana_program::{program::invoke_signed, system_instruction};
|
use anchor_lang::system_program::{self, Transfer};
|
||||||
use anchor_lang::system_program::Transfer;
|
use anchor_lang::prelude::*;
|
||||||
use anchor_lang::{prelude::*, system_program};
|
|
||||||
use descro_ext_resolvers::state::Ruling;
|
use descro_ext_resolvers::state::Ruling;
|
||||||
|
|
||||||
#[derive(Accounts)]
|
#[derive(Accounts)]
|
||||||
|
|||||||
Reference in New Issue
Block a user