Skip to content

Commit

Permalink
Add hotspots transfer command
Browse files Browse the repository at this point in the history
also generalizes setting compute budget and price as commands on the anchor RequestBuilder
  • Loading branch information
madninja committed Jun 10, 2024
1 parent 57a510b commit 7d8eaef
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 77 deletions.
56 changes: 40 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions helium-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ reqwest = { version = "0", default-features = false, features = [
] }
helium-anchor-gen = {git = "https://github.com/helium/helium-anchor-gen.git"}
spl-associated-token-account = { version = "*", features = ["no-entrypoint"] }
mpl-bubblegum = "1"
solana-program = "*"
solana-transaction-status = "*"
serde = {workspace = true}
Expand Down
42 changes: 40 additions & 2 deletions helium-lib/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use crate::{
settings::{DasClient, DasSearchAssetsParams, Settings},
};
use helium_anchor_gen::helium_entity_manager;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use solana_sdk::{bs58, signer::Signer};
use std::{ops::Deref, result::Result as StdResult, str::FromStr};
use std::{collections::HashMap, ops::Deref, result::Result as StdResult, str::FromStr};

pub async fn account_for_entity_key<C: Clone + Deref<Target = impl Signer>, E>(
client: &anchor_client::Client<C>,
Expand Down Expand Up @@ -54,6 +55,26 @@ pub async fn get_with_proof(
Ok((asset, asset_proof))
}

pub async fn get_canopy_heights() -> Result<HashMap<Pubkey, usize>> {
const KNOWN_CANOPY_HEIGHT_URL: &str = "https://shdw-drive.genesysgo.net/6tcnBSybPG7piEDShBcrVtYJDPSvGrDbVvXmXKpzBvWP/merkles.json";
let client = reqwest::Client::new();
let map: HashMap<String, usize> = client
.get(KNOWN_CANOPY_HEIGHT_URL)
.send()
.await?
.error_for_status()?
.json()
.await?;

map.into_iter()
.map(|(str, value)| {
Pubkey::from_str(str.as_str())
.map_err(|err| DecodeError::from(err).into())
.map(|key| (key, value))
})
.try_collect()
}

pub mod proof {
use super::*;

Expand Down Expand Up @@ -151,12 +172,18 @@ pub struct AssetProof {
pub proof: Vec<String>,
#[serde(with = "serde_pubkey")]
pub root: Pubkey,
#[serde(with = "serde_pubkey")]
pub tree_id: Pubkey,
}

impl AssetProof {
pub fn proof(&self) -> Result<Vec<solana_program::instruction::AccountMeta>> {
pub fn proof(
&self,
len: Option<usize>,
) -> Result<Vec<solana_program::instruction::AccountMeta>> {
self.proof
.iter()
.take(len.unwrap_or(self.proof.len()))
.map(|s| {
Pubkey::from_str(s)
.map_err(DecodeError::from)
Expand All @@ -169,6 +196,17 @@ impl AssetProof {
})
.collect()
}

pub async fn proof_for_tree(
&self,
tree: &Pubkey,
) -> Result<Vec<solana_program::instruction::AccountMeta>> {
let canopy_heights = get_canopy_heights().await?;
let height = canopy_heights
.get(tree)
.ok_or_else(|| anchor_client::ClientError::AccountNotFound)?;
self.proof(Some(*height))
}
}

#[derive(Debug, Deserialize, Serialize, Clone)]
Expand Down
Loading

0 comments on commit 7d8eaef

Please sign in to comment.