Class: Sigma::Token
- Inherits:
-
Object
- Object
- Sigma::Token
- Extended by:
- FFI::Library
- Defined in:
- lib/sigma/token.rb
Overview
Token represented with token id paired with its amount
Instance Attribute Summary collapse
-
#pointer ⇒ Object
Returns the value of attribute pointer.
Class Method Summary collapse
-
.create(token_id:, token_amount:) ⇒ Token
Create a token with given id and amount.
-
.with_raw_pointer(pointer) ⇒ Token
Takes ownership of an existing Token Pointer.
Instance Method Summary collapse
-
#==(token_two) ⇒ bool
Equality check.
-
#get_amount ⇒ TokenAmount
Get amount.
-
#get_id ⇒ TokenId
Get id.
-
#to_json_eip12 ⇒ String
JSON representation according to EIP-12.
Instance Attribute Details
#pointer ⇒ Object
Returns the value of attribute pointer.
146 147 148 |
# File 'lib/sigma/token.rb', line 146 def pointer @pointer end |
Class Method Details
.create(token_id:, token_amount:) ⇒ Token
Create a token with given id and amount
152 153 154 155 156 157 |
# File 'lib/sigma/token.rb', line 152 def self.create(token_id:, token_amount:) pointer = FFI::MemoryPointer.new(:pointer) ergo_lib_token_new(token_id.pointer, token_amount.pointer, pointer) init(pointer) end |
.with_raw_pointer(pointer) ⇒ Token
Note:
A user of sigma_rb generally does not need to call this function
Takes ownership of an existing Token Pointer.
163 164 165 |
# File 'lib/sigma/token.rb', line 163 def self.with_raw_pointer(pointer) init(pointer) end |
Instance Method Details
#==(token_two) ⇒ bool
Equality check
199 200 201 |
# File 'lib/sigma/token.rb', line 199 def ==(token_two) ergo_lib_token_eq(self.pointer, token_two.pointer) end |
#get_amount ⇒ TokenAmount
Get amount
177 178 179 180 181 |
# File 'lib/sigma/token.rb', line 177 def get_amount pointer = FFI::MemoryPointer.new(:pointer) ergo_lib_token_get_amount(self.pointer, pointer) Sigma::TokenAmount.with_raw_pointer(pointer) end |
#get_id ⇒ TokenId
Get id
169 170 171 172 173 |
# File 'lib/sigma/token.rb', line 169 def get_id pointer = FFI::MemoryPointer.new(:pointer) ergo_lib_token_get_id(self.pointer, pointer) Sigma::TokenId.with_raw_pointer(pointer) end |
#to_json_eip12 ⇒ String
JSON representation according to EIP-12
186 187 188 189 190 191 192 193 194 |
# File 'lib/sigma/token.rb', line 186 def to_json_eip12 s_ptr = FFI::MemoryPointer.new(:pointer, 1) error = ergo_lib_token_to_json_eip12(self.pointer, s_ptr) Util.check_error!(error) s_ptr = s_ptr.read_pointer() str = s_ptr.read_string().force_encoding('UTF-8') Util.ergo_lib_delete_string(s_ptr) str end |