Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up hotspot location uses, reuse hpl key serialization #367

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions helium-lib/src/entity_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ impl AsEntityKey for helium_crypto::PublicKey {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Copy)]
pub enum EntityKeyEncoding {
String,
UTF8,
}
pub use helium_anchor_gen::helium_entity_manager::KeySerialization;

pub fn from_string(str: String, encoding: EntityKeyEncoding) -> Result<Vec<u8>> {
pub fn from_string(str: String, encoding: KeySerialization) -> Result<Vec<u8>> {
let entity_key = match encoding {
EntityKeyEncoding::String => str.as_entity_key(),
EntityKeyEncoding::UTF8 => bs58::decode(str).into_vec().map_err(DecodeError::from)?,
KeySerialization::UTF8 => str.as_entity_key(),
KeySerialization::B58 => bs58::decode(str).into_vec().map_err(DecodeError::from)?,
};
Ok(entity_key)
}
9 changes: 8 additions & 1 deletion helium-lib/src/hotspot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,12 @@ impl TryFrom<asset::AssetPage> for HotspotPage {
}

#[derive(Debug, Serialize, Clone)]
#[skip_serializing_none]
pub struct Hotspot {
pub key: helium_crypto::PublicKey,
pub name: String,
#[serde(with = "serde_pubkey")]
pub owner: Pubkey,
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<HashMap<SubDao, HotspotInfo>>,
}

Expand Down Expand Up @@ -743,6 +743,13 @@ impl TryFrom<u64> for HotspotLocation {
}
}

impl FromStr for HotspotLocation {
type Err = h3o::error::InvalidCellIndex;
fn from_str(s: &str) -> StdResult<Self, Self::Err> {
s.parse::<h3o::CellIndex>().map(Into::into)
}
}

impl HotspotLocation {
pub fn from_maybe<T: TryInto<HotspotLocation>>(value: Option<T>) -> Option<Self> {
value.and_then(|v| TryInto::try_into(v).ok())
Expand Down
6 changes: 3 additions & 3 deletions helium-lib/src/reward.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
asset,
dao::SubDao,
entity_key::{self, AsEntityKey, EntityKeyEncoding},
entity_key::{self, AsEntityKey, KeySerialization},
keypair::{Keypair, Pubkey, PublicKey},
programs::SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
result::{DecodeError, Error, Result},
Expand Down Expand Up @@ -60,7 +60,7 @@ pub async fn claim<C: Clone + Deref<Target = impl Signer>, E>(
settings: &Settings,
subdao: &SubDao,
entity_key_string: &str,
entity_key_encoding: EntityKeyEncoding,
entity_key_encoding: KeySerialization,
keypair: C,
) -> Result<solana_sdk::transaction::Transaction>
where
Expand Down Expand Up @@ -214,7 +214,7 @@ pub async fn pending(
settings: &Settings,
subdao: &SubDao,
entity_key_strings: &[String],
entity_key_encoding: EntityKeyEncoding,
entity_key_encoding: KeySerialization,
) -> Result<HashMap<String, OracleReward>> {
fn for_entity_key(
bulk_rewards: &HashMap<String, Vec<OracleReward>>,
Expand Down
4 changes: 2 additions & 2 deletions helium-wallet/src/cmd/hotspots/rewards.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::cmd::*;
use helium_lib::{dao::SubDao, entity_key::EntityKeyEncoding, reward};
use helium_lib::{dao::SubDao, entity_key::KeySerialization, reward};

#[derive(Debug, Clone, clap::Args)]
pub struct Cmd {
Expand Down Expand Up @@ -46,7 +46,7 @@ impl PendingCmd {
&settings,
&self.subdao,
&entity_key_strings,
EntityKeyEncoding::UTF8,
KeySerialization::B58,
)
.await?;

Expand Down