如何将Pubkey添加到包含锚定程序中Pubkey向量的帐户中


use anchor_lang::prelude::*;
use rand::Rng;
use solana_program::{declare_id, pubkey::Pubkey};
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
pub mod raffle_impl {
use super::*;
pub fn create_raffle(ctx: Context<CreateRaffle>, authority: Pubkey) -> ProgramResult{
let payer = &mut ctx.accounts.wallet;
let escrow_account = &mut ctx.accounts.escrow_account;
Ok(())
}

这个wallet_address_to_dd是一个Pubkey,它将在事务中从前端传递。它应该被推送到下面定义的帐户宏中定义的向量。

pub fn add_participants(ctx: Context<AddParticipants>, wallet_address_to_add: Pubkey) -> 
ProgramResult{
let payer = &mut ctx.accounts.wallet;
let mut data = &mut ctx.accounts.escrow_account.data;
data = data.push(wallet_address_to_add); // Error occurs here
Ok(())
}
}
#[derive(Accounts)]
pub struct AddParticipants<'info>{
#[account(mut,signer)]
pub wallet: AccountInfo<'info>,
#[account(mut)]
pub owner: AccountInfo<'info>,
#[account(init_if_needed, payer = wallet, space=8+16)]
pub escrow_account: Account<'info, EscrowAccount>,
pub system_program: Program<'info, System>,
pub rent: Sysvar<'info, Rent>,
#[account]
#[derive(Default)]    
pub struct EscrowAccount{
pub data: Vec<Pubkey>,
pub length: usize,
pub payer: Pubkey,
pub authority: Pubkey,
}

我一直得到的错误是";预期的可变引用CCD_ 1找到了单元类型CCD_">

您应该只执行data.push(wallet_address_to_add);而不执行data =部分,而不是data = data.push(wallet_address_to_add);

相关内容

  • 没有找到相关文章

最新更新