pub struct CoreScript(/* private fields */);Implementations§
Source§impl CoreScript
impl CoreScript
pub fn new(script: DashcoreScript) -> Self
pub fn to_string(&self, encoding: Encoding) -> String
pub fn from_string( encoded_value: &str, encoding: Encoding, ) -> Result<Self, ProtocolError>
pub fn from_bytes(bytes: Vec<u8>) -> Self
pub fn new_p2pkh(key_hash: [u8; 20]) -> Self
pub fn new_p2sh(script_hash: [u8; 20]) -> Self
pub fn random_p2sh(rng: &mut StdRng) -> Self
pub fn random_p2pkh(rng: &mut StdRng) -> Self
Methods from Deref<Target = DashcoreScript>§
pub fn as_script(&self) -> &Script
pub fn as_script(&self) -> &Script
Returns a reference to unsized script.
pub fn to_p2sh(&self) -> ScriptBuf
pub fn to_p2sh(&self) -> ScriptBuf
Computes the P2SH output corresponding to this redeem script.
pub fn p2wpkh_script_code(&self) -> Option<ScriptBuf>
pub fn p2wpkh_script_code(&self) -> Option<ScriptBuf>
Returns the script code used for spending a P2WPKH output if this script is a script pubkey
for a P2WPKH output. The scriptCode is described in BIP143.
Methods from Deref<Target = Script>§
pub fn as_mut_bytes(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_bytes(&mut self) -> &mut [u8] ⓘ
Returns the script data as a mutable byte slice.
pub fn script_hash(&self) -> ScriptHash
pub fn script_hash(&self) -> ScriptHash
Returns 160-bit hash of the script.
pub fn wscript_hash(&self) -> WScriptHash
pub fn wscript_hash(&self) -> WScriptHash
Returns 256-bit hash of the script for P2WSH outputs.
pub fn tapscript_leaf_hash(&self) -> TapLeafHash
pub fn tapscript_leaf_hash(&self) -> TapLeafHash
Computes leaf hash of tapscript.
pub fn bytes(&self) -> Bytes<'_>
pub fn bytes(&self) -> Bytes<'_>
Returns an iterator over script bytes.
pub fn to_v0_p2wsh(&self) -> ScriptBuf
pub fn to_v0_p2wsh(&self) -> ScriptBuf
Computes the P2WSH output corresponding to this witnessScript (aka the “witness redeem script”).
pub fn to_v1_p2tr<C>(
&self,
secp: &Secp256k1<C>,
internal_key: XOnlyPublicKey,
) -> ScriptBufwhere
C: Verification,
pub fn to_v1_p2tr<C>(
&self,
secp: &Secp256k1<C>,
internal_key: XOnlyPublicKey,
) -> ScriptBufwhere
C: Verification,
Computes P2TR output with a given internal key and a single script spending path equal to the current script, assuming that the script is a Tapscript.
pub fn witness_version(&self) -> Option<WitnessVersion>
pub fn witness_version(&self) -> Option<WitnessVersion>
Returns witness version of the script, if any, assuming the script is a scriptPubkey.
pub fn is_p2pk(&self) -> bool
pub fn is_p2pk(&self) -> bool
Checks whether a script pubkey is a P2PK output.
You can obtain the public key, if its valid,
by calling p2pk_public_key()
pub fn p2pkh_public_key_hash_bytes(&self) -> Option<&[u8]>
pub fn p2pkh_public_key_hash_bytes(&self) -> Option<&[u8]>
Returns the public key hash if this script is P2PKH.
pub fn p2pk_public_key(&self) -> Option<PublicKey>
pub fn p2pk_public_key(&self) -> Option<PublicKey>
Returns the public key if this script is P2PK with a valid public key.
This may return None even when is_p2pk() returns true.
This happens when the public key is invalid (e.g. the point not being on the curve).
It also implies the script is unspendable.
pub fn p2pk_pubkey_bytes(&self) -> Option<&[u8]>
pub fn p2pk_pubkey_bytes(&self) -> Option<&[u8]>
Returns the bytes of the (possibly invalid) public key if this script is P2PK.
pub fn is_witness_program(&self) -> bool
pub fn is_witness_program(&self) -> bool
Checks whether a script pubkey is a Segregated Witness (segwit) program.
pub fn is_v0_p2wsh(&self) -> bool
pub fn is_v0_p2wsh(&self) -> bool
Checks whether a script pubkey is a P2WSH output.
pub fn is_v0_p2wpkh(&self) -> bool
pub fn is_v0_p2wpkh(&self) -> bool
Checks whether a script pubkey is a P2WPKH output.
pub fn v0_p2wpkh(&self) -> Option<&[u8; 20]>
pub fn v0_p2wpkh(&self) -> Option<&[u8; 20]>
Returns P2WPKH byte slice if this script is P2WPKH, otherwise None.
pub fn is_v1_p2tr(&self) -> bool
pub fn is_v1_p2tr(&self) -> bool
Checks whether a script pubkey is a P2TR output.
pub fn is_op_return(&self) -> bool
pub fn is_op_return(&self) -> bool
Check if this is an OP_RETURN output.
pub fn is_provably_unspendable(&self) -> bool
pub fn is_provably_unspendable(&self) -> bool
Checks whether a script can be proven to have no satisfying input.
pub fn dust_value(&self) -> Amount
pub fn dust_value(&self) -> Amount
Returns the minimum value an output with this script should have in order to be broadcastable on today’s Bitcoin network.
pub fn instructions(&self) -> Instructions<'_>
pub fn instructions(&self) -> Instructions<'_>
Iterates over the script instructions.
Each returned item is a nested enum covering opcodes, datapushes and errors.
At most one error will be returned and then the iterator will end. To instead iterate over
the script as sequence of bytes call the bytes method.
To force minimal pushes, use instructions_minimal.
pub fn instructions_minimal(&self) -> Instructions<'_>
pub fn instructions_minimal(&self) -> Instructions<'_>
Iterates over the script instructions while enforcing minimal pushes.
This is similar to instructions but an error is returned if a push
is not minimal.
pub fn instruction_indices(&self) -> InstructionIndices<'_>
pub fn instruction_indices(&self) -> InstructionIndices<'_>
Iterates over the script instructions and their indices.
Unless the script contains an error, the returned item consists of an index pointing to the position in the script where the instruction begins and the decoded instruction - either an opcode or data push.
To force minimal pushes, use [Self::instruction_indices_minimal].
pub fn instruction_indices_minimal(&self) -> InstructionIndices<'_>
pub fn instruction_indices_minimal(&self) -> InstructionIndices<'_>
Iterates over the script instructions and their indices while enforcing minimal pushes.
This is similar to instruction_indices but an error is
returned if a push is not minimal.
pub fn fmt_asm(&self, f: &mut dyn Write) -> Result<(), Error>
pub fn fmt_asm(&self, f: &mut dyn Write) -> Result<(), Error>
Writes the assembly decoding of the script to the formatter.
pub fn to_asm_string(&self) -> String
pub fn to_asm_string(&self) -> String
Returns the assembly decoding of the script.
pub fn to_hex_string(&self) -> String
pub fn to_hex_string(&self) -> String
Formats the script as lower-case hex.
This is a more convenient and performant way to write format!("{:x}", script).
For better performance you should generally prefer displaying the script but if String is
required (this is common in tests) this method is can be used.
pub fn first_opcode(&self) -> Option<All>
pub fn first_opcode(&self) -> Option<All>
Returns the first opcode of the script (if there is any).
pub fn last_opcode(&self) -> Option<All>
pub fn last_opcode(&self) -> Option<All>
Iterates the script to find the last opcode.
Returns None is the instruction is data push or if the script is empty.
Trait Implementations§
Source§impl<'de, C> BorrowDecode<'de, C> for CoreScript
impl<'de, C> BorrowDecode<'de, C> for CoreScript
Source§fn borrow_decode<D: BorrowDecoder<'de, Context = C>>(
decoder: &mut D,
) -> Result<Self, DecodeError>
fn borrow_decode<D: BorrowDecoder<'de, Context = C>>( decoder: &mut D, ) -> Result<Self, DecodeError>
Source§impl Clone for CoreScript
impl Clone for CoreScript
Source§fn clone(&self) -> CoreScript
fn clone(&self) -> CoreScript
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CoreScript
impl Debug for CoreScript
Source§impl<C> Decode<C> for CoreScript
impl<C> Decode<C> for CoreScript
Source§impl Default for CoreScript
impl Default for CoreScript
Source§fn default() -> CoreScript
fn default() -> CoreScript
Source§impl Deref for CoreScript
impl Deref for CoreScript
Source§impl<'de> Deserialize<'de> for CoreScript
impl<'de> Deserialize<'de> for CoreScript
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for CoreScript
impl Display for CoreScript
Source§impl Encode for CoreScript
impl Encode for CoreScript
Source§impl PartialEq for CoreScript
impl PartialEq for CoreScript
Source§impl Serialize for CoreScript
impl Serialize for CoreScript
impl Eq for CoreScript
impl JsonSafeFields for CoreScript
impl StructuralPartialEq for CoreScript
Auto Trait Implementations§
impl Freeze for CoreScript
impl RefUnwindSafe for CoreScript
impl Send for CoreScript
impl Sync for CoreScript
impl Unpin for CoreScript
impl UnwindSafe for CoreScript
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> CostsExt for T
impl<T> CostsExt for T
§fn wrap_with_cost(self, cost: OperationCost) -> CostContext<Self>where
Self: Sized,
fn wrap_with_cost(self, cost: OperationCost) -> CostContext<Self>where
Self: Sized,
CostContext object with provided costs.§fn wrap_fn_cost(
self,
f: impl FnOnce(&Self) -> OperationCost,
) -> CostContext<Self>where
Self: Sized,
fn wrap_fn_cost(
self,
f: impl FnOnce(&Self) -> OperationCost,
) -> CostContext<Self>where
Self: Sized,
CostContext object with costs computed using the
value getting wrapped.§impl<'de, T> DefaultBorrowDecode<'de> for Twhere
T: BorrowDecode<'de, ()>,
impl<'de, T> DefaultBorrowDecode<'de> for Twhere
T: BorrowDecode<'de, ()>,
fn borrow_decode<D>(decoder: &mut D) -> Result<Self, DecodeError>
§impl<T> DefaultDecode for T
impl<T> DefaultDecode for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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§impl<T, U> IntoOnNetwork<U> for Twhere
U: FromOnNetwork<T>,
impl<T, U> IntoOnNetwork<U> for Twhere
U: FromOnNetwork<T>,
§fn into_on_network(self, network: Network) -> U
fn into_on_network(self, network: Network) -> U
Calls U::from_on_network(self).
§impl<T, U> IntoPlatformVersioned<U> for Twhere
U: FromPlatformVersioned<T>,
impl<T, U> IntoPlatformVersioned<U> for Twhere
U: FromPlatformVersioned<T>,
§fn into_platform_versioned(self, platform_version: &PlatformVersion) -> U
fn into_platform_versioned(self, platform_version: &PlatformVersion) -> U
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.