From 47d72cbc127fe58f0f852544cda34bdec6d84cf4 Mon Sep 17 00:00:00 2001 From: Brian Balser Date: Wed, 30 Oct 2024 12:52:30 -0400 Subject: [PATCH] fix promotion rewards by encoding timestamp as seconds (#884) * fix promotion rewards by encoding timestamp as seconds * Update reward_index to store promotion reward in db --- .../src/client/carrier_service_client.rs | 2 +- .../11_add_mobile_promotion_reward_type.sql | 1 + reward_index/src/indexer.rs | 30 +++++-------------- 3 files changed, 10 insertions(+), 23 deletions(-) create mode 100644 reward_index/migrations/11_add_mobile_promotion_reward_type.sql diff --git a/mobile_config/src/client/carrier_service_client.rs b/mobile_config/src/client/carrier_service_client.rs index 69e9be28c..bce2b7e30 100644 --- a/mobile_config/src/client/carrier_service_client.rs +++ b/mobile_config/src/client/carrier_service_client.rs @@ -71,7 +71,7 @@ impl CarrierServiceVerifier for CarrierServiceClient { &self, ) -> Result, Self::Error> { let mut request = mobile_config::CarrierIncentivePromotionListReqV1 { - timestamp: Utc::now().encode_timestamp_millis(), + timestamp: Utc::now().encode_timestamp(), signer: self.signing_key.public_key().into(), signature: vec![], }; diff --git a/reward_index/migrations/11_add_mobile_promotion_reward_type.sql b/reward_index/migrations/11_add_mobile_promotion_reward_type.sql new file mode 100644 index 000000000..c728749de --- /dev/null +++ b/reward_index/migrations/11_add_mobile_promotion_reward_type.sql @@ -0,0 +1 @@ +ALTER TYPE reward_type ADD VALUE 'mobile_promotion'; diff --git a/reward_index/src/indexer.rs b/reward_index/src/indexer.rs index b70e30505..bc6c345a1 100644 --- a/reward_index/src/indexer.rs +++ b/reward_index/src/indexer.rs @@ -36,6 +36,7 @@ pub enum RewardType { MobileServiceProvider, MobileUnallocated, IotUnallocated, + MobilePromotion, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -185,28 +186,13 @@ impl Indexer { }, r.amount, ))), - // Some(MobileReward::PromotionReward(PromotionReward { - // entity: Some(Entity::SubscriberId(subscriber_id)), - // service_provider_amount, - // matched_amount, - // })) => Ok(Some(( - // RewardKey { - // key: bs58::encode(&subscriber_id).into_string(), - // reward_type: RewardType::MobileSubscriber, - // }, - // service_provider_amount + matched_amount, - // ))), - // Some(MobileReward::PromotionReward(PromotionReward { - // entity: Some(Entity::GatewayKey(gateway_key)), - // service_provider_amount, - // matched_amount, - // })) => Ok(Some(( - // RewardKey { - // key: PublicKeyBinary::from(gateway_key).to_string(), - // reward_type: RewardType::MobileGateway, - // }, - // service_provider_amount + matched_amount, - // ))), + Some(MobileReward::PromotionReward(promotion)) => Ok(Some(( + RewardKey { + key: promotion.entity, + reward_type: RewardType::MobilePromotion, + }, + promotion.service_provider_amount + promotion.matched_amount, + ))), _ => bail!("got an invalid reward share"), } }