pub struct PushDrop<'a, W: WalletInterface + ?Sized> {
pub wallet: &'a W,
pub originator: Option<String>,
}Expand description
PushDrop script template for embedding data with spending control.
Holds a WalletInterface (see the module docs); the locking key is derived
per (protocol_id, key_id, counterparty), never supplied directly.
The wallet is BORROWED. Go stores a wallet.Interface (an interface value,
i.e. a pointer); a borrow is the Rust analogue and keeps the template usable
from a store that owns its wallet (&self.wallet) and from one that holds it
behind an Arc (&*arc) alike, with no clone and no Arc requirement.
Fields§
§wallet: &'a WThe wallet that derives keys and produces signatures.
originator: Option<String>Originator passed through on every wallet request.
Implementations§
Source§impl<'a, W: WalletInterface + ?Sized> PushDrop<'a, W>
impl<'a, W: WalletInterface + ?Sized> PushDrop<'a, W>
Sourcepub fn new(wallet: &'a W, originator: Option<String>) -> Self
pub fn new(wallet: &'a W, originator: Option<String>) -> Self
Construct a PushDrop template bound to wallet.
Sourcepub async fn lock(
&self,
fields: Vec<Vec<u8>>,
protocol_id: Protocol,
key_id: &str,
counterparty: Counterparty,
for_self: bool,
include_signature: bool,
lock_position: LockPosition,
) -> Result<LockingScript, ScriptError>
pub async fn lock( &self, fields: Vec<Vec<u8>>, protocol_id: Protocol, key_id: &str, counterparty: Counterparty, for_self: bool, include_signature: bool, lock_position: LockPosition, ) -> Result<LockingScript, ScriptError>
Create a PushDrop locking script.
Port of TS PushDrop.lock / Go PushDrop.Lock, in that order of authority.
- The locking pubkey is derived:
getPublicKey({protocol_id, key_id, counterparty, for_self}). - When
include_signature(the TS/Go default is true), acreateSignatureover the CONCATENATED fields is appended as an extra field — so it participates in the OP_2DROP/OP_DROP tail count. - Fields are minimally encoded (see [
make_data_push]).
Sourcepub async fn unlock(
&self,
preimage: &[u8],
protocol_id: Protocol,
key_id: &str,
counterparty: Counterparty,
sighash_type: u8,
) -> Result<UnlockingScript, ScriptError>
pub async fn unlock( &self, preimage: &[u8], protocol_id: Protocol, key_id: &str, counterparty: Counterparty, sighash_type: u8, ) -> Result<UnlockingScript, ScriptError>
Produce the unlocking script for a PushDrop output, signing preimage
(the BIP-143/BSV sighash preimage) through the wallet.
Matches TS/Go: the wallet is handed sha256(preimage) as data, and
hashes once more internally — so the signed digest is sha256d(preimage),
the correct BSV sighash. (The previous private-key implementation signed a
SINGLE sha256 of the preimage, which is not a valid BSV sighash.)
Sourcepub fn default_sighash_type() -> u8
pub fn default_sighash_type() -> u8
The default sighash scope: SIGHASH_ALL | SIGHASH_FORKID.
Sourcepub fn estimate_unlock_length() -> usize
pub fn estimate_unlock_length() -> usize
Estimate the byte length of the unlocking script (TS/Go both answer 73).