use std::collections::HashMap;
use {anchor_lang::prelude::*, hpl_utils::Default};
#[account]
pub struct User {
pub bump: u8,
pub primary_wallet: Pubkey,
pub secondary_wallets: Vec<Pubkey>,
pub username: String,
pub name: String,
pub bio: String,
pub pfp: String,
}
impl Default for User {
const LEN: usize = 160 + 8; fn set_defaults(&mut self) {
self.bump = 0;
self.primary_wallet = Pubkey::default();
self.secondary_wallets = vec![];
self.username = String::from("");
self.name = String::from("");
self.bio = String::from("");
self.pfp = String::from("");
}
}
#[account]
pub struct WalletResolver {
pub bump: u8,
pub user: Pubkey,
pub wallet: Pubkey,
}
impl Default for WalletResolver {
const LEN: usize = 65 + 8; fn set_defaults(&mut self) {
self.bump = 0;
self.user = Pubkey::default();
self.wallet = Pubkey::default();
}
}
#[account]
pub struct Profile {
pub bump: u8,
pub project: Pubkey,
pub user: Pubkey,
pub identity: ProfileIdentity,
pub data: HashMap<String, ProfileData>,
}
impl Default for Profile {
const LEN: usize = 96 + 10 + 8; fn set_defaults(&mut self) {
self.bump = 0;
self.project = Pubkey::default();
self.user = Pubkey::default();
self.identity = ProfileIdentity::Main;
self.data = HashMap::new();
}
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, PartialEq)]
pub enum ProfileIdentity {
Main,
Wallet { key: Pubkey },
Value { value: String },
}
impl ProfileIdentity {
pub fn to_bytes(&self) -> Vec<u8> {
match self {
ProfileIdentity::Main => {
let value = String::from("main");
value.as_bytes().to_vec()
}
ProfileIdentity::Wallet { key } => key.as_ref().to_vec(),
ProfileIdentity::Value { value } => value.as_bytes().to_vec(),
}
}
pub fn to_string(&self) -> String {
match self {
ProfileIdentity::Main => String::from("main"),
ProfileIdentity::Wallet { key } => key.to_string(),
ProfileIdentity::Value { value } => value.clone(),
}
}
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, PartialEq)]
pub enum ProfileData {
SingleValue { value: String },
MultiValue { value: Vec<String> },
Entity { tree: Pubkey },
}
impl ProfileData {
pub const LEN: usize = 8 + 40;
}