Class: Bitcoin::TxOut
- Inherits:
-
Object
- Object
- Bitcoin::TxOut
- Defined in:
- lib/bitcoin/tx_out.rb
Overview
transaction output
Instance Attribute Summary collapse
-
#script_pubkey ⇒ Object
Returns the value of attribute script_pubkey.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#dust? ⇒ Boolean
Whether this output is dust or not.
-
#initialize(value: 0, script_pubkey: nil) ⇒ TxOut
constructor
A new instance of TxOut.
-
#size ⇒ Integer
Returns this output bytesize.
- #to_empty_payload ⇒ Object
- #to_h ⇒ Object
- #to_payload ⇒ Object
-
#value_to_btc ⇒ Object
convert satoshi to btc.
Constructor Details
#initialize(value: 0, script_pubkey: nil) ⇒ TxOut
Returns a new instance of TxOut.
12 13 14 15 |
# File 'lib/bitcoin/tx_out.rb', line 12 def initialize(value: 0, script_pubkey: nil) @value = value @script_pubkey = script_pubkey end |
Instance Attribute Details
#script_pubkey ⇒ Object
Returns the value of attribute script_pubkey.
10 11 12 |
# File 'lib/bitcoin/tx_out.rb', line 10 def script_pubkey @script_pubkey end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/bitcoin/tx_out.rb', line 9 def value @value end |
Class Method Details
.parse_from_payload(payload) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/bitcoin/tx_out.rb', line 17 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 |
Instance Method Details
#==(other) ⇒ Object
41 42 43 |
# File 'lib/bitcoin/tx_out.rb', line 41 def ==(other) to_payload == other.to_payload end |
#dust? ⇒ Boolean
Whether this output is dust or not
53 54 55 |
# File 'lib/bitcoin/tx_out.rb', line 53 def dust? value < dust_threshold end |
#size ⇒ Integer
Returns this output bytesize
47 48 49 |
# File 'lib/bitcoin/tx_out.rb', line 47 def size to_payload.bytesize end |
#to_empty_payload ⇒ Object
28 29 30 |
# File 'lib/bitcoin/tx_out.rb', line 28 def to_empty_payload 'ffffffffffffffff00'.htb end |
#to_h ⇒ Object
37 38 39 |
# File 'lib/bitcoin/tx_out.rb', line 37 def to_h {value: value_to_btc, script_pubkey: script_pubkey.to_h} end |
#to_payload ⇒ Object
24 25 26 |
# File 'lib/bitcoin/tx_out.rb', line 24 def to_payload [value].pack('Q') << script_pubkey.to_payload(true) end |
#value_to_btc ⇒ Object
convert satoshi to btc
33 34 35 |
# File 'lib/bitcoin/tx_out.rb', line 33 def value_to_btc value / 100000000.0 end |