Sha256: f7de6ff45f7ed9f0ef4db99f685eb16e9e3028a1102e789627364e1dc71f9afe

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

module Glueby
  module Contract
    class Timestamp
      module TxBuilder
        # The simple Timestamp method
        class Simple
          def initialize(wallet, fee_estimator)
            @wallet = wallet
            @fee_estimator = fee_estimator

            @txb = Internal::ContractBuilder.new(
              sender_wallet: @wallet.internal_wallet,
              fee_estimator: @fee_estimator
            )
          end

          def build
            @txb.build
          end

          def set_data(prefix, data)
            @prefix = prefix
            @data = data

            contents = [prefix, data].map(&:bth)
            @txb.data(*contents)
            self
          end

          def set_inputs(utxo_provider)
            if utxo_provider
              @txb.add_utxo_to!(
                address: @wallet.internal_wallet.receive_address,
                amount: input_amount,
                utxo_provider: utxo_provider
              )
            else
              fee = input_amount
              return self if fee == 0

              _, outputs = @wallet.internal_wallet.collect_uncolored_outputs(fee)
              outputs.each { |utxo| @txb.add_utxo(utxo) }
            end
            self
          end

          def funding_tx
            @txb.prev_txs.first
          end

          private

          def input_amount
            @txb.dummy_fee
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
glueby-1.4.0 lib/glueby/contract/timestamp/tx_builder/simple.rb
glueby-1.3.0 lib/glueby/contract/timestamp/tx_builder/simple.rb
glueby-1.2.3 lib/glueby/contract/timestamp/tx_builder/simple.rb
glueby-1.2.2 lib/glueby/contract/timestamp/tx_builder/simple.rb
glueby-1.2.1 lib/glueby/contract/timestamp/tx_builder/simple.rb