Skip to main content

PushDrop

Struct PushDrop 

Source
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 W

The 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>

Source

pub fn new(wallet: &'a W, originator: Option<String>) -> Self

Construct a PushDrop template bound to wallet.

Source

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), a createSignature over 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]).
Source

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.)

Source

pub fn default_sighash_type() -> u8

The default sighash scope: SIGHASH_ALL | SIGHASH_FORKID.

Source

pub fn estimate_unlock_length() -> usize

Estimate the byte length of the unlocking script (TS/Go both answer 73).

Auto Trait Implementations§

§

impl<'a, W> Freeze for PushDrop<'a, W>
where W: ?Sized,

§

impl<'a, W> RefUnwindSafe for PushDrop<'a, W>
where W: RefUnwindSafe + ?Sized,

§

impl<'a, W> Send for PushDrop<'a, W>
where W: ?Sized,

§

impl<'a, W> Sync for PushDrop<'a, W>
where W: ?Sized,

§

impl<'a, W> Unpin for PushDrop<'a, W>
where W: ?Sized,

§

impl<'a, W> UnsafeUnpin for PushDrop<'a, W>
where W: ?Sized,

§

impl<'a, W> UnwindSafe for PushDrop<'a, W>
where W: RefUnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.