pub struct PushDrop {
pub fields: Vec<Vec<u8>>,
pub private_key: Option<PrivateKey>,
pub sighash_type: u32,
}Expand description
PushDrop script template for embedding data with spending control.
Creates a locking script that pushes data fields onto the stack, drops them with OP_DROP operations, then verifies a signature against a public key (OP_CHECKSIG).
Fields§
§fields: Vec<Vec<u8>>Data fields to embed in the script.
private_key: Option<PrivateKey>Private key for signing (used for both lock pubkey and unlock signature).
sighash_type: u32Sighash scope for signing (default: SIGHASH_ALL | SIGHASH_FORKID).
Implementations§
Source§impl PushDrop
impl PushDrop
Sourcepub fn new(fields: Vec<Vec<u8>>, key: PrivateKey) -> Self
pub fn new(fields: Vec<Vec<u8>>, key: PrivateKey) -> Self
Create a PushDrop template with data fields and a key for locking and unlocking.
The private key’s public key will be used in the locking script, and the private key will be used for signing in the unlocking script.
Sourcepub fn lock_only(fields: Vec<Vec<u8>>) -> Self
pub fn lock_only(fields: Vec<Vec<u8>>) -> Self
Create a PushDrop template for locking only (no signing capability).
Requires knowing the public key bytes to embed in the script.
Use new() instead if you also need unlock capability.
Sourcepub fn unlock(&self, preimage: &[u8]) -> Result<UnlockingScript, ScriptError>
pub fn unlock(&self, preimage: &[u8]) -> Result<UnlockingScript, ScriptError>
Create an unlocking script from a sighash preimage.
Produces: <signature_DER + sighash_byte>
Sourcepub fn estimate_unlock_length(&self) -> usize
pub fn estimate_unlock_length(&self) -> usize
Estimate the byte length of the unlocking script.
PushDrop unlock is just a signature: approximately 74 bytes (1 push opcode + up to 72 DER sig bytes + 1 sighash byte).
Sourcepub fn decode(script: &LockingScript) -> Result<PushDrop, ScriptError>
pub fn decode(script: &LockingScript) -> Result<PushDrop, ScriptError>
Decode a PushDrop locking script, recovering the embedded data fields.
Parses the script pattern:
<field_1> <field_2> ... <field_N> OP_DROP|OP_2DROP... <pubkey> OP_CHECKSIG
Returns a PushDrop with the extracted fields, no private key, and default sighash.
Trait Implementations§
Source§impl ScriptTemplateLock for PushDrop
impl ScriptTemplateLock for PushDrop
Source§fn lock(&self) -> Result<LockingScript, ScriptError>
fn lock(&self) -> Result<LockingScript, ScriptError>
Create a PushDrop locking script.
Structure: <field_1> <field_2> ... <field_N> OP_DROP|OP_2DROP... <pubkey> OP_CHECKSIG
Each field is pushed as data, then removed with OP_DROP (or OP_2DROP for pairs). The final element on stack will be verified against the embedded public key via OP_CHECKSIG.