Class: Sigma::ErgoBoxCandidateBuilder
- Inherits:
-
Object
- Object
- Sigma::ErgoBoxCandidateBuilder
- Extended by:
- FFI::Library
- Defined in:
- lib/sigma/ergo_box_candidate_builder.rb
Overview
An ErgoBoxCandidate Builder
Instance Attribute Summary collapse
-
#pointer ⇒ Object
Returns the value of attribute pointer.
Class Method Summary collapse
-
.create(box_value:, contract:, creation_height:) ⇒ ErgoBoxCandidateBuilder
Create builder with required box parameters.
Instance Method Summary collapse
-
#add_token(token_id, token_amount) ⇒ ErgoBoxCandidateBuilder
Add given token_id and token_amount.
-
#build ⇒ ErgoBoxCandidate
Build the box candidate.
-
#calc_box_size_bytes ⇒ Integer
Calulate serialized box size (in bytes).
-
#calc_min_box_value ⇒ BoxValue
Calculate minimal box value for the current box serialized size (in bytes).
-
#delete_register_value(register_id) ⇒ ErgoBoxCandidate
Delete register value (make register empty) for the given register id (R4-R9).
-
#get_min_box_value_per_byte ⇒ Integer
Get minimal value (per byte of the serialized box size).
-
#get_register_value(register_id) ⇒ Constant?
Gets register value or nil if empty.
-
#get_value ⇒ BoxValue
Get box value.
-
#mint_token(token:, name:, description:, num_decimals:) ⇒ ErgoBoxCandidateBuilder
Mint token, as defined in EIP-004.
-
#set_min_box_value_per_byte(min_box_value) ⇒ ErgoBoxCandidateBuilder
Set minimal value (per byte of the serialized box size).
-
#set_register_value(register_id, constant) ⇒ Object
Set register (R4-R9) to the given value.
-
#set_value(box_value) ⇒ ErgoBoxCandidate
Set new box value.
Instance Attribute Details
#pointer ⇒ Object
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
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
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 |
#build ⇒ ErgoBoxCandidate
Build the box candidate
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_bytes ⇒ Integer
Calulate serialized box size (in bytes)
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_value ⇒ BoxValue
Calculate minimal box value for the current box serialized size (in bytes)
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)
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_byte ⇒ Integer
Get minimal value (per byte of the serialized box size)
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
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_value ⇒ BoxValue
Get box value
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
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)
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
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
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 |