Class: BSV::Transaction::FeeModels::SatoshisPerKilobyte

Inherits:
BSV::Transaction::FeeModel show all
Defined in:
lib/bsv/transaction/fee_models/satoshis_per_kilobyte.rb

Overview

Fee model that charges a configurable number of satoshis per kilobyte.

Uses the transaction’s estimated size (from templates for unsigned inputs, actual size for signed inputs) to compute the fee.

Examples:

model = BSV::Transaction::FeeModels::SatoshisPerKilobyte.new(value: 100)
fee = model.compute_fee(transaction) # => 25 (for a ~250 byte tx)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value: 100) ⇒ SatoshisPerKilobyte

Returns a new instance of SatoshisPerKilobyte.

Parameters:

  • value (Integer) (defaults to: 100)

    satoshis per kilobyte (default: 100)



19
20
21
22
# File 'lib/bsv/transaction/fee_models/satoshis_per_kilobyte.rb', line 19

def initialize(value: 100)
  super()
  @value = value
end

Instance Attribute Details

#valueInteger (readonly)

Returns satoshis per kilobyte rate.

Returns:

  • (Integer)

    satoshis per kilobyte rate



16
17
18
# File 'lib/bsv/transaction/fee_models/satoshis_per_kilobyte.rb', line 16

def value
  @value
end

Instance Method Details

#compute_fee(transaction) ⇒ Integer

Compute the fee for a transaction based on its estimated size.

Parameters:

  • transaction (Transaction)

    the transaction to compute the fee for

Returns:

  • (Integer)

    the fee in satoshis



28
29
30
31
# File 'lib/bsv/transaction/fee_models/satoshis_per_kilobyte.rb', line 28

def compute_fee(transaction)
  size = transaction.estimated_size
  (size / 1000.0 * @value).ceil
end