Sha256: 15635d6e1b3db7a4f7785278d6ad43e4572613ec778afe3a636010ee91b1c9a1

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 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 do |content|
              content.bytes.map { |i| i.to_s(16) }.join
            end

            @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

4 entries across 4 versions & 1 rubygems

Version Path
glueby-1.2.0 lib/glueby/contract/timestamp/tx_builder/simple.rb
glueby-1.2.0.beta.3 lib/glueby/contract/timestamp/tx_builder/simple.rb
glueby-1.2.0.beta.2 lib/glueby/contract/timestamp/tx_builder/simple.rb
glueby-1.2.0.beta.1 lib/glueby/contract/timestamp/tx_builder/simple.rb