Skip to content

Commit

Permalink
Revert "update helium-lib to take router_key as a string (#943)"
Browse files Browse the repository at this point in the history
This reverts commit fc57aaa.
  • Loading branch information
michaeldjeffrey committed Feb 25, 2025
1 parent 356e606 commit ffbbb0f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ sqlx = { version = "0", features = [
"runtime-tokio-rustls",
] }
helium-anchor-gen = { git = "https://github.com/helium/helium-anchor-gen.git" }
helium-crypto = { version = "0.8.4", features = ["multisig", "solana"] }
helium-crypto = { version = "0.8.4", features = ["multisig"] }
helium-lib = { git = "https://github.com/helium/helium-wallet-rs.git", branch = "master" }
hextree = { git = "https://github.com/jaykickliter/HexTree", branch = "main", features = [
"disktree",
Expand Down
14 changes: 11 additions & 3 deletions solana/src/burn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
read_keypair_from_file, sender, GetSignature, Keypair, SolanaRpcError, SubDao, Transaction,
read_keypair_from_file, sender, GetSignature, Keypair, Pubkey, SolanaRpcError, SubDao,
Transaction,
};
use async_trait::async_trait;
use helium_crypto::PublicKeyBinary;
Expand Down Expand Up @@ -58,7 +59,12 @@ pub struct SolanaRpc {

impl SolanaRpc {
pub async fn new(settings: &Settings, sub_dao: SubDao) -> Result<Arc<Self>, SolanaRpcError> {
let keypair = read_keypair_from_file(&settings.burn_keypair)?;
let Ok(keypair) = read_keypair_from_file(&settings.burn_keypair) else {
return Err(SolanaRpcError::FailedToReadKeypairError(
settings.burn_keypair.to_owned(),
));
};

let provider = client::SolanaRpcClient::new_with_commitment(
settings.rpc_url.clone(),
CommitmentConfig::finalized(),
Expand All @@ -85,7 +91,8 @@ impl SolanaNetwork for SolanaRpc {
type Transaction = Transaction;

async fn payer_balance(&self, payer: &PublicKeyBinary) -> Result<u64, SolanaRpcError> {
let delegated_dc_key = SubDao::Iot.delegated_dc_key(payer);
let payer_pubkey = Pubkey::try_from(payer.as_ref())?;
let delegated_dc_key = SubDao::Iot.delegated_dc_key(&payer_pubkey.to_string());
let escrow_account = SubDao::Iot.escrow_key(&delegated_dc_key);

let amount = match token::balance_for_address(&self, &escrow_account).await? {
Expand All @@ -112,6 +119,7 @@ impl SolanaNetwork for SolanaRpc {
payer: &PublicKeyBinary,
amount: u64,
) -> Result<Self::Transaction, SolanaRpcError> {
let payer = Pubkey::try_from(payer.as_ref())?;
let tx = dc::burn_delegated(
self,
self.sub_dao,
Expand Down
13 changes: 8 additions & 5 deletions solana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use helium_lib::{
error,
keypair::{Keypair, Pubkey, Signature},
};
pub use solana_sdk::transaction::VersionedTransaction as SolanaTransaction;
pub use solana_sdk::transaction::Transaction as SolanaTransaction;

#[derive(serde::Serialize)]
pub struct Transaction {
Expand Down Expand Up @@ -50,11 +50,14 @@ pub mod carrier;
pub mod sender;
pub mod start_boost;

pub fn read_keypair_from_file<F: AsRef<Path>>(path: F) -> Result<Keypair, SolanaRpcError> {
pub fn read_keypair_from_file<F: AsRef<Path>>(path: F) -> anyhow::Result<Keypair> {
let path = path.as_ref();
let keypair = read_keypair_file(path)
.map_err(|_err| SolanaRpcError::FailedToReadKeypairError(path.display().to_string()))?;
Ok(keypair.into())
let keypair = read_keypair_file(path).map_err(|_e| {
let path = path.display().to_string();
SolanaRpcError::FailedToReadKeypairError(path)
})?;
let bytes = keypair.to_bytes();
Ok(Keypair::try_from(&bytes)?)
}

#[derive(thiserror::Error, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion solana/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ mod tests {
let mut inner = solana_sdk::transaction::Transaction::default();
inner.signatures.push(Signature::new_unique());
Transaction {
inner: inner.into(),
inner,
sent_block_height: 1,
}
}
Expand Down
6 changes: 5 additions & 1 deletion solana/src/start_boost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ pub struct SolanaRpc {

impl SolanaRpc {
pub async fn new(settings: &Settings) -> Result<Arc<Self>, SolanaRpcError> {
let keypair = read_keypair_from_file(&settings.start_authority_keypair)?;
let Ok(keypair) = read_keypair_from_file(&settings.start_authority_keypair) else {
return Err(SolanaRpcError::FailedToReadKeypairError(
settings.start_authority_keypair.to_owned(),
));
};
let provider = client::SolanaRpcClient::new_with_commitment(
settings.rpc_url.clone(),
CommitmentConfig::finalized(),
Expand Down

0 comments on commit ffbbb0f

Please sign in to comment.