Class: Bitcoin::Wallet::Utxo
- Inherits:
-
Object
- Object
- Bitcoin::Wallet::Utxo
- Defined in:
- lib/bitcoin/wallet/utxo.rb
Instance Attribute Summary collapse
-
#block_height ⇒ Object
readonly
Returns the value of attribute block_height.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#script_pubkey ⇒ Object
readonly
Returns the value of attribute script_pubkey.
-
#tx_hash ⇒ Object
readonly
Returns the value of attribute tx_hash.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(tx_hash, index, value, script_pubkey, block_height = nil) ⇒ Utxo
constructor
A new instance of Utxo.
- #to_payload ⇒ Object
Constructor Details
#initialize(tx_hash, index, value, script_pubkey, block_height = nil) ⇒ Utxo
Returns a new instance of Utxo.
10 11 12 13 14 15 16 |
# File 'lib/bitcoin/wallet/utxo.rb', line 10 def initialize(tx_hash, index, value, script_pubkey, block_height = nil) @tx_hash = tx_hash @index = index @block_height = block_height @value = value @script_pubkey = script_pubkey end |
Instance Attribute Details
#block_height ⇒ Object (readonly)
Returns the value of attribute block_height.
6 7 8 |
# File 'lib/bitcoin/wallet/utxo.rb', line 6 def block_height @block_height end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
5 6 7 |
# File 'lib/bitcoin/wallet/utxo.rb', line 5 def index @index end |
#script_pubkey ⇒ Object (readonly)
Returns the value of attribute script_pubkey.
8 9 10 |
# File 'lib/bitcoin/wallet/utxo.rb', line 8 def script_pubkey @script_pubkey end |
#tx_hash ⇒ Object (readonly)
Returns the value of attribute tx_hash.
4 5 6 |
# File 'lib/bitcoin/wallet/utxo.rb', line 4 def tx_hash @tx_hash end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/bitcoin/wallet/utxo.rb', line 7 def value @value end |
Class Method Details
.parse_from_payload(payload) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bitcoin/wallet/utxo.rb', line 18 def self.parse_from_payload(payload) return nil if payload.nil? tx_hash, index, block_height, value, payload = payload.unpack('H64VVQa*') buf = StringIO.new(payload) script_size = Bitcoin.unpack_var_int_from_io(buf) script_pubkey = Bitcoin::Script.parse_from_payload(buf.read(script_size)); new(tx_hash, index, value, script_pubkey, block_height == 0 ? nil : block_height ) end |
Instance Method Details
#to_payload ⇒ Object
29 30 31 32 33 34 |
# File 'lib/bitcoin/wallet/utxo.rb', line 29 def to_payload payload = [tx_hash, index, block_height.nil? ? 0 : block_height, value].pack('H64VVQ') s = script_pubkey.to_payload payload << Bitcoin.pack_var_int(s.length) << s payload end |