(
private_key: &PrivateKey,
program: &str,
function: &str,
inputs: Array,
priority_fee_credits: f64,
fee_record: Option<RecordPlaintext>,
url: O
| 382 | #[wasm_bindgen(js_name = buildDevnodeExecutionTransaction)] |
| 383 | #[allow(clippy::too_many_arguments)] |
| 384 | pub async fn devnode_execute( |
| 385 | private_key: &PrivateKey, |
| 386 | program: &str, |
| 387 | function: &str, |
| 388 | inputs: Array, |
| 389 | priority_fee_credits: f64, |
| 390 | fee_record: Option<RecordPlaintext>, |
| 391 | url: Option<String>, |
| 392 | imports: Option<Object>, |
| 393 | edition: Option<u16>, |
| 394 | program_imports: Option<ProgramImports>, |
| 395 | ) -> Result<Transaction, String> { |
| 396 | log("Loading the SnarkVM process"); |
| 397 | let node_url = url.as_deref().unwrap_or(LOCAL_URL); |
| 398 | let edition = edition.unwrap_or(1); |
| 399 | |
| 400 | let mut resolved = ResolvedProcess::resolve(&program_imports, program, edition, imports)?; |
| 401 | let program_native = resolved.program().clone(); |
| 402 | let process = resolved.process_mut(); |
| 403 | |
| 404 | // Initialize the rng. |
| 405 | let rng = &mut rand::rng(); |
| 406 | let program_id = program_native.id().to_string(); |
| 407 | let inputs = process_inputs!(inputs); |
| 408 | |
| 409 | // Add the program to the process (no-op if ensure_program already added it). |
| 410 | if program_id != "credits.aleo" && !process.contains_program(program_native.id()) { |
| 411 | log("Adding program to the process"); |
| 412 | process.lock().add_program_with_edition(&program_native, edition).map_err(|e| e.to_string())?; |
| 413 | } |
| 414 | |
| 415 | // Generate the authorization. |
| 416 | let authorization = process |
| 417 | .authorize::<CurrentAleo, _>(&private_key, &program_id, function, inputs.iter(), rng) |
| 418 | .map_err(|e| e.to_string())?; |
| 419 | |
| 420 | // Get the state root. |
| 421 | let state_root = latest_stateroot(node_url).await.map_err(|e| e.to_string())?; |
| 422 | |
| 423 | // Get the consensus version. |
| 424 | let latest_height = latest_block_height(node_url).await.map_err(|err| err.to_string())?; |
| 425 | let consensus_version = CurrentNetwork::CONSENSUS_VERSION(latest_height).map_err(|err| err.to_string())?; |
| 426 | |
| 427 | // Execute without proving. |
| 428 | let execution = ExecutionNative::from(authorization.transitions().values().cloned(), state_root, None) |
| 429 | .map_err(|e| e.to_string())?; |
| 430 | |
| 431 | // Calculate the cost. |
| 432 | let (cost, _) = execution_cost(&process, &execution, consensus_version).map_err(|e| e.to_string())?; |
| 433 | |
| 434 | // Generate the fee authorization. |
| 435 | let id = authorization.to_execution_id().map_err(|e| e.to_string())?; |
| 436 | |
| 437 | // Convert the priority fee to microcredits. |
| 438 | let priority_fee_microcredits = (priority_fee_credits * 1_000_000.0) as u64; |
| 439 | |
| 440 | let fee_authorization = match fee_record { |
| 441 | Some(fee_record) => { |
nothing calls this directly
no test coverage detected