Skip to content

Commit 87c60bc

Browse files
authored
BM-1003: added the with_input_url method to RequestParams in the request builder API (#706)
added `with_input_url` to match the schema of `with_program_url`, now you can use: `client.new_request().with_program_url(program_url)?.with_input_url(input_url)?`
1 parent dd5704b commit 87c60bc

File tree

2 files changed

+58
-1
lines changed
  • crates/boundless-market/src/request_builder
  • examples/counter/apps/src

2 files changed

+58
-1
lines changed

crates/boundless-market/src/request_builder/mod.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,22 @@ impl RequestParams {
422422
Self { request_input: Some(value.into()), ..self }
423423
}
424424

425+
/// Sets the input as a URL from which provers can download the input data.
426+
///
427+
/// This is a convenience method that creates a [RequestInput] with URL type.
428+
///
429+
/// ```rust
430+
/// # use boundless_market::request_builder::RequestParams;
431+
/// # || -> anyhow::Result<()> {
432+
/// RequestParams::new()
433+
/// .with_input_url("https://fileserver.example/input.bin")?;
434+
/// # Ok(())
435+
/// # }().unwrap();
436+
/// ```
437+
pub fn with_input_url<T: TryInto<Url>>(self, value: T) -> Result<Self, T::Error> {
438+
Ok(Self { request_input: Some(RequestInput::url(value.try_into()?)), ..self })
439+
}
440+
425441
/// Gets the cycle count, returning an error if not set.
426442
///
427443
/// The cycle count is used to estimate proving costs.
@@ -934,6 +950,34 @@ mod tests {
934950
RequestParams::new().with_program_url(url).inspect_err(|e| match *e {}).unwrap();
935951
}
936952

953+
#[test]
954+
fn request_params_with_input_url_infallible() {
955+
// When passing a parsed URL, with_input_url should be infallible.
956+
// NOTE: The `match *e {}` incantation is a compile-time assert that this error cannot
957+
// occur.
958+
let url = Url::parse("https://fileserver.example/input.bin").unwrap();
959+
RequestParams::new().with_input_url(url).inspect_err(|e| match *e {}).unwrap();
960+
}
961+
962+
#[test]
963+
fn test_with_input_url() {
964+
// Test with string URL
965+
let params =
966+
RequestParams::new().with_input_url("https://fileserver.example/input.bin").unwrap();
967+
968+
let input = params.request_input.unwrap();
969+
assert_eq!(input.inputType, RequestInputType::Url);
970+
assert_eq!(input.data.as_ref(), "https://fileserver.example/input.bin".as_bytes());
971+
972+
// Test with parsed URL
973+
let url = Url::parse("https://fileserver.example/input2.bin").unwrap();
974+
let params = RequestParams::new().with_input_url(url).unwrap();
975+
976+
let input = params.request_input.unwrap();
977+
assert_eq!(input.inputType, RequestInputType::Url);
978+
assert_eq!(input.data.as_ref(), "https://fileserver.example/input2.bin".as_bytes());
979+
}
980+
937981
#[allow(dead_code)]
938982
trait AssertSend: Send {}
939983

examples/counter/apps/src/main.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ struct Args {
4444
/// Address of the Counter contract.
4545
#[clap(short, long, env)]
4646
counter_address: Address,
47+
/// URL where provers can download the program to be proven.
48+
#[clap(long, env)]
49+
program_url: Option<Url>,
4750
/// Configuration for the StorageProvider to use for uploading programs and inputs.
4851
#[clap(flatten, next_help_heading = "Storage Provider")]
4952
storage_config: StorageProviderConfig,
@@ -81,10 +84,19 @@ async fn run(args: Args) -> Result<()> {
8184
.await
8285
.context("failed to build boundless client")?;
8386

87+
// Use the default ECHO program with timestamp input
8488
// We use a timestamp as input to the ECHO guest code as the Counter contract
8589
// accepts only unique proofs. Using the same input twice would result in the same proof.
8690
let echo_message = format!("{:?}", SystemTime::now());
87-
let request = client.new_request().with_program(ECHO_ELF).with_stdin(echo_message.as_bytes());
91+
92+
// Build the request based on whether program URL is provided
93+
let request = if let Some(program_url) = args.program_url {
94+
// Use the provided URL
95+
client.new_request().with_program_url(program_url)?.with_stdin(echo_message.as_bytes())
96+
} else {
97+
client.new_request().with_program(ECHO_ELF).with_stdin(echo_message.as_bytes())
98+
};
99+
88100
let (request_id, expires_at) = client.submit_onchain(request).await?;
89101

90102
// Wait for the request to be fulfilled. The market will return the journal and seal.
@@ -194,6 +206,7 @@ mod tests {
194206
counter_address,
195207
rpc_url: anvil.endpoint_url(),
196208
private_key: ctx.customer_signer,
209+
program_url: None,
197210
storage_config: StorageProviderConfig::builder()
198211
.storage_provider(StorageProviderType::Mock)
199212
.build()

0 commit comments

Comments
 (0)