Skip to content

Commit

Permalink
support unallocated rewards in indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Nov 14, 2023
1 parent 87f6ce3 commit 8da38aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions reward_index/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Indexer {
verifier_store: FileStore,
mode: settings::Mode,
op_fund_key: String,
unallocated_reward_key: String,
}

#[derive(sqlx::Type, Debug, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -50,6 +51,12 @@ impl Indexer {
.ok_or_else(|| anyhow!("operation fund key is required for IOT mode"))?,
settings::Mode::Mobile => String::new(),
},
unallocated_reward_key: match settings.mode {
settings::Mode::Mobile => settings
.unallocated_reward_entity_key()
.ok_or_else(|| anyhow!("unallocated reward key is required for MOBILE mode"))?,
settings::Mode::Iot => String::new(),
},
})
}

Expand Down Expand Up @@ -157,6 +164,13 @@ impl Indexer {
},
r.amount,
)),
Some(MobileReward::UnallocatedReward(r)) => Ok((
RewardKey {
key: self.unallocated_reward_key.clone(),
reward_type: RewardType::MobileSubscriber,
},
r.amount,
)),
_ => bail!("got an invalid reward share"),
}
}
Expand Down
5 changes: 5 additions & 0 deletions reward_index/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct Settings {
pub verifier: file_store::Settings,
pub metrics: poc_metrics::Settings,
pub operation_fund_key: Option<String>,
pub unallocated_reward_entity_key: Option<String>,
#[serde(default = "default_start_after")]
pub start_after: u64,
}
Expand Down Expand Up @@ -78,6 +79,10 @@ impl Settings {
pub fn operation_fund_key(&self) -> Option<String> {
self.operation_fund_key.clone()
}

pub fn unallocated_reward_entity_key(&self) -> Option<String> {
self.unallocated_reward_entity_key.clone()
}
}

fn default_interval() -> i64 {
Expand Down

0 comments on commit 8da38aa

Please sign in to comment.