Class: Sigma::ErgoBoxCandidateBuilder

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

Overview

An ErgoBoxCandidate 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/ergo_box_candidate_builder.rb', line 26

def pointer
  @pointer
end

Class Method Details

.create(box_value:, contract:, creation_height:) ⇒ ErgoBoxCandidateBuilder

Create builder with required box parameters

Parameters:

  • box_value: (BoxValue)

    amount of money associated with the box

  • contract: (Contract)

    guarding contract, which should be evaluated to true in order to open(spend) this box

  • creation_height: (Integer)

    height when a transaction containing the box is created. It should not exceed height of the block, containing the transaction with this box.

Returns:



32
33
34
35
36
37
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 32

def self.create(box_value:, contract:, creation_height:)
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_ergo_box_candidate_builder_new(box_value.pointer, contract.pointer, creation_height, pointer)
  
  init(pointer)
end

Instance Method Details

#add_token(token_id, token_amount) ⇒ ErgoBoxCandidateBuilder

Add given token_id and token_amount

Parameters:

Returns:



140
141
142
143
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 140

def add_token(token_id, token_amount)
  ergo_lib_ergo_box_candidate_builder_add_token(self.pointer, token_id.pointer, token_amount.pointer)
  self
end

#buildErgoBoxCandidate

Build the box candidate

Returns:



147
148
149
150
151
152
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 147

def build
  pointer = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_ergo_box_candidate_builder_build(self.pointer, pointer)
  Util.check_error!(error)
  ErgoBoxCandidate.with_raw_pointer(pointer)
end

#calc_box_size_bytesInteger

Calulate serialized box size (in bytes)

Returns:

  • (Integer)


71
72
73
74
75
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 71

def calc_box_size_bytes
  res = ergo_lib_ergo_box_candidate_builder_calc_box_size_bytes(self.pointer)
  Util.check_error!(res[:error])
  res[:value]
end

#calc_min_box_valueBoxValue

Calculate minimal box value for the current box serialized size (in bytes)

Returns:



79
80
81
82
83
84
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 79

def calc_min_box_value
  pointer = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_ergo_box_candidate_calc_min_box_value(self.pointer, pointer)
  Util.check_error!(error)
  Sigma::BoxValue.with_raw_pointer(pointer)
end

#delete_register_value(register_id) ⇒ ErgoBoxCandidate

Delete register value (make register empty) for the given register id (R4-R9)

Parameters:

  • register_id (Integer)

Returns:

See Also:



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

def delete_register_value(register_id)
  ergo_lib_ergo_box_candidate_builder_delete_register_value(self.pointer, register_id)
  self
end

#get_min_box_value_per_byteInteger

Get minimal value (per byte of the serialized box size)

Returns:

  • (Integer)


49
50
51
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 49

def get_min_box_value_per_byte
  ergo_lib_ergo_box_candidate_builder_min_box_value_per_byte(self.pointer)
end

#get_register_value(register_id) ⇒ Constant?

Gets register value or nil if empty

Parameters:

  • register_id (Integer)

Returns:

See Also:



98
99
100
101
102
103
104
105
106
107
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 98

def get_register_value(register_id)
  pointer = FFI::MemoryPointer.new(:pointer)
  res = ergo_lib_ergo_box_candidate_builder_register_value(self.pointer, register_id, pointer)
  Util.check_error!(res[:error]) 
  if res[:is_some]
    Sigma::Constant.with_raw_pointer(pointer)
  else
    nil
  end
end

#get_valueBoxValue

Get box value

Returns:



63
64
65
66
67
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 63

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

#mint_token(token:, name:, description:, num_decimals:) ⇒ ErgoBoxCandidateBuilder

Mint token, as defined in EIP-004

Parameters:

  • token: (Token)
  • name: (String)

    Token name, will be encoded in R4

  • description: (String)

    Token description, will be encoded in R5

  • num_decimals: (Integer)

    Number of decimals, will be encoded in R6

Returns:

See Also:



125
126
127
128
129
130
131
132
133
134
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 125

def mint_token(token:, name:, description:, num_decimals:)
  ergo_lib_ergo_box_candidate_builder_mint_token(
    self.pointer,
    token.pointer,
    name,
    description,
    num_decimals
  )
  self
end

#set_min_box_value_per_byte(min_box_value) ⇒ ErgoBoxCandidateBuilder

Set minimal value (per byte of the serialized box size)

Parameters:

  • min_box_value (Uint32)

    Unsigned 32-bit integer

Returns:



42
43
44
45
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 42

def set_min_box_value_per_byte(min_box_value)
  ergo_lib_ergo_box_candidate_builder_set_min_box_value_per_byte(self.pointer, min_box_value)
  self
end

#set_register_value(register_id, constant) ⇒ Object

Set register (R4-R9) to the given value

Parameters:

  • register_id (Integer)
  • constant (Constant)

See Also:



90
91
92
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 90

def set_register_value(register_id, constant)
  ergo_lib_ergo_box_candidate_builder_set_register_value(self.pointer, register_id, constant.pointer)
end

#set_value(box_value) ⇒ ErgoBoxCandidate

Set new box value

Parameters:

Returns:



56
57
58
59
# File 'lib/sigma/ergo_box_candidate_builder.rb', line 56

def set_value(box_value)
  ergo_lib_ergo_box_candidate_builder_set_value(self.pointer, box_value.pointer)
  self
end