so I'm looking to create an instruction that creates an account called GamePot that contains a field called TokenInfo
that holds the data for what is meant to be any particular SPL token with a mint account and token account. The idea is that numerous people will be depositing into this account. Sidenote: I also have the issue of properly handling more than two users writing to what is effectively a shared game account via transfers.
#[account]
pub struct GamePot {
pub current_total: u64,
pub total_winnings: u64,
pub token_info: TokenInfo,
pub bump: u8
}
#[derive(AnchorSerialize, AnchorDeserialize)]
pub struct TokenInfo {
pub mint_account: Mint,
pub token_account: Token,
}
My issue, however, are several errors appearing that all seem to be related to AnchorSerialize/Deserialize and how they're being implemented in TokenInfo
.
the trait bound `anchor_spl::token::Mint: anchor_lang::AnchorSerialize` is not satisfied
the trait bound `anchor_spl::token::Token: anchor_lang::AnchorSerialize` is not satisfied
This was Bard's suggestion for TokenInfo
...
Unsatisfied trait bounds for TokenInfo:
Error: TokenInfo doesn't implement AnchorSerialize and AnchorDeserialize due to the embedded fields Mint and Token not implementing them.
Solution:
Add the #![feature(trivial_bounds)] attribute to your crate: This enables a feature that allows traits to be implemented for types containing fields that don't implement the trait themselves.
Implement AnchorSerialize and AnchorDeserialize for Mint and Token: This might be a more robust solution, but it depends on the specific libraries you're using for these types.