Class: Sigma::TokenId

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

Overview

Token id (32-byte digest)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



72
73
74
# File 'lib/sigma/token.rb', line 72

def pointer
  @pointer
end

Class Method Details

.from_base16_encoded_string(str) ⇒ TokenId

Parse token id (32 byte digest) from base16-encoded string

Parameters:

  • str (String)

Returns:



95
96
97
98
99
100
101
# File 'lib/sigma/token.rb', line 95

def self.from_base16_encoded_string(str)
  tid_ptr = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_token_id_from_str(str, tid_ptr)
  Util.check_error!(error)

  init(tid_ptr)
end

.with_box_id(box_id) ⇒ TokenId

Create token id from ergo box id (32 byte digest)

Parameters:

Returns:



85
86
87
88
89
90
# File 'lib/sigma/token.rb', line 85

def self.with_box_id(box_id)
  tid_ptr = FFI::MemoryPointer.new(:pointer)
  ergo_lib_token_id_from_box_id(box_id.pointer, tid_ptr)

  init(tid_ptr)
end

.with_raw_pointer(tid_pointer) ⇒ TokenId

Note:

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

Takes ownership of an existing TokenId Pointer.

Parameters:

  • pointer (FFI::MemoryPointer)

Returns:



78
79
80
# File 'lib/sigma/token.rb', line 78

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

Instance Method Details

#==(token_id_two) ⇒ bool

Equality check

Parameters:

Returns:

  • (bool)


117
118
119
# File 'lib/sigma/token.rb', line 117

def ==(token_id_two)
  ergo_lib_token_id_eq(self.pointer, token_id_two.pointer)
end

#to_base16_encoded_stringString

Get base16 encoded string

Returns:

  • (String)


105
106
107
108
109
110
111
112
# File 'lib/sigma/token.rb', line 105

def to_base16_encoded_string
  s_ptr = FFI::MemoryPointer.new(:pointer, 1)
  ergo_lib_token_id_to_str(self.pointer, s_ptr)
  s_ptr = s_ptr.read_pointer()
  str = s_ptr.read_string().force_encoding('UTF-8')
  Util.ergo_lib_delete_string(s_ptr)
  str
end