Class: OpenAssets::Transaction::TransferParameters

Inherits:
Object
  • Object
show all
Defined in:
lib/openassets/transaction/transfer_parameters.rb

Overview

The value object of a bitcoin or asset transfer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unspent_outputs, to_script, change_script, amount, output_qty = 1) ⇒ TransferParameters

initialize

Parameters:

  • unspent_outputs (Array[OpenAssets::Transaction::SpendableOutput])

    Array of the unspent outputs available for the transaction.

  • to_script (String)

    the output script to which to send the assets or bitcoins.

  • change_script (String)

    the output script to which to send any remaining change.

  • amount (Integer)

    The asset quantity or amount of the satoshi sent in the transaction.



18
19
20
21
22
23
24
# File 'lib/openassets/transaction/transfer_parameters.rb', line 18

def initialize(unspent_outputs, to_script, change_script, amount, output_qty = 1)
  @unspent_outputs = unspent_outputs
  @to_script = to_script
  @change_script = change_script
  @amount = amount
  @output_qty = output_qty
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



8
9
10
# File 'lib/openassets/transaction/transfer_parameters.rb', line 8

def amount
  @amount
end

#change_scriptObject

Returns the value of attribute change_script.



9
10
11
# File 'lib/openassets/transaction/transfer_parameters.rb', line 9

def change_script
  @change_script
end

#output_qtyObject

Returns the value of attribute output_qty.



11
12
13
# File 'lib/openassets/transaction/transfer_parameters.rb', line 11

def output_qty
  @output_qty
end

#to_scriptObject

Returns the value of attribute to_script.



10
11
12
# File 'lib/openassets/transaction/transfer_parameters.rb', line 10

def to_script
  @to_script
end

#unspent_outputsObject

Returns the value of attribute unspent_outputs.



7
8
9
# File 'lib/openassets/transaction/transfer_parameters.rb', line 7

def unspent_outputs
  @unspent_outputs
end

Instance Method Details

#split_output_amountObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/openassets/transaction/transfer_parameters.rb', line 26

def split_output_amount
  split_amounts = []
  output_qty.times{|index|
    if index == output_qty - 1
      value = amount / output_qty + amount % output_qty
    else
      value = amount / output_qty
    end
    split_amounts << value
  }
  split_amounts
end