1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! # BSV Script
//!
//! Bitcoin Script construction, parsing, execution, validation, and templates.
//!
//! This module provides:
//! - Opcode constants (`op` module)
//! - Script chunks (`ScriptChunk`)
//! - Script parsing and serialization (`Script`)
//! - Locking and unlocking script types (`LockingScript`, `UnlockingScript`)
//! - Script number encoding (`script_num` module)
//! - Script evaluation errors (`evaluation_error` module)
//! - Spend validation (`Spend`)
//! - Script templates (`template` module, `templates` module)
//!
//! # Example: Building Scripts
//!
//! ```rust
//! use bsv_rs::script::{Script, LockingScript, op};
//!
//! // Create a P2PKH locking script from ASM
//! let script = Script::from_asm("OP_DUP OP_HASH160 0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG").unwrap();
//!
//! // Build a script programmatically
//! let mut script = Script::new();
//! script
//! .write_opcode(op::OP_DUP)
//! .write_opcode(op::OP_HASH160)
//! .write_bin(&[0u8; 20])
//! .write_opcode(op::OP_EQUALVERIFY)
//! .write_opcode(op::OP_CHECKSIG);
//!
//! // Serialize to hex
//! let hex = script.to_hex();
//!
//! // Convert to a locking script
//! let locking = LockingScript::from_script(script);
//! assert!(locking.is_locking_script());
//! ```
//!
//! # Example: Using Templates
//!
//! ```rust,ignore
//! use bsv_rs::script::templates::P2PKH;
//! use bsv_rs::script::template::{ScriptTemplate, SignOutputs};
//! use bsv_rs::primitives::ec::PrivateKey;
//!
//! let private_key = PrivateKey::random();
//! let pubkey_hash = private_key.public_key().hash160();
//!
//! // Create locking script
//! let template = P2PKH::new();
//! let locking = template.lock(&pubkey_hash)?;
//!
//! // Or from an address
//! let locking = P2PKH::lock_from_address("1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2")?;
//! ```
// Re-exports for convenience
pub use Address;
pub use *;
pub use ScriptChunk;
pub use ;
pub use LockingScript;
pub use Script;
pub use ScriptNum;
pub use ;
pub use ;
pub use ;
pub use UnlockingScript;