Class: Glueby::Contract::Timestamp::TxBuilder::Simple

Inherits:
Object
  • Object
show all
Defined in:
lib/glueby/contract/timestamp/tx_builder/simple.rb

Overview

The simple Timestamp method

Direct Known Subclasses

Trackable

Instance Method Summary collapse

Constructor Details

#initialize(wallet, fee_estimator) ⇒ Simple

Returns a new instance of Simple.



7
8
9
10
11
12
13
14
15
# File 'lib/glueby/contract/timestamp/tx_builder/simple.rb', line 7

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

Instance Method Details

#buildObject



17
18
19
# File 'lib/glueby/contract/timestamp/tx_builder/simple.rb', line 17

def build
  @txb.build
end

#funding_txObject



47
48
49
# File 'lib/glueby/contract/timestamp/tx_builder/simple.rb', line 47

def funding_tx
  @txb.prev_txs.first
end

#set_data(prefix, data) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/glueby/contract/timestamp/tx_builder/simple.rb', line 21

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

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

#set_inputs(utxo_provider) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/glueby/contract/timestamp/tx_builder/simple.rb', line 30

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