Sha256: 9fc3f607ec3c36191f47770441fd5cc6835c606b982d6344ed9b3680b541f191

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

module Glueby
  module Contract
    module FeeEstimator
      autoload :Fixed, 'glueby/contract/fee_estimator/fixed'
      autoload :Auto, 'glueby/contract/fee_estimator/auto'

      # @param [Tapyrus::Tx] tx - The target tx
      # @return fee by tapyrus(not TPC).
      def fee(tx)
        return 0 if Glueby.configuration.fee_provider_bears?
        estimate_fee(tx)
      end

      # Add dummy inputs and outputs to tx
      def dummy_tx(tx)
        dummy = Tapyrus::Tx.parse_from_payload(tx.to_payload)

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

        # Add script_sig to all intpus
        dummy.inputs.each do |input|
          input.script_sig = Tapyrus::Script.parse_from_payload('000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'.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
      module_function :dummy_tx

      private

      # @private
      # @abstract Override in subclasses. This is would be implemented an actual estimation logic.
      # @param [Tapyrus::Tx] tx - The target tx
      # @return fee by tapyrus(not TPC).
      def estimate_fee(tx)
        raise NotImplementedError
      end
    end

    # Create alias name of FeeEstimator::Fixed class for backward compatibility
    FixedFeeEstimator = FeeEstimator::Fixed
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
glueby-1.0.0 lib/glueby/contract/fee_estimator.rb
glueby-0.12.0 lib/glueby/contract/fee_estimator.rb