class Tapyrus::TxOut
transaction output
Attributes
script_pubkey[RW]
value[RW]
Public Class Methods
new(value: 0, script_pubkey: nil)
click to toggle source
# File lib/tapyrus/tx_out.rb, line 13 def initialize(value: 0, script_pubkey: nil) @value = value @script_pubkey = script_pubkey end
parse_from_payload(payload)
click to toggle source
# File lib/tapyrus/tx_out.rb, line 18 def self.parse_from_payload(payload) buf = payload.is_a?(String) ? StringIO.new(payload) : payload value = buf.read(8).unpack('q').first script_size = Tapyrus.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/tapyrus/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/tapyrus/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/tapyrus/tx_out.rb, line 49 def size to_payload.bytesize end
to_empty_payload()
click to toggle source
# File lib/tapyrus/tx_out.rb, line 30 def to_empty_payload 'ffffffffffffffff00'.htb end
to_h()
click to toggle source
# File lib/tapyrus/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/tapyrus/tx_out.rb, line 25 def to_payload s = script_pubkey.to_payload [value].pack('Q') << Tapyrus.pack_var_int(s.length) << s end
value_to_btc()
click to toggle source
convert satoshi to btc
# File lib/tapyrus/tx_out.rb, line 35 def value_to_btc value / 100000000.0 end
Private Instance Methods
dust_threshold()
click to toggle source
# File lib/tapyrus/tx_out.rb, line 61 def dust_threshold return 0 if script_pubkey.unspendable? n_size = size n_size += (32 + 4 + 1 + 107 + 4) fee = n_size * Tapyrus.chain_params.dust_relay_fee / 1000 fee = Tapyrus.chain_params.dust_relay_fee > 0 ? 1 : -1 if fee == 0 && n_size != 0 fee end