2024-12-15 00:55:11 -08:00
|
|
|
use crate::Error;
|
|
|
|
|
|
|
|
#[allow(nonstandard_style)]
|
|
|
|
pub struct ActionSubmissionUploadedRequest{
|
|
|
|
pub SubmissionID:i64,
|
|
|
|
pub TargetAssetID:Option<u64>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct SubmissionID(pub i64);
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Context(crate::context::Context);
|
|
|
|
|
|
|
|
// there are lots of action endpoints and they all follow the same pattern
|
|
|
|
macro_rules! action{
|
|
|
|
($fname:ident,$action:expr)=>{
|
|
|
|
pub async fn $fname(&self,config:SubmissionID)->Result<(),Error>{
|
|
|
|
let url_raw=format!(concat!("{}/submissions/{}/status/",$action),self.0.base_url,config.0);
|
|
|
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::ParseError)?;
|
|
|
|
|
2024-12-14 00:15:05 -08:00
|
|
|
self.0.post_empty_body(url).await.map_err(Error::Reqwest)?
|
2024-12-15 00:55:11 -08:00
|
|
|
.error_for_status().map_err(Error::Reqwest)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
impl Context{
|
|
|
|
pub fn new(base_url:String)->reqwest::Result<Self>{
|
|
|
|
Ok(Self(crate::context::Context::new(base_url)?))
|
|
|
|
}
|
|
|
|
pub async fn action_submission_uploaded(&self,config:ActionSubmissionUploadedRequest)->Result<(),Error>{
|
2024-12-15 01:54:05 -08:00
|
|
|
let url_raw=format!("{}/submissions/{}/status/validator-uploaded",self.0.base_url,config.SubmissionID);
|
2024-12-15 00:55:11 -08:00
|
|
|
let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::ParseError)?;
|
|
|
|
|
|
|
|
if let Some(target_asset_id)=config.TargetAssetID{
|
|
|
|
url.query_pairs_mut()
|
|
|
|
.append_pair("TargetAssetID",target_asset_id.to_string().as_str());
|
|
|
|
}
|
|
|
|
|
2024-12-14 00:15:05 -08:00
|
|
|
self.0.post_empty_body(url).await.map_err(Error::Reqwest)?
|
2024-12-15 00:55:11 -08:00
|
|
|
.error_for_status().map_err(Error::Reqwest)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
action!(action_submission_validated,"validator-validated");
|
|
|
|
action!(action_submission_released,"releaser-released");
|
|
|
|
}
|