Skip to content

Commit

Permalink
Dont assume all erros are 0 balance (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Plant authored Nov 13, 2023
1 parent 7d00ec4 commit 0360679
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions solana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use helium_crypto::PublicKeyBinary;
use helium_sub_daos::{DaoV0, SubDaoV0};
use serde::Deserialize;
use sha2::{Digest, Sha256};
use solana_client::{client_error::ClientError, nonblocking::rpc_client::RpcClient};
use solana_client::{
client_error::ClientError, nonblocking::rpc_client::RpcClient, rpc_response::Response,
};
use solana_sdk::{
commitment_config::CommitmentConfig,
program_pack::Pack,
Expand Down Expand Up @@ -124,10 +126,19 @@ impl SolanaNetwork for SolanaRpc {
&["escrow_dc_account".as_bytes(), &ddc_key.to_bytes()],
&data_credits::ID,
);
let Ok(account_data) = self.provider.get_account_data(&escrow_account).await else {
// If the account is empty, it has no DC
tracing::info!(%payer, "Account not found, therefore no balance");
return Ok(0);
let account_data = match self
.provider
.get_account_with_commitment(&escrow_account, CommitmentConfig::finalized())
.await?
{
Response { value: None, .. } => {
tracing::info!(%payer, "Account not found, therefore no balance");
return Ok(0);
}
Response {
value: Some(account),
..
} => account.data,
};
let account_layout = spl_token::state::Account::unpack(account_data.as_slice())?;

Expand Down

0 comments on commit 0360679

Please sign in to comment.