Class: Sigma::Token

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

Overview

Token represented with token id paired with its amount

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

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

Parameters:

Returns:



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.

Parameters:

  • pointer (FFI::MemoryPointer)

Returns:



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

Parameters:

Returns:

  • (bool)


199
200
201
# File 'lib/sigma/token.rb', line 199

def ==(token_two)
  ergo_lib_token_eq(self.pointer, token_two.pointer)
end

#get_amountTokenAmount

Get amount

Returns:



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_idTokenId

Get id

Returns:



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_eip12String

JSON representation according to EIP-12

Returns:

  • (String)

See Also:



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