Module: Glueby::Contract::FeeEstimator

Included in:
Auto, Fixed
Defined in:
lib/glueby/contract/fee_estimator.rb,
lib/glueby/contract/fee_estimator/auto.rb,
lib/glueby/contract/fee_estimator/fixed.rb

Defined Under Namespace

Classes: Auto, Fixed

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dummy_tx(tx, dummy_input_count: 1) ⇒ Tapyrus::Tx

Add dummy inputs and outputs to tx. Fee Estimation needs the actual tx size when it will be broadcasted to the blockchain network.

Parameters:

  • tx (Tapyrus::Tx)

    The tx that is the target to be estimated fees

  • dummy_input_count (Integer) (defaults to: 1)

    The number of dummy inputs to be added before the estimation.

Returns:

  • (Tapyrus::Tx)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/glueby/contract/fee_estimator.rb', line 20

def dummy_tx(tx, dummy_input_count: 1)
  dummy = Tapyrus::Tx.parse_from_payload(tx.to_payload)

  # dummy input for tpc
  dummy_input_count.times do
    out_point = Tapyrus::OutPoint.new('00' * 32, 0)
    dummy.inputs << Tapyrus::TxIn.new(out_point: out_point)
  end

  # Add script_sig to all intpus
  dummy.inputs.each do |input|
    input.script_sig = Tapyrus::Script.parse_from_payload(('00' * 100).htb)
  end

  # dummy output to return change
  change_script = Tapyrus::Script.to_p2pkh('0000000000000000000000000000000000000000')
  dummy.outputs << Tapyrus::TxOut.new(value: 0, script_pubkey: change_script)
  dummy
end

Instance Method Details

#fee(tx) ⇒ Object

Returns fee by tapyrus(not TPC).

Parameters:

  • tx (Tapyrus::Tx)
    • The target tx

Returns:

  • fee by tapyrus(not TPC).



9
10
11
12
# File 'lib/glueby/contract/fee_estimator.rb', line 9

def fee(tx)
  return 0 if Glueby.configuration.fee_provider_bears?
  estimate_fee(tx)
end