Skip to content

Commit

Permalink
resolve subdao address via helium lib
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Dec 18, 2024
1 parent 9e729c7 commit e9edb2e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 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 iot_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ file-store = { path = "../file_store" }
futures = { workspace = true }
futures-util = { workspace = true }
helium-crypto = { workspace = true, features = ["sqlx-postgres"] }
helium-lib = { workspace = true }
helium-proto = { workspace = true }
hextree = { workspace = true }
http = { workspace = true }
Expand Down
7 changes: 4 additions & 3 deletions iot_config/src/client/sub_dao_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::{call_with_retry, ClientError, Settings};
use crate::sub_dao_epoch_reward_info::EpochRewardInfo;
use file_store::traits::MsgVerify;
use helium_crypto::{Keypair, PublicKey, Sign};
use helium_lib::keypair::Pubkey;
use helium_proto::{
services::{
sub_dao::{self, SubDaoEpochRewardInfoReqV1},
Expand Down Expand Up @@ -39,7 +40,7 @@ pub trait SubDaoEpochRewardInfoResolver: Clone + Send + Sync + 'static {

async fn resolve_info(
&self,
sub_dao: &str,
sub_dao: &Pubkey,
epoch: u64,
) -> Result<Option<EpochRewardInfo>, Self::Error>;
}
Expand All @@ -50,11 +51,11 @@ impl SubDaoEpochRewardInfoResolver for SubDaoClient {

async fn resolve_info(
&self,
sub_dao: &str,
sub_dao: &Pubkey,
epoch: u64,
) -> Result<Option<EpochRewardInfo>, Self::Error> {
let mut request = SubDaoEpochRewardInfoReqV1 {
sub_dao_address: sub_dao.into(),
sub_dao_address: sub_dao.to_string(),
epoch,
signer: self.signing_key.public_key().into(),
signature: vec![],
Expand Down
7 changes: 5 additions & 2 deletions iot_verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ pub mod telemetry;
pub mod tx_scaler;
pub mod witness_updater;

use helium_lib::keypair::Pubkey;
use rust_decimal::Decimal;
pub use settings::Settings;

pub const IOT_SUB_DAO_ONCHAIN_ADDRESS: &str = "Gm9xDCJawDEKDrrQW6haw94gABaYzQwCq4ZQU8h8bd22";

#[derive(Clone, Debug)]
pub struct PriceInfo {
pub price_in_bones: u64,
Expand All @@ -47,3 +46,7 @@ impl PriceInfo {
}
}
}

pub fn resolve_subdao_pubkey() -> Pubkey {
helium_lib::dao::SubDao::Iot.key()
}
13 changes: 9 additions & 4 deletions iot_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::{
resolve_subdao_pubkey,
reward_share::{self, GatewayShares},
telemetry, PriceInfo, IOT_SUB_DAO_ONCHAIN_ADDRESS,
telemetry, PriceInfo,
};
use chrono::{DateTime, TimeZone, Utc};
use db_store::meta;
use file_store::{file_sink, traits::TimestampEncode};
use futures::future::LocalBoxFuture;
use helium_lib::keypair::Pubkey;
use helium_lib::token::Token;
use helium_proto::{
reward_manifest::RewardData::IotRewardData,
Expand Down Expand Up @@ -33,7 +35,7 @@ use tokio::time::sleep;
const REWARDS_NOT_CURRENT_DELAY_PERIOD: Duration = Duration::from_secs(5 * 60);

pub struct Rewarder<A> {
sub_dao_address: String,
sub_dao: Pubkey,
pub pool: Pool<Postgres>,
pub rewards_sink: file_sink::FileSinkClient<proto::IotRewardShare>,
pub reward_manifests_sink: file_sink::FileSinkClient<RewardManifest>,
Expand Down Expand Up @@ -74,8 +76,11 @@ where
price_tracker: PriceTracker,
sub_dao_epoch_reward_client: A,
) -> anyhow::Result<Self> {
// get the subdao address
let sub_dao = resolve_subdao_pubkey();
tracing::info!("Iot SubDao pubkey: {}", sub_dao);
Ok(Self {
sub_dao_address: IOT_SUB_DAO_ONCHAIN_ADDRESS.to_string(),
sub_dao,
pool,
rewards_sink,
reward_manifests_sink,
Expand Down Expand Up @@ -132,7 +137,7 @@ where
pub async fn reward(&mut self, next_reward_epoch: u64) -> anyhow::Result<()> {
let reward_info = self
.sub_dao_epoch_reward_client
.resolve_info(&self.sub_dao_address, next_reward_epoch)
.resolve_info(&self.sub_dao, next_reward_epoch)
.await?
.ok_or(anyhow::anyhow!(
"No reward info found for epoch {}",
Expand Down

0 comments on commit e9edb2e

Please sign in to comment.