Skip to content

Commit

Permalink
use string keys
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Apr 20, 2023
1 parent 180b0f4 commit 75619df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
20 changes: 11 additions & 9 deletions reward_index/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use file_store::{
file_info_poller::FileInfoStream, reward_manifest::RewardManifest, FileInfo, FileStore,
};
use futures::{stream, StreamExt, TryStreamExt};
use helium_crypto::PublicKeyBinary;
use helium_proto::{
services::poc_lora::{iot_reward_share::Reward as IotReward, IotRewardShare},
services::poc_mobile::{mobile_reward_share::Reward as MobileReward, MobileRewardShare},
Expand All @@ -18,7 +19,7 @@ pub struct Indexer {
pool: Pool<Postgres>,
verifier_store: FileStore,
mode: settings::Mode,
op_fund_key: Vec<u8>,
op_fund_key: String,
}

#[derive(sqlx::Type, Debug, Clone, PartialEq, Eq, Hash)]
Expand All @@ -31,7 +32,7 @@ pub enum RewardType {

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RewardKey {
key: Vec<u8>,
key: String,
reward_type: RewardType,
}

Expand All @@ -45,7 +46,7 @@ impl Indexer {
settings::Mode::Iot => settings
.operation_fund_key()
.ok_or_else(|| anyhow!("operation fund key is required for IOT mode"))?,
settings::Mode::Mobile => vec![],
settings::Mode::Mobile => String::new(),
},
})
}
Expand All @@ -64,7 +65,8 @@ impl Indexer {
return Ok(());
}
msg = receiver.recv() => if let Some(file_info_stream) = msg {
tracing::info!("Processing reward file {}", file_info_stream.file_info.key);
let key = file_info_stream.file_info.key.clone();
tracing::info!("Processing reward file {}", key);
let mut txn = self.pool.begin().await?;
let mut stream = file_info_stream.into_stream(&mut txn).await?;

Expand All @@ -74,8 +76,8 @@ impl Indexer {
self.handle_rewards(&mut txn, reward_manifest).await?
)
}

txn.commit().await?;
tracing::info!("Completed processing reward file {}", key);
}
}
}
Expand Down Expand Up @@ -107,7 +109,7 @@ impl Indexer {
for (reward_key, amount) in hotspot_rewards {
reward_index::insert(
&mut *txn,
&reward_key.key,
reward_key.key,
amount,
reward_key.reward_type,
&manifest_time,
Expand All @@ -125,7 +127,7 @@ impl Indexer {
match share.reward {
Some(MobileReward::RadioReward(r)) => Ok((
RewardKey {
key: r.hotspot_key,
key: PublicKeyBinary::from(r.hotspot_key).to_string(),
reward_type: RewardType::MobileGateway,
},
r.dc_transfer_reward + r.poc_reward,
Expand All @@ -138,14 +140,14 @@ impl Indexer {
match share.reward {
Some(IotReward::GatewayReward(r)) => Ok((
RewardKey {
key: r.hotspot_key,
key: PublicKeyBinary::from(r.hotspot_key).to_string(),
reward_type: RewardType::IotGateway,
},
r.witness_amount + r.beacon_amount + r.dc_transfer_amount,
)),
Some(IotReward::OperationalReward(r)) => Ok((
RewardKey {
key: self.op_fund_key.clone().to_vec(),
key: self.op_fund_key.clone(),
reward_type: RewardType::IotOperational,
},
r.amount,
Expand Down
2 changes: 1 addition & 1 deletion reward_index/src/reward_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use chrono::{DateTime, Utc};

pub async fn insert<'c, E>(
executor: E,
address: &Vec<u8>,
address: String,
amount: u64,
reward_type: RewardType,
timestamp: &DateTime<Utc>,
Expand Down
6 changes: 2 additions & 4 deletions reward_index/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ impl Settings {
Duration::seconds(self.interval)
}

pub fn operation_fund_key(&self) -> Option<Vec<u8>> {
self.operation_fund_key
.clone()
.map(|string| string.into_bytes())
pub fn operation_fund_key(&self) -> Option<String> {
self.operation_fund_key.clone()
}
}

Expand Down

0 comments on commit 75619df

Please sign in to comment.