class Bitcoin::TxOut
transaction output
Attributes
script_pubkey[RW]
value[RW]
Public Class Methods
new(value: 0, script_pubkey: nil)
click to toggle source
# File lib/bitcoin/tx_out.rb, line 14 def initialize(value: 0, script_pubkey: nil) @value = value @script_pubkey = script_pubkey end
parse_from_payload(payload)
click to toggle source
# File lib/bitcoin/tx_out.rb, line 19 def self.parse_from_payload(payload) buf = payload.is_a?(String) ? StringIO.new(payload) : payload value = buf.read(8).unpack1('q') script_size = Bitcoin.unpack_var_int_from_io(buf) new(value: value, script_pubkey: Script.parse_from_payload(buf.read(script_size))) end
Public Instance Methods
==(other)
click to toggle source
# File lib/bitcoin/tx_out.rb, line 43 def ==(other) to_payload == other.to_payload end
dust?()
click to toggle source
Whether this output is dust or not @return [Boolean]
# File lib/bitcoin/tx_out.rb, line 55 def dust? value < dust_threshold end
size()
click to toggle source
Returns this output bytesize @return [Integer] bytesize
# File lib/bitcoin/tx_out.rb, line 49 def size to_payload.bytesize end
to_empty_payload()
click to toggle source
# File lib/bitcoin/tx_out.rb, line 30 def to_empty_payload 'ffffffffffffffff00'.htb end
to_h()
click to toggle source
# File lib/bitcoin/tx_out.rb, line 39 def to_h {value: value_to_btc, script_pubkey: script_pubkey.to_h} end
to_payload()
click to toggle source
# File lib/bitcoin/tx_out.rb, line 26 def to_payload [value].pack('Q') << script_pubkey.to_payload(true) end
value_to_btc()
click to toggle source
convert satoshi to btc
# File lib/bitcoin/tx_out.rb, line 35 def value_to_btc value / 100000000.0 end
Private Instance Methods
dust_threshold()
click to toggle source
# File lib/bitcoin/tx_out.rb, line 61 def dust_threshold return 0 if script_pubkey.unspendable? n_size = size n_size += script_pubkey.witness_program? ? (32 + 4 + 1 + (107 / Bitcoin::WITNESS_SCALE_FACTOR) + 4) : (32 + 4 + 1 + 107 + 4) fee = n_size * Bitcoin.chain_params.dust_relay_fee / 1000 if fee == 0 && n_size != 0 fee = Bitcoin.chain_params.dust_relay_fee > 0 ? 1 : -1 end fee end