Skip to content

Commit

Permalink
Update Indexer to handle MobileRewardShare
Browse files Browse the repository at this point in the history
  • Loading branch information
bbalser authored and jeffgrunewald committed Apr 12, 2023
1 parent 52c5b9a commit 8e97e44
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions reward_index/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use file_store::{
file_info_poller::FileInfoStream, reward_manifest::RewardManifest, FileInfo, FileStore,
};
use futures::{stream, StreamExt, TryStreamExt};
use helium_proto::services::poc_lora::iot_reward_share::Reward as ProtoReward;
use helium_proto::{
services::poc_lora::IotRewardShare, services::poc_mobile::RadioRewardShare, Message,
services::poc_lora::{iot_reward_share::Reward as IotReward, IotRewardShare},
services::poc_mobile::{mobile_reward_share::Reward as MobileReward, MobileRewardShare},
Message,
};
use poc_metrics::record_duration;
use sqlx::{Pool, Postgres, Transaction};
Expand Down Expand Up @@ -120,17 +121,22 @@ impl Indexer {
fn extract_reward_share(&self, msg: &[u8]) -> Result<(RewardKey, u64)> {
match self.mode {
settings::Mode::Mobile => {
let share = RadioRewardShare::decode(msg)?;
let key = RewardKey {
key: share.hotspot_key,
reward_type: RewardType::MobileGateway,
};
Ok((key, share.amount))
let share = MobileRewardShare::decode(msg)?;
match share.reward {
Some(MobileReward::RadioReward(r)) => Ok((
RewardKey {
key: r.hotspot_key,
reward_type: RewardType::MobileGateway,
},
r.dc_transfer_reward + r.poc_reward,
)),
_ => bail!("got an invalid mobile reward share"),
}
}
settings::Mode::Iot => {
let share = IotRewardShare::decode(msg)?;
match share.reward {
Some(ProtoReward::GatewayReward(r)) => {
Some(IotReward::GatewayReward(r)) => {
let key = RewardKey {
key: r.hotspot_key,
reward_type: RewardType::IotGateway,
Expand All @@ -140,7 +146,7 @@ impl Indexer {
r.witness_amount + r.beacon_amount + r.dc_transfer_amount,
))
}
Some(ProtoReward::OperationalReward(r)) => {
Some(IotReward::OperationalReward(r)) => {
let key = RewardKey {
key: self.op_fund_key.clone().to_vec(),
reward_type: RewardType::IotOperational,
Expand Down

0 comments on commit 8e97e44

Please sign in to comment.