(script: Vec<u8>, witness: Vec<Vec<u8>>)
| 278 | } |
| 279 | |
| 280 | pub fn execute_raw_script_with_inputs(script: Vec<u8>, witness: Vec<Vec<u8>>) -> ExecuteInfo { |
| 281 | // Get the default options for the script exec. |
| 282 | // Do not enforce the stack limit. |
| 283 | let opts = Options { |
| 284 | enforce_stack_limit: false, |
| 285 | ..Default::default() |
| 286 | }; |
| 287 | |
| 288 | let mut exec = Exec::new( |
| 289 | ExecCtx::Tapscript, |
| 290 | opts, |
| 291 | TxTemplate { |
| 292 | tx: Transaction { |
| 293 | version: bitcoin::transaction::Version::TWO, |
| 294 | lock_time: bitcoin::locktime::absolute::LockTime::ZERO, |
| 295 | input: vec![], |
| 296 | output: vec![], |
| 297 | }, |
| 298 | prevouts: vec![], |
| 299 | input_idx: 0, |
| 300 | taproot_annex_scriptleaf: Some((TapLeafHash::all_zeros(), None)), |
| 301 | }, |
| 302 | ScriptBuf::from_bytes(script), |
| 303 | witness, |
| 304 | ) |
| 305 | .expect("error creating exec"); |
| 306 | |
| 307 | loop { |
| 308 | let temp_res = exec.exec_next(); |
| 309 | match temp_res { |
| 310 | Ok(()) => (), |
| 311 | Err(err) => { |
| 312 | if !err.success { |
| 313 | // println!("temp_res: {:?}", temp_res); |
| 314 | } |
| 315 | break; |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | let res = exec.result().unwrap(); |
| 321 | let execute_info = ExecuteInfo { |
| 322 | success: res.success, |
| 323 | error: res.error.clone(), |
| 324 | last_opcode: res.opcode, |
| 325 | final_stack: FmtStack(exec.stack().clone()), |
| 326 | // alt_stack: FmtStack(exec.altstack().clone()), |
| 327 | remaining_script: exec.remaining_script().to_owned().to_asm_string(), |
| 328 | stats: exec.stats().clone(), |
| 329 | }; |
| 330 | |
| 331 | execute_info |
| 332 | } |
| 333 | |
| 334 | pub fn execute_script_with_inputs(script: treepp::Script, witness: Vec<Vec<u8>>) -> ExecuteInfo { |
| 335 | execute_raw_script_with_inputs(script.compile().to_bytes(), witness) |
no test coverage detected