Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 7881

Account::try_from is not working because of the lifetime issue

$
0
0

I am trying to create an instruction where I decide which Account struct should be used based on an argument. I am accepting UncheckedAccount and trying to convert it to Account with PriceUpdateV2 struct data.

The error on Account::<PriceUpdateV2>::try_from says: "explicit lifetime required in the type of ctx"

if I replace '_ with 'info as analizer siggests it shows another error on #[program] like this: "__accounts does not live long enoughborrowed value does not live long enough"

here is the code:

#[program]pub mod oracle {  use pyth_solana_receiver_sdk::price_update::PriceUpdateV2;use super::*;  pub fn record_price_test<'info>(    ctx: Context<'_, '_, '_, 'info, Initialize<'info>>,     data_source_name: String,     asset_id: String,     timestamp: i64) -> Result<()> {    let account: Account<'_, PriceUpdateV2> = Account::<PriceUpdateV2>::try_from(&ctx.accounts.oracle_account).expect("Some error");    Ok(())  }}#[derive(Accounts)]pub struct Initialize<'info> {  pub oracle_account: UncheckedAccount<'info>,}

Viewing all articles
Browse latest Browse all 7881

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>