Class: Sigma::SimpleBoxSelector

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

Overview

Naive box selector, collects inputs until target balace is reached

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



84
85
86
# File 'lib/sigma/box_selection.rb', line 84

def pointer
  @pointer
end

Class Method Details

.createSimpleBoxSelector

Create an empty SimpleBoxSelector

Returns:



88
89
90
91
92
# File 'lib/sigma/box_selection.rb', line 88

def self.create
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_simple_box_selector_new(pointer)
  init(pointer)
end

.with_raw_pointer(pointer) ⇒ SimpleBoxSelector

Note:

A user of sigma_rb generally does not need to call this function

Takes ownership of an existing SimpleBoxSelector Pointer.

Parameters:

  • pointer (FFI::MemoryPointer)

Returns:



116
117
118
# File 'lib/sigma/box_selection.rb', line 116

def self.with_raw_pointer(pointer)
  init(pointer)
end

Instance Method Details

#select(inputs:, target_balance:, target_tokens:) ⇒ BoxSelection

Selects inputs to satisfy target balance and tokens

Parameters:

  • inputs (ErgoBoxes)

    Available inputs (returns error if empty)

  • target_balance (BoxValue)

    coins (in nanoERGs) needed

  • target_tokens (Tokens)

    amount of tokens needed

Returns:

  • (BoxSelection)

    selected inputs and box assets(value + tokens) with change



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/sigma/box_selection.rb', line 99

def select(inputs:, target_balance:, target_tokens:)
  pointer = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_simple_box_selector_select(
    self.pointer,
    inputs.pointer,
    target_balance.pointer,
    target_tokens.pointer,
    pointer
  )
  Util.check_error!(error)
  Sigma::BoxSelection.with_raw_pointer(pointer)
end