Class: Sigma::BlockHeaders
- Inherits:
-
Object
- Object
- Sigma::BlockHeaders
- Extended by:
- FFI::Library
- Defined in:
- lib/sigma/block_header.rb
Overview
An ordered collection of BlockHeader
Instance Attribute Summary collapse
-
#pointer ⇒ Object
Returns the value of attribute pointer.
Class Method Summary collapse
-
.create ⇒ BlockHeaders
Create an empty collection.
-
.from_json(array_of_json_elements) ⇒ BlockHeaders
Parse BlockHeaders from array of JSON.
-
.with_raw_pointer(unread_pointer) ⇒ BlockHeaders
Takes ownership of an existing BlockHeaders Pointer.
Instance Method Summary collapse
-
#add(block_header) ⇒ Object
Add a BlockHeader.
-
#get(index) ⇒ BlockHeader?
Get item at specified index or return nil if no item exists.
-
#len ⇒ Integer
Get length of BlockHeaders.
Instance Attribute Details
#pointer ⇒ Object
Returns the value of attribute pointer.
73 74 75 |
# File 'lib/sigma/block_header.rb', line 73 def pointer @pointer end |
Class Method Details
.create ⇒ BlockHeaders
Create an empty collection
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
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.
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
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
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 |
#len ⇒ Integer
Get length of BlockHeaders
108 109 110 |
# File 'lib/sigma/block_header.rb', line 108 def len ergo_lib_block_headers_len(self.pointer) end |