diff --git a/routes/config.toml b/routes/config.toml index 720f848..aa10aa0 100644 --- a/routes/config.toml +++ b/routes/config.toml @@ -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 + diff --git a/routes/src/register.rs b/routes/src/register.rs index 3de02fc..60456dd 100644 --- a/routes/src/register.rs +++ b/routes/src/register.rs @@ -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}; @@ -40,7 +42,8 @@ pub struct RegistrationData { /// Register a parachain for resource utilization tracking. #[post("/register_para", data = "")] pub async fn register_para(registration_data: Json) -> Result<(), Error> { - let (relay_chain, para_id) = registration_data.para.clone(); + + log::info!( target: LOG_TARGET, diff --git a/routes/tests/mock.rs b/routes/tests/mock.rs index dbf8373..c904c9b 100644 --- a/routes/tests/mock.rs +++ b/routes/tests/mock.rs @@ -96,3 +96,4 @@ pub fn mock_consumption() -> HashMap> { ], } } + diff --git a/routes/tests/register.rs b/routes/tests/register.rs index 2e7ce0d..5f08cfb 100644 --- a/routes/tests/register.rs +++ b/routes/tests/register.rs @@ -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. diff --git a/shared/src/config.rs b/shared/src/config.rs index 6ad6bce..23220e4 100644 --- a/shared/src/config.rs +++ b/shared/src/config.rs @@ -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, } diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 9983bdb..2ef4865 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -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"); diff --git a/types/src/lib.rs b/types/src/lib.rs index 2dc6cee..09e204f 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -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, }