pub struct Script(/* private fields */);
Implementations§
Source§impl Script
Script Template
impl Script
Script Template
pub fn match_impl( &self, script_template: &ScriptTemplate, ) -> Result<Vec<(MatchDataTypes, Vec<u8>)>, ScriptTemplateErrors>
pub fn test_impl(&self, script_template: &ScriptTemplate) -> bool
Source§impl Script
impl Script
Sourcepub fn matches(
&self,
script_template: &ScriptTemplate,
) -> Result<Vec<(MatchDataTypes, Vec<u8>)>, ScriptTemplateErrors>
pub fn matches( &self, script_template: &ScriptTemplate, ) -> Result<Vec<(MatchDataTypes, Vec<u8>)>, ScriptTemplateErrors>
Matches the Script against the provided ScriptTemplate.
If any data can be gleaned from the Script (ie. OP_DATA, OP_PUBKEY, OP_SIG, etc.), it will return it in a Vec<Match>
§Example
use bsv_wasm::{ Script, MatchDataTypes, ScriptTemplate };
let script = Script::from_asm_string("OP_HASH160 b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc6 OP_EQUALVERIFY OP_DUP OP_HASH160 f9dfc5a4ae5256e5938c2d819738f7b57e4d7b46 OP_EQUALVERIFY OP_CHECKSIG OP_RETURN 21e8").unwrap();
let script_template = ScriptTemplate::from_asm_string("OP_HASH160 OP_DATA=20 OP_EQUALVERIFY OP_DUP OP_HASH160 OP_PUBKEYHASH OP_EQUALVERIFY OP_CHECKSIG OP_RETURN OP_DATA").unwrap();
let match_result = script.matches(&script_template);
let extracted = match_result.unwrap();
assert_eq!(extracted.len(), 3);
match &extracted[0] {
(MatchDataTypes::Data, v) => {
assert_eq!(v.len(), 20, "Data was not 20 bytes long");
assert_eq!(v, &hex::decode("b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc6").unwrap())
}
_ => assert!(false, "Index 0 did not contain Signature"),
}
Sourcepub fn is_match(&self, script_template: &ScriptTemplate) -> bool
pub fn is_match(&self, script_template: &ScriptTemplate) -> bool
Matches the Script against the provided ScriptTemplate.
Returns true
if the Script matches the ScriptTemplate.
Source§impl Script
Native Specific Functions
impl Script
Native Specific Functions
pub fn to_asm_string(&self) -> String
pub fn from_bytes(bytes: &[u8]) -> Result<Script, BSVErrors>
pub fn to_extended_asm_string(&self) -> String
pub fn from_hex(hex: &str) -> Result<Script, BSVErrors>
pub fn from_asm_string(asm_string: &str) -> Result<Script, BSVErrors>
pub fn encode_pushdata(data_bytes: &[u8]) -> Result<Vec<u8>, BSVErrors>
Sourcepub fn get_pushdata_bytes(length: usize) -> Result<Vec<u8>, BSVErrors>
pub fn get_pushdata_bytes(length: usize) -> Result<Vec<u8>, BSVErrors>
Gets the OP_PUSHDATA prefix varint
pub fn to_script_bits(&self) -> Vec<ScriptBit>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Script
impl<'de> Deserialize<'de> for Script
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Script
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> 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