Skip to content

Commit

Permalink
Merge pull request #9 from BoredApe8461/track-registration
Browse files Browse the repository at this point in the history
Track registration
  • Loading branch information
BoredApe8461 authored Aug 19, 2024
2 parents 1ba43f0 + a8b7d87 commit 54c3aaf
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions routes/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ receiver = "5DADsnBXr5DXiEAjdJvruf6c7ZSUR8iXUTATQqJfheGLiEVm"
cost = "1000000000" #0.001 ROC
# 2,419,200 is 4 weeks in seconds.
subscription_duration=2419200

# 604800 is 1 week in seconds.
renewal_period=604800

5 changes: 4 additions & 1 deletion routes/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ use crate::*;
use polkadot_core_primitives::BlockNumber;
use rocket::{post, serde::json::Json};
use shared::{

chaindata,
config::config,
current_timestamp,
payment::validate_registration_payment,

registry::{registered_para, registered_paras, update_registry},
};
use types::{ParaId, RelayChain};
Expand All @@ -40,7 +42,8 @@ pub struct RegistrationData {
/// Register a parachain for resource utilization tracking.
#[post("/register_para", data = "<registration_data>")]
pub async fn register_para(registration_data: Json<RegistrationData>) -> Result<(), Error> {
let (relay_chain, para_id) = registration_data.para.clone();



log::info!(
target: LOG_TARGET,
Expand Down
1 change: 1 addition & 0 deletions routes/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@ pub fn mock_consumption() -> HashMap<Parachain, Vec<WeightConsumption>> {
],
}
}

1 change: 1 addition & 0 deletions routes/tests/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fn register_works() {

assert_eq!(response.status(), Status::Ok);


let registered = registered_para(Polkadot, 2000).unwrap();

// Set the `expiry_timestamp` to the proper value.
Expand Down
1 change: 1 addition & 0 deletions shared/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct PaymentInfo {
pub cost: String,
/// This defines the duration that a single subscription payment will cover.
pub subscription_duration: Timestamp,

/// Defines how much before the expiry can the subscription be renewed.
pub renewal_period: Timestamp,
}
Expand Down
1 change: 1 addition & 0 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn current_timestamp() -> Timestamp {
SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs()
}


pub fn init_tracker() {
let output = Command::new("./scripts/init.sh").output().expect("Failed to execute command");

Expand Down
1 change: 1 addition & 0 deletions types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct Parachain {
pub para_id: ParaId,
/// The relay chain that the parachain is using for block validation.
pub relay_chain: RelayChain,

/// The timestamp when the subscription expires.
pub expiry_timestamp: Timestamp,
}
Expand Down

0 comments on commit 54c3aaf

Please sign in to comment.