Class: Bitcoin::Message::BlockTransactions

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/message/block_transactions.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block_hash, transactions) ⇒ BlockTransactions

Returns a new instance of BlockTransactions.



11
12
13
14
# File 'lib/bitcoin/message/block_transactions.rb', line 11

def initialize(block_hash, transactions)
  @block_hash = block_hash
  @transactions = transactions
end

Instance Attribute Details

#block_hashObject

Returns the value of attribute block_hash.



8
9
10
# File 'lib/bitcoin/message/block_transactions.rb', line 8

def block_hash
  @block_hash
end

#transactionsObject

Returns the value of attribute transactions.



9
10
11
# File 'lib/bitcoin/message/block_transactions.rb', line 9

def transactions
  @transactions
end

Class Method Details

.parse_from_payload(payload) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/bitcoin/message/block_transactions.rb', line 16

def self.parse_from_payload(payload)
  buf = StringIO.new(payload)
  block_hash = buf.read(32).bth
  tx_count = Bitcoin.unpack_var_int_from_io(buf)
  txn = tx_count.times.map{Bitcoin::Tx.parse_from_payload(buf)}
  self.new(block_hash, txn)
end

Instance Method Details

#to_payloadObject



24
25
26
# File 'lib/bitcoin/message/block_transactions.rb', line 24

def to_payload
  block_hash.htb << Bitcoin.pack_var_int(transactions.size) << transactions.map(&:to_payload).join
end