Struct Script

Source
pub struct Script(/* private fields */);
Expand description

A Bitcoin-style script for spending or encumbering coins in transparent transactions.

Script represents a serialized Bitcoin script, which is a sequence of operations used to specify conditions for spending Zcash coins in transparent transactions. In ZeWIF, scripts appear in two contexts:

  • script_pubkey in outputs: Defines spending conditions (e.g., P2PKH, P2SH)
  • script_sig in inputs: Contains signatures and data to satisfy spending conditions

Internally, Script is a wrapper around Data, providing a type-safe representation for script handling.

§Zcash Concept Relation

Zcash inherits the Bitcoin script system for its transparent UTXO model. Unlike shielded transactions, which use zero-knowledge proofs, transparent transactions use explicit scripts to validate spending conditions.

Common script patterns in Zcash transparent addresses include:

  • Pay to Public Key Hash (P2PKH): Sends to a standard transparent address
  • Pay to Script Hash (P2SH): Sends to a script hash, enabling more complex conditions

§Data Preservation

The Script type preserves the exact binary representation of transaction scripts from wallet data, ensuring cryptographic integrity during wallet migrations.

§Examples

// Create a script from binary data (this would typically be from a transaction)
let script_bytes = vec![0x76, 0xa9, 0x14, /* more script bytes */];
let script = Script::from(Data::from_vec(script_bytes.clone()));

// Check script properties
assert_eq!(script.len(), script_bytes.len());
assert!(!script.is_empty());

Implementations§

Source§

impl Script

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl AsRef<[u8]> for Script

Allows treating a Script as a byte slice

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Script

Source§

fn clone(&self) -> Script

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Script

Debug formatting that includes script length and hex representation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&Script> for CBOR

Source§

fn from(value: &Script) -> Self

Converts to this type from the input type.
Source§

impl From<Data> for Script

Creates a Script from Data, allowing conversion from variable-length bytes

Source§

fn from(data: Data) -> Self

Converts to this type from the input type.
Source§

impl From<Script> for CBOR

Source§

fn from(value: Script) -> Self

Converts to this type from the input type.
Source§

impl From<Script> for Data

Converts a Script to a Data value, allowing manipulation as variable-length bytes

Source§

fn from(script: Script) -> Self

Converts to this type from the input type.
Source§

impl From<Script> for Envelope

Source§

fn from(value: Script) -> Self

Converts to this type from the input type.
Source§

impl Hash for Script

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<Range<usize>> for Script

Source§

type Output = [u8]

The returned type after indexing.
Source§

fn index(&self, index: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFrom<usize>> for Script

Source§

type Output = [u8]

The returned type after indexing.
Source§

fn index(&self, index: RangeFrom<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeFull> for Script

Source§

type Output = [u8]

The returned type after indexing.
Source§

fn index(&self, index: RangeFull) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeInclusive<usize>> for Script

Source§

type Output = [u8]

The returned type after indexing.
Source§

fn index(&self, index: RangeInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeTo<usize>> for Script

Source§

type Output = [u8]

The returned type after indexing.
Source§

fn index(&self, index: RangeTo<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<RangeToInclusive<usize>> for Script

Source§

type Output = [u8]

The returned type after indexing.
Source§

fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<usize> for Script

Allows accessing individual bytes in the script by index

Source§

type Output = u8

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<Range<usize>> for Script

Source§

fn index_mut(&mut self, index: Range<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeFrom<usize>> for Script

Source§

fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeFull> for Script

Source§

fn index_mut(&mut self, index: RangeFull) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeInclusive<usize>> for Script

Source§

fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeTo<usize>> for Script

Source§

fn index_mut(&mut self, index: RangeTo<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<RangeToInclusive<usize>> for Script

Source§

fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Script

Allows modifying individual bytes in the script by index

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl PartialEq for Script

Source§

fn eq(&self, other: &Script) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<CBOR> for Script

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cbor: CBOR) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Envelope> for Script

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(envelope: Envelope) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Script

Source§

impl StructuralPartialEq for Script

Auto Trait Implementations§

§

impl Freeze for Script

§

impl RefUnwindSafe for Script

§

impl Send for Script

§

impl Sync for Script

§

impl Unpin for Script

§

impl UnwindSafe for Script

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CBORDecodable for T
where T: TryFrom<CBOR, Error = Error>,

Source§

fn try_from_cbor(cbor: &CBOR) -> Result<Self, Error>

Source§

impl<T> CBOREncodable for T
where T: Into<CBOR> + Clone,

Source§

fn to_cbor(&self) -> CBOR

Converts this value to a CBOR object. Read more
Source§

fn to_cbor_data(&self) -> Vec<u8>

Converts this value directly to binary CBOR data. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> EnvelopeEncodable for T
where T: Into<Envelope> + Clone,

Source§

fn into_envelope(self) -> Envelope

Converts the value into an envelope by using its Into<Envelope> implementation.

Source§

fn to_envelope(&self) -> Envelope
where Self: Clone,

Converts a reference to this value into a Gordian Envelope. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToHex for T
where T: AsRef<[u8]>,

Source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
Source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> CBORCodable for T

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T