Class: TonSdkRuby::Message

Inherits:
Object
  • Object
show all
Extended by:
TonSdkRuby
Includes:
TonSdkRuby
Defined in:
lib/ton-sdk-ruby/types/block.rb

Constant Summary

Constants included from TonSdkRuby

DEPTH_BITS, FLAG_BOUNCEABLE, FLAG_NON_BOUNCEABLE, FLAG_TEST_ONLY, HASH_BITS, INT32_MAX, INT32_MIN, LEAN_BOC_MAGIC_PREFIX, LEAN_BOC_MAGIC_PREFIX_CRC, REACH_BOC_MAGIC_PREFIX, VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TonSdkRuby

augment, base64_to_bytes, bits_to_big_int, bits_to_big_uint, bits_to_bytes, bits_to_hex, bits_to_int_uint, breadth_first_sort, bytes_compare, bytes_needed_for_words_bip39, bytes_to_base64, bytes_to_bits, bytes_to_data_string, bytes_to_hex, bytes_to_string, bytes_to_uint, crc16, crc16_bytes_be, crc32c, crc32c_bytes_le, depth_first_sort, deserialize, deserialize_cell, deserialize_fift, deserialize_header, generate_words_bip39, get_mapper, hex_to_bits, hex_to_bytes, hex_to_data_string, read_json_from_link, read_post_json_from_link, require_type, rollback, serialize, serialize_cell, sha256, sha512, sign_cell, slice_into_chunks, string_to_bytes, uint_to_hex, validate_library_reference, validate_merkle_proof, validate_merkle_update, validate_ordinary, validate_pruned_branch

Constructor Details

#initialize(options) ⇒ Message

Returns a new instance of Message.



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/ton-sdk-ruby/types/block.rb', line 280

def initialize(options)
  @data = options
  b = Builder.new
  b.store_slice(data.info.cell.parse) # info:CommonMsgInfo

  # init:(Maybe (Either StateInit ^StateInit))
  if data.init
    b.store_bits([1, 0])
    b.store_slice(data.init.cell.parse)
  else
    b.store_bit(0)
  end

  # body:(Either X ^X)
  if data.body
    if (b.bits.length + data.body.bits.length + 1 <= 1023) &&
      (b.refs.length + data.body.refs.length <= 4)
      b.store_bit(0)
      b.store_slice(data.body.parse)
    else
      b.store_bit(1)
      b.store_ref(data.body)
    end
  else
    b.store_bit(0)
  end

  @cell = b.cell
end

Instance Attribute Details

#cellObject (readonly)

Returns the value of attribute cell.



278
279
280
# File 'lib/ton-sdk-ruby/types/block.rb', line 278

def cell
  @cell
end

#dataObject (readonly)

Returns the value of attribute data.



278
279
280
# File 'lib/ton-sdk-ruby/types/block.rb', line 278

def data
  @data
end

Class Method Details

.parse(cs) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/ton-sdk-ruby/types/block.rb', line 310

def self.parse(cs)
  data = {}
  data.info = CommonMsgInfo.parse(cs)

  if cs.load_bit
    init = cs.load_bit ? cs.load_ref.parse : cs
    data.init = StateInit.parse(init)
  end

  if cs.load_bit
    data.body = cs.load_ref
  else
    data.body = Builder.new.store_slice(cs).cell
  end

  new(data)
end