Class: Glueby::FeeProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/glueby/fee_provider.rb,
lib/glueby/fee_provider/tasks.rb

Defined Under Namespace

Classes: NoUtxosInUtxoPool, Tasks

Constant Summary collapse

WALLET_ID =
'FEE_PROVIDER_WALLET'
DEFAULT_FIXED_FEE =
1000
DEFAULT_UTXO_POOL_SIZE =
20
MAX_UTXO_POOL_SIZE =
2_000

Instance Method Summary collapse

Constructor Details

#initializeFeeProvider

Returns a new instance of FeeProvider.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/glueby/fee_provider.rb', line 30

def initialize
  @wallet = begin
              Internal::Wallet.load(WALLET_ID)
            rescue Internal::Wallet::Errors::WalletNotFound => _
              Internal::Wallet.create(WALLET_ID)
            end

  validate_config!
  @fixed_fee = (FeeProvider.config && FeeProvider.config[:fixed_fee]) || DEFAULT_FIXED_FEE
  @utxo_pool_size = (FeeProvider.config && FeeProvider.config[:utxo_pool_size]) || DEFAULT_UTXO_POOL_SIZE
end

Instance Method Details

#provide(tx) ⇒ Tapyrus::Tx

Provide an input for fee to the tx.

Parameters:

  • tx (Tapyrus::Tx)
    • The tx that is provided fee as a input. It should be signed with ANYONECANPAY flag.

Returns:

  • (Tapyrus::Tx)

Raises:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/glueby/fee_provider.rb', line 47

def provide(tx)
  tx.inputs.each do |txin|
    sig = get_signature(txin.script_sig)
    unless sig[-1].unpack1('C') & Tapyrus::SIGHASH_TYPE[:anyonecanpay] == Tapyrus::SIGHASH_TYPE[:anyonecanpay]
      raise ArgumentError, 'All the signatures that the tx inputs has should have ANYONECANPAY flag.'
    end
  end

  utxo = utxo_for_fee
  out_point = Tapyrus::OutPoint.new(utxo[:txid].rhex, utxo[:vout])
  tx.inputs << Tapyrus::TxIn.new(out_point: out_point)

  wallet.sign_tx(tx, for_fee_provider_input: true)
end