//! Serialized script, used inside transaction inputs and outputs. use bytes::Bytes; use std::{fmt, ops}; use zebra_keys::{self, AddressHash, Public}; use {Error, Opcode}; /// Maximum number of bytes pushable to the stack pub const MAX_SCRIPT_ELEMENT_SIZE: usize = 520; /// Maximum number of non-push operations per script pub const MAX_OPS_PER_SCRIPT: u32 = 201; /// Maximum number of public keys per multisig pub const MAX_PUBKEYS_PER_MULTISIG: usize = 20; /// Maximum script length in bytes pub const MAX_SCRIPT_SIZE: usize = 10000; /// Classified script type #[derive(PartialEq, Debug)] pub enum ScriptType { NonStandard, PubKey, PubKeyHash, ScriptHash, Multisig, NullData, } /// Address from Script #[derive(PartialEq, Debug)] pub struct ScriptAddress { /// The type of the address. pub kind: zebra_keys::Type, /// Public key hash. pub hash: AddressHash, } impl ScriptAddress { /// Creates P2PKH-type ScriptAddress pub fn new_p2pkh(hash: AddressHash) -> Self { ScriptAddress { kind: zebra_keys::Type::P2PKH, hash: hash, } } /// Creates P2SH-type ScriptAddress pub fn new_p2sh(hash: AddressHash) -> Self { ScriptAddress { kind: zebra_keys::Type::P2SH, hash: hash, } } } /// Serialized script, used inside transaction inputs and outputs. #[derive(PartialEq, Debug)] pub struct Script { data: Bytes, } impl From<&'static str> for Script { fn from(s: &'static str) -> Self { Script::new(s.into()) } } impl From for Script { fn from(s: Bytes) -> Self { Script::new(s) } } impl From> for Script { fn from(v: Vec) -> Self { Script::new(v.into()) } } impl From