Class: Sigma::TxBuilder

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/sigma/tx_builder.rb

Overview

UnsignedTransaction builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



26
27
28
# File 'lib/sigma/tx_builder.rb', line 26

def pointer
  @pointer
end

Class Method Details

.create(box_selection:, output_candidates:, current_height:, fee_amount:, change_address:, min_change_value:) ⇒ TxBuilder

Create new TxBuilder

Parameters:

  • box_selection (BoxSelection)

    selected input boxes

  • output_candidates (ErgoBoxCandidates)

    output boxes to be “created” in this transaction

  • current_height (Integer)

    chain height that will be used in additionally created boxes (change, miner’s fee, etc.)

  • fee_amount (BoxValue)

    miner’s fee

  • change_address (Address)

    change (inputs - outputs) will be sent to this address

  • min_change_value (BoxValue)

    minimal value of the change to be sent to ‘change_address`, value less than that will be given to miners

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sigma/tx_builder.rb', line 36

def self.create(box_selection:, output_candidates:, current_height:, fee_amount:, change_address:, min_change_value:)
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_builder_new(
    box_selection.pointer,
    output_candidates.pointer,
    current_height,
    fee_amount.pointer,
    change_address.pointer,
    min_change_value.pointer,
    pointer
  )
  init(pointer)
end

.suggested_tx_feeBoxValue

Suggested transaction fee (semi-default value used across wallets and dApps as of Oct 2020)

Returns:



52
53
54
55
56
# File 'lib/sigma/tx_builder.rb', line 52

def self.suggested_tx_fee
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_builder_suggested_tx_fee(pointer)
  Sigma::BoxValue.with_raw_pointer(pointer)
end

Instance Method Details

#buildUnsignedTransaction

Build the UnsignedTransaction

Returns:



81
82
83
84
85
86
# File 'lib/sigma/tx_builder.rb', line 81

def build
  pointer = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_tx_builder_build(self.pointer, pointer)
  Util.check_error!(error)
  Sigma::UnsignedTransaction.with_raw_pointer(pointer)
end

#get_box_selectionBoxSelection

Get box selection

Returns:



90
91
92
93
94
# File 'lib/sigma/tx_builder.rb', line 90

def get_box_selection
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_builder_box_selection(self.pointer, pointer)
  Sigma::BoxSelection.with_raw_pointer(pointer)
end

#get_change_addressAddress

Get change address

Returns:



120
121
122
123
124
# File 'lib/sigma/tx_builder.rb', line 120

def get_change_address
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_builder_change_address(self.pointer, pointer)
  Sigma::Address.with_raw_pointer(pointer)
end

#get_current_heightInteger

Get current height

Returns:

  • (Integer)


106
107
108
# File 'lib/sigma/tx_builder.rb', line 106

def get_current_height
  ergo_lib_tx_builder_current_height(self.pointer)
end

#get_data_inputsDataInputs

Get data inputs

Returns:



73
74
75
76
77
# File 'lib/sigma/tx_builder.rb', line 73

def get_data_inputs
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_builder_data_inputs(self.pointer, pointer)
  Sigma::DataInputs.with_raw_pointer(pointer)
end

#get_fee_amountBoxValue

Get fee amount

Returns:



112
113
114
115
116
# File 'lib/sigma/tx_builder.rb', line 112

def get_fee_amount
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_builder_fee_amount(self.pointer, pointer)
  Sigma::BoxValue.with_raw_pointer(pointer)
end

#get_min_change_valueBoxValue

Get min change value

Returns:



128
129
130
131
132
# File 'lib/sigma/tx_builder.rb', line 128

def get_min_change_value
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_builder_min_change_value(self.pointer, pointer)
  Sigma::BoxValue.with_raw_pointer(pointer)
end

#get_output_candidatesErgoBoxCandidates

Get output candidates

Returns:



98
99
100
101
102
# File 'lib/sigma/tx_builder.rb', line 98

def get_output_candidates
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_tx_builder_output_candidates(self.pointer, pointer)
  Sigma::ErgoBoxCandidates.with_raw_pointer(pointer)
end

#set_context_extension(box_id, context_extension) ⇒ Object

Set context extension for given input

Parameters:

  • box_id (BoxId)
  • context_extension (ContextExension)


67
68
69
# File 'lib/sigma/tx_builder.rb', line 67

def set_context_extension(box_id, context_extension)
  ergo_lib_tx_builder_set_context_extension(self.pointer, box_id.pointer, context_extension.pointer)
end

#set_data_inputs(data_inputs) ⇒ Object

Set transaction’s data inputs

Parameters:



60
61
62
# File 'lib/sigma/tx_builder.rb', line 60

def set_data_inputs(data_inputs)
  ergo_lib_tx_builder_set_data_inputs(self.pointer, data_inputs.pointer)
end