老师们好,我在写solana时遇到一个问题,问题代码如下,我如何将receivers(pubkey类型), to: receiver.to_account_info()是错误的,如何才能在to中使用AccountInfo类型?报错如下: he method to_account_info exists for struct Pubkey, but its trait bounds were not satisfied --> src/lib.rs:148:30 | 148 | to: receiver.to_account_info(), | ^^^^^^^^^^^^^^^ method cannot be called on Pubkey due to unsatisfied trait bounds 删掉to_account_info()则报错不是AccountInfo类型。
pub fn outbox(
ctx: Context,
receivers: Vec,
amounts: Vec,
data: Vec,
) -> Result<()> {
require!(
ctx.accounts
.state
.maker_list
.contains_key(&ctx.accounts.user.key()),
ErrorCode::NotMaker
);
require!(receivers.len() == amounts.len(), ErrorCode::InvalidLength);
for (i, &receiver) in receivers.iter().enumerate() {
let cpi_accounts = Transfer {
from: ctx.accounts.contract_token_account.to_account_info(),
to: receiver.to_account_info(),
authority: ctx.accounts.contract_authority.to_account_info(),
};
let cpi_program = ctx.accounts.token_program.to_account_info();
let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
token::transfer(cpi_ctx, amounts[i])?;
emit!(OutboxEvent {
token: ctx.accounts.contract_token_account.key(),
to: receiver.key(),
amount: amounts[i],
data: data,
});
}
Ok(())
}
#[derive(Accounts)]
pub struct Outbox<'info> {
pub state: Account<'info, InitializeState>,
#[account(mut)]
pub user: Signer<'info>,
pub contract_token_account: Account<'info, TokenAccount>,
pub contract_authority: Signer<'info>,
pub token_program: Program<'info, Token>,
}
#[account]
pub struct InitializeState {
pub owner: Pubkey,
pub paused: bool,
pub fee: u64,
pub fee_receiver: Pubkey,
pub maker_list: HashMap<Pubkey, bool>,
}
#[event]
pub struct OutboxEvent {
pub token: Pubkey,
pub to: Pubkey,
pub amount: u64,
pub data: Vec,
}