Class: Tapyrus::TxOut
- Inherits:
-
Object
- Object
- Tapyrus::TxOut
- Includes:
- OpenAssets::MarkerOutput, Color::ColoredOutput
- Defined in:
- lib/tapyrus/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.
Methods included from Color::ColoredOutput
#color_id, #colored?, #nft?, #non_reissuable?, #reissuable?
Methods included from OpenAssets::MarkerOutput
#oa_payload, #open_assets_marker?
Constructor Details
#initialize(value: 0, script_pubkey: nil) ⇒ TxOut
Returns a new instance of TxOut.
13 14 15 16 |
# File 'lib/tapyrus/tx_out.rb', line 13 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.
11 12 13 |
# File 'lib/tapyrus/tx_out.rb', line 11 def script_pubkey @script_pubkey end |
#value ⇒ Object
Returns the value of attribute value.
10 11 12 |
# File 'lib/tapyrus/tx_out.rb', line 10 def value @value end |
Class Method Details
.parse_from_payload(payload) ⇒ Object
18 19 20 21 22 23 |
# 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 |
Instance Method Details
#==(other) ⇒ Object
43 44 45 |
# File 'lib/tapyrus/tx_out.rb', line 43 def ==(other) to_payload == other.to_payload end |
#dust? ⇒ Boolean
Whether this output is dust or not
55 56 57 |
# File 'lib/tapyrus/tx_out.rb', line 55 def dust? value < dust_threshold end |
#size ⇒ Integer
Returns this output bytesize
49 50 51 |
# File 'lib/tapyrus/tx_out.rb', line 49 def size to_payload.bytesize end |
#to_empty_payload ⇒ Object
30 31 32 |
# File 'lib/tapyrus/tx_out.rb', line 30 def to_empty_payload "ffffffffffffffff00".htb end |
#to_h ⇒ Object
39 40 41 |
# File 'lib/tapyrus/tx_out.rb', line 39 def to_h { value: value_to_btc, script_pubkey: script_pubkey.to_h } end |
#to_payload ⇒ Object
25 26 27 28 |
# 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 ⇒ Object
convert satoshi to btc
35 36 37 |
# File 'lib/tapyrus/tx_out.rb', line 35 def value_to_btc value / 100000000.0 end |