pub struct VelocityApprover<A: Approve> { /* private fields */ }
Expand description
An approver that auto-approves L2 payments under a certain velocity. If the invoice is over the velocity, it is passed on to a delegate approver. You can use this to allow micropayments to arbitrary destinations.
You can also pass in a delegate approver, to allow asking the user for approval for payments over the micropayment maximum velocity.
L1 payments are always passed to the delegate approver (i.e. velocity control is not used for approval).
use lightning_signer::util::clock::ManualClock;
use lightning_signer::util::velocity::{
VelocityControl,
VelocityControlIntervalType::Hourly,
VelocityControlSpec
};
let delegate = NegativeApprover();
let clock = Arc::new(ManualClock::new(Duration::ZERO));
let spec = VelocityControlSpec {
limit_msat: 1000000,
interval_type: Hourly
};
let control = VelocityControl::new(spec);
let approver = VelocityApprover::new(clock.clone(), control, delegate);
let state = approver.control().get_state();
// persist the state here if you don't want the velocity control to be cleared
// every time the signer restarts
// ...
// now restore from the state
let restored_control = VelocityControl::load_from_state(spec, state);
let restored_approver = VelocityApprover::new(clock.clone(), restored_control, delegate);
Implementations§
Source§impl<A: Approve> VelocityApprover<A>
impl<A: Approve> VelocityApprover<A>
Sourcepub fn new(clock: Arc<dyn Clock>, control: VelocityControl, delegate: A) -> Self
pub fn new(clock: Arc<dyn Clock>, control: VelocityControl, delegate: A) -> Self
Create a new velocity approver with the given velocity control and delgate approver
Sourcepub fn control(&self) -> VelocityControl
pub fn control(&self) -> VelocityControl
Get a snapshot of the velocity control, for persistence
Sourcepub fn set_control(&self, control: VelocityControl)
pub fn set_control(&self, control: VelocityControl)
Set the velocity control
Trait Implementations§
Source§impl<A: Approve> Approve for VelocityApprover<A>
impl<A: Approve> Approve for VelocityApprover<A>
Source§fn approve_invoice(&self, invoice: &Invoice) -> bool
fn approve_invoice(&self, invoice: &Invoice) -> bool
Approve an invoice for payment
Source§fn approve_keysend(&self, payment_hash: PaymentHash, amount_msat: u64) -> bool
fn approve_keysend(&self, payment_hash: PaymentHash, amount_msat: u64) -> bool
Approve a keysend (ad-hoc payment)
Source§fn approve_onchain(
&self,
tx: &Transaction,
prev_outs: &[TxOut],
unknown_indices: &[usize],
) -> bool
fn approve_onchain( &self, tx: &Transaction, prev_outs: &[TxOut], unknown_indices: &[usize], ) -> bool
Approve an onchain payment to an unknown destination Read more
Source§fn handle_proposed_invoice(
&self,
node: &Arc<Node>,
invoice: Invoice,
) -> Result<bool, Status>
fn handle_proposed_invoice( &self, node: &Arc<Node>, invoice: Invoice, ) -> Result<bool, Status>
Checks invoice for approval and adds to the node if needed and appropriate
Source§fn handle_proposed_keysend(
&self,
node: &Arc<Node>,
payee: PublicKey,
payment_hash: PaymentHash,
amount_msat: u64,
) -> Result<bool, Status>
fn handle_proposed_keysend( &self, node: &Arc<Node>, payee: PublicKey, payment_hash: PaymentHash, amount_msat: u64, ) -> Result<bool, Status>
Checks keysend for approval and adds to the node if needed and appropriate.
The payee is not validated yet.
Source§fn handle_proposed_onchain(
&self,
node: &Arc<Node>,
tx: &Transaction,
segwit_flags: &[bool],
prev_outs: &[TxOut],
uniclosekeys: &[Option<(SecretKey, Vec<Vec<u8>>)>],
opaths: &[Vec<u32>],
) -> Result<bool, Status>
fn handle_proposed_onchain( &self, node: &Arc<Node>, tx: &Transaction, segwit_flags: &[bool], prev_outs: &[TxOut], uniclosekeys: &[Option<(SecretKey, Vec<Vec<u8>>)>], opaths: &[Vec<u32>], ) -> Result<bool, Status>
Checks onchain payment for unknown destinations and checks approval
for any such outputs.
Returns Ok(false) if any unknown destinations were not approved.
impl<A: Approve> SendSync for VelocityApprover<A>
Auto Trait Implementations§
impl<A> !Freeze for VelocityApprover<A>
impl<A> !RefUnwindSafe for VelocityApprover<A>
impl<A> Send for VelocityApprover<A>
impl<A> Sync for VelocityApprover<A>
impl<A> Unpin for VelocityApprover<A>where
A: Unpin,
impl<A> !UnwindSafe for VelocityApprover<A>
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
Source§impl<T> Downcast for T
impl<T> Downcast for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more