Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track registration #9

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading