Class: Sigma::BlockHeaders

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

Overview

An ordered collection of BlockHeader

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



73
74
75
# File 'lib/sigma/block_header.rb', line 73

def pointer
  @pointer
end

Class Method Details

.createBlockHeaders

Create an empty collection

Returns:



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

def self.create
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_block_headers_new(pointer)

  init(pointer)
end

.from_json(array_of_json_elements) ⇒ BlockHeaders

Parse BlockHeaders from array of JSON

Parameters:

  • array_of_json_elements (Array<String>)

Returns:



95
96
97
98
99
100
101
102
103
104
# File 'lib/sigma/block_header.rb', line 95

def self.from_json(array_of_json_elements)
  headers = array_of_json_elements.map do |json|
    Sigma::BlockHeader.with_json(json)
  end
  container = create
  headers.each do |header|
    container.add(header)
  end
  container
end

.with_raw_pointer(unread_pointer) ⇒ BlockHeaders

Note:

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

Takes ownership of an existing BlockHeaders Pointer.

Parameters:

  • pointer (FFI::MemoryPointer)

Returns:



79
80
81
# File 'lib/sigma/block_header.rb', line 79

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

Instance Method Details

#add(block_header) ⇒ Object

Add a BlockHeader

Parameters:



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

def add(block_header)
  ergo_lib_block_headers_add(block_header.pointer, self.pointer)
end

#get(index) ⇒ BlockHeader?

Get item at specified index or return nil if no item exists

Returns:



121
122
123
124
125
126
127
128
129
130
# File 'lib/sigma/block_header.rb', line 121

def get(index)
  pointer = FFI::MemoryPointer.new(:pointer)
  res = ergo_lib_block_headers_get(self.pointer, index, pointer)
  Util.check_error!(res[:error])
  if res[:is_some]
    Sigma::BlockHeader.with_raw_pointer(pointer)
  else
    nil
  end
end

#lenInteger

Get length of BlockHeaders

Returns:

  • (Integer)


108
109
110
# File 'lib/sigma/block_header.rb', line 108

def len
  ergo_lib_block_headers_len(self.pointer)
end