mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
Move feerate helpers to chain module
We plan to use these outside of the `bump_transaction` module in the next commit, and they really should belong in the same module as `FeeEstimator`.
This commit is contained in:
parent
07606c1841
commit
19de4353d5
2 changed files with 10 additions and 10 deletions
|
@ -14,9 +14,18 @@
|
||||||
//! disconnections, transaction broadcasting, and feerate information requests.
|
//! disconnections, transaction broadcasting, and feerate information requests.
|
||||||
|
|
||||||
use core::{cmp, ops::Deref};
|
use core::{cmp, ops::Deref};
|
||||||
|
use core::convert::TryInto;
|
||||||
|
|
||||||
use bitcoin::blockdata::transaction::Transaction;
|
use bitcoin::blockdata::transaction::Transaction;
|
||||||
|
|
||||||
|
// TODO: Define typed abstraction over feerates to handle their conversions.
|
||||||
|
pub(crate) fn compute_feerate_sat_per_1000_weight(fee_sat: u64, weight: u64) -> u32 {
|
||||||
|
(fee_sat * 1000 / weight).try_into().unwrap_or(u32::max_value())
|
||||||
|
}
|
||||||
|
pub(crate) const fn fee_for_weight(feerate_sat_per_1000_weight: u32, weight: u64) -> u64 {
|
||||||
|
((feerate_sat_per_1000_weight as u64 * weight) + 1000 - 1) / 1000
|
||||||
|
}
|
||||||
|
|
||||||
/// An interface to send a transaction to the Bitcoin network.
|
/// An interface to send a transaction to the Bitcoin network.
|
||||||
pub trait BroadcasterInterface {
|
pub trait BroadcasterInterface {
|
||||||
/// Sends a list of transactions out to (hopefully) be mined.
|
/// Sends a list of transactions out to (hopefully) be mined.
|
||||||
|
|
|
@ -12,10 +12,9 @@
|
||||||
//! [`Event`]: crate::events::Event
|
//! [`Event`]: crate::events::Event
|
||||||
|
|
||||||
use alloc::collections::BTreeMap;
|
use alloc::collections::BTreeMap;
|
||||||
use core::convert::TryInto;
|
|
||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
|
|
||||||
use crate::chain::chaininterface::BroadcasterInterface;
|
use crate::chain::chaininterface::{BroadcasterInterface, compute_feerate_sat_per_1000_weight, fee_for_weight};
|
||||||
use crate::chain::ClaimId;
|
use crate::chain::ClaimId;
|
||||||
use crate::io_extras::sink;
|
use crate::io_extras::sink;
|
||||||
use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
|
use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
|
||||||
|
@ -44,14 +43,6 @@ const BASE_INPUT_SIZE: u64 = 32 /* txid */ + 4 /* vout */ + 4 /* sequence */;
|
||||||
|
|
||||||
const BASE_INPUT_WEIGHT: u64 = BASE_INPUT_SIZE * WITNESS_SCALE_FACTOR as u64;
|
const BASE_INPUT_WEIGHT: u64 = BASE_INPUT_SIZE * WITNESS_SCALE_FACTOR as u64;
|
||||||
|
|
||||||
// TODO: Define typed abstraction over feerates to handle their conversions.
|
|
||||||
fn compute_feerate_sat_per_1000_weight(fee_sat: u64, weight: u64) -> u32 {
|
|
||||||
(fee_sat * 1000 / weight).try_into().unwrap_or(u32::max_value())
|
|
||||||
}
|
|
||||||
const fn fee_for_weight(feerate_sat_per_1000_weight: u32, weight: u64) -> u64 {
|
|
||||||
((feerate_sat_per_1000_weight as u64 * weight) + 1000 - 1) / 1000
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The parameters required to derive a channel signer via [`SignerProvider`].
|
/// The parameters required to derive a channel signer via [`SignerProvider`].
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct ChannelDerivationParameters {
|
pub struct ChannelDerivationParameters {
|
||||||
|
|
Loading…
Add table
Reference in a new issue