use cpi context

This commit is contained in:
thesn10
2026-05-18 23:18:26 +02:00
parent 480d894810
commit 5bfde3ec6e
4 changed files with 22 additions and 26 deletions

View File

@@ -90,7 +90,6 @@ create_escrow (seller) → deposit (buyer) → complete (buyer)
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`)
@@ -102,7 +101,7 @@ cancel (seller, only from AwaitingDeposit)
### 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.
- **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.

View File

@@ -1,5 +1,5 @@
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::error::EscrowError;
@@ -42,17 +42,16 @@ pub fn handler(ctx: Context<Complete>) -> Result<()> {
let vault_bump = ctx.accounts.escrow_account.vault_bump;
let vault_balance = ctx.accounts.vault.to_account_info().lamports();
invoke_signed(
&system_instruction::transfer(
ctx.accounts.vault.to_account_info().key,
ctx.accounts.seller.to_account_info().key,
vault_balance,
system_program::transfer(
CpiContext::new_with_signer(
system_program::ID,
Transfer {
from: ctx.accounts.vault.to_account_info(),
to: ctx.accounts.seller.to_account_info(),
},
&[&[b"vault", escrow_key.as_ref(), &[vault_bump]]],
),
&[
ctx.accounts.vault.to_account_info(),
ctx.accounts.seller.to_account_info(),
],
&[&[b"vault", escrow_key.as_ref(), &[vault_bump]]],
vault_balance,
)?;
Ok(())

View File

@@ -1,5 +1,5 @@
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::error::EscrowError;
@@ -31,16 +31,15 @@ pub struct Deposit<'info> {
pub fn handler(ctx: Context<Deposit>) -> Result<()> {
let amount = ctx.accounts.escrow_account.amount;
invoke(
&system_instruction::transfer(
ctx.accounts.buyer.to_account_info().key,
ctx.accounts.vault.to_account_info().key,
amount,
system_program::transfer(
CpiContext::new(
system_program::ID,
Transfer {
from: ctx.accounts.buyer.to_account_info(),
to: ctx.accounts.vault.to_account_info(),
},
),
&[
ctx.accounts.buyer.to_account_info(),
ctx.accounts.vault.to_account_info(),
],
amount,
)?;
ctx.accounts.escrow_account.state = EscrowState::Active;

View File

@@ -1,8 +1,7 @@
use crate::error::EscrowError;
use crate::state::{EscrowAccount, EscrowState, Winner};
use anchor_lang::solana_program::{program::invoke_signed, system_instruction};
use anchor_lang::system_program::Transfer;
use anchor_lang::{prelude::*, system_program};
use anchor_lang::system_program::{self, Transfer};
use anchor_lang::prelude::*;
use descro_ext_resolvers::state::Ruling;
#[derive(Accounts)]