Skip to content

Commit

Permalink
discard request
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay111meher committed Nov 8, 2024
1 parent b3f1069 commit 75fec4c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
37 changes: 37 additions & 0 deletions kalypso-cli/src/common_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,40 @@ impl CommonDeps {
})
}
}

pub struct DiscardRequestInfo {
#[allow(unused)]
pub private_key_signer: LocalWallet,
pub proof_marketplace: bindings::proof_marketplace::ProofMarketplace<
SignerMiddleware<Provider<Http>, LocalWallet>,
>,
pub ask_id: U256,
}

impl CommonDeps {
pub fn discard_request_info(
config: &std::collections::HashMap<String, String>,
) -> Result<DiscardRequestInfo, String> {
get_config_ref!(config, "private_key", private_key);
get_config_ref!(config, "rpc_url", rpc_url);
get_config_ref!(config, "proof_marketplace", proof_marketplace_address);
get_config_ref!(config, "chain_id", chain_id);
get_config_ref!(config, "ask_id", ask_id);

let (proof_marketplace, private_key_signer) = get_proof_marketplace_instance(
private_key,
chain_id,
proof_marketplace_address,
rpc_url,
)?;

let ask_id =
U256::from_dec_str(&ask_id.as_str()).map_err(|e| format!("Invalid Ask Id: {}", e))?;

Ok(DiscardRequestInfo {
private_key_signer,
proof_marketplace,
ask_id,
})
}
}
17 changes: 17 additions & 0 deletions kalypso-cli/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
"prompt": "Enter inputs in hex string",
"secret": false,
"env_var": "INPUTS"
},
{
"field": "ask_id",
"prompt": "Enter Ask ID/ Request ID",
"secret": false,
"env_var": "ASK_ID"
}
],
"operations": [
Expand Down Expand Up @@ -257,6 +263,17 @@
"max_proof_generation_time",
"inputs"
]
},
{
"name": "Discard Request",
"description": "Discard your own request using Request ID",
"required_prompts": [
"private_key",
"rpc_url",
"chain_id",
"proof_marketplace",
"ask_id"
]
}
]
}
2 changes: 2 additions & 0 deletions kalypso-cli/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod create_marketplace;
pub mod create_request;
pub mod join_marketplace;
pub mod leave_or_request_leave_marketplace;
pub mod request;
pub mod stake;

// ... Add other operation modules here
Expand Down Expand Up @@ -59,6 +60,7 @@ pub fn get_operation(name: &str) -> Option<Box<dyn Operation>> {
"Create Proof Request (non confidential market)" => {
Some(Box::new(create_request::NonConfidentialRequest))
}
"Discard Request" => Some(Box::new(request::DiscardRequest)),
_ => unimplemented!(),
}
}
29 changes: 29 additions & 0 deletions kalypso-cli/src/operations/request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::collections::HashMap;

use async_trait::async_trait;

use crate::common_deps::CommonDeps;

use super::Operation;

pub struct DiscardRequest;

#[async_trait]
impl Operation for DiscardRequest {
async fn execute(&self, config: HashMap<String, String>) -> Result<(), String> {
let discard_request_info = CommonDeps::discard_request_info(&config)?;

let tx_hash = CommonDeps::send_and_confirm(
discard_request_info
.proof_marketplace
.discard_request(discard_request_info.ask_id)
.send(),
)
.await?;

// Print the transaction hash
println!("{}", tx_hash);

Ok(())
}
}
1 change: 1 addition & 0 deletions kalypso-cli/src/prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl<'a> Prompter<'a> {
validators.insert("max_proof_generation_cost".to_string(), validate_dec_str_id);
validators.insert("inputs".to_string(), validate_inputs);
validators.insert("max_proof_generation_time".to_string(), validate_dec_str_id);
validators.insert("ask_id".to_string(), validate_dec_str_id);

validators.insert(
"confirmation".to_string(),
Expand Down

0 comments on commit 75fec4c

Please sign in to comment.