pub struct ScriptPubkey { /* private fields */ }Expand description
A single script pubkey containing spending conditions for a crate::TxOut.
Script pubkeys define the conditions that must be met to spend a transaction output. They are also called “locking scripts” because they lock the output to specific spending conditions.
Script pubkeys can be created from raw script bytes or retrieved from an existing
crate::TxOut.
§Examples
Creating a simple script:
let script_bytes = vec![0x76, 0xa9, 0x14]; // OP_DUP OP_HASH160 OP_PUSHBYTES_20
let script = ScriptPubkey::new(&script_bytes).unwrap();
assert_eq!(script.to_bytes(), script_bytes);Implementations§
Source§impl ScriptPubkey
impl ScriptPubkey
Sourcepub fn new(script_bytes: &[u8]) -> Result<Self, KernelError>
pub fn new(script_bytes: &[u8]) -> Result<Self, KernelError>
Creates a new script pubkey from raw script bytes.
§Arguments
script_bytes- The raw bytes representing the script
§Returns
Ok(ScriptPubkey)- Successfully created script pubkeyErr(KernelError::Internal)- If the script could not be created
§Examples
// Create a P2PKH script
let p2pkh = ScriptPubkey::new(&[
0x76, 0xa9, 0x14, // OP_DUP OP_HASH160 OP_PUSHBYTES_20
// ... pubkey hash bytes ...
0x88, 0xac // OP_EQUALVERIFY OP_CHECKSIG
]).unwrap();Sourcepub fn as_ref(&self) -> ScriptPubkeyRef<'_>
pub fn as_ref(&self) -> ScriptPubkeyRef<'_>
Creates a borrowed reference to this script pubkey.
This allows converting from an owned ScriptPubkey to a ScriptPubkeyRef
without copying the underlying data.
§Lifetime
The returned reference is valid for the lifetime of this ScriptPubkey.
Trait Implementations§
Source§impl Clone for ScriptPubkey
impl Clone for ScriptPubkey
Source§impl Debug for ScriptPubkey
impl Debug for ScriptPubkey
Source§impl Drop for ScriptPubkey
impl Drop for ScriptPubkey
Source§impl From<&ScriptPubkey> for Vec<u8>
impl From<&ScriptPubkey> for Vec<u8>
Source§fn from(script: &ScriptPubkey) -> Self
fn from(script: &ScriptPubkey) -> Self
Converts to this type from the input type.
Source§impl From<ScriptPubkey> for Vec<u8>
impl From<ScriptPubkey> for Vec<u8>
Source§fn from(script: ScriptPubkey) -> Self
fn from(script: ScriptPubkey) -> Self
Converts to this type from the input type.
Source§impl ScriptPubkeyExt for ScriptPubkey
impl ScriptPubkeyExt for ScriptPubkey
Source§impl TryFrom<&[u8]> for ScriptPubkey
impl TryFrom<&[u8]> for ScriptPubkey
impl Send for ScriptPubkey
impl Sync for ScriptPubkey
Auto Trait Implementations§
impl Freeze for ScriptPubkey
impl RefUnwindSafe for ScriptPubkey
impl Unpin for ScriptPubkey
impl UnwindSafe for ScriptPubkey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more