Sha256: 82758ee6bc8bc235480af78d576a9caa24cabe4d83fdb11447868d4745169e30
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
module Tapyrus module Message # block message # https://bitcoin.org/en/developer-reference#block class Block < Base attr_accessor :header attr_accessor :transactions attr_accessor :use_segwit COMMAND = 'block' def initialize(header, transactions = [], use_segwit = false) @header = header @transactions = transactions @use_segwit = use_segwit end def self.parse_from_payload(payload) buf = StringIO.new(payload) header = Tapyrus::BlockHeader.parse_from_payload(buf.read(80)) transactions = [] unless buf.eof? tx_count = Tapyrus.unpack_var_int_from_io(buf) tx_count.times do transactions << Tapyrus::Tx.parse_from_payload(buf) end end new(header, transactions) end def to_payload header.to_payload << Tapyrus.pack_var_int(transactions.size) << transactions.map{|t|use_segwit ? t.to_payload : t.serialize_old_format}.join end # generate Tapyrus::Block object. def to_block Tapyrus::Block.new(header, transactions) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tapyrus-0.1.0 | lib/tapyrus/message/block.rb |