Class: CoinOp::Bit::Output
- Inherits:
-
Object
- Object
- CoinOp::Bit::Output
- Includes:
- Encodings
- Defined in:
- lib/coin-op/bit/output.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#native ⇒ Object
readonly
Returns the value of attribute native.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
-
#transaction ⇒ Object
readonly
Returns the value of attribute transaction.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#address ⇒ Object
The bitcoin address generated from the associated Script.
- #confirmations ⇒ Object
-
#initialize(options, network: nil) ⇒ Output
constructor
Takes a Hash with required keys:.
-
#set_transaction(transaction, index) ⇒ Object
DEPRECATED.
- #to_hash ⇒ Object
- #to_json(*a) ⇒ Object
-
#transaction_hash ⇒ Object
Returns the transaction hash for this output.
Methods included from Encodings
#base58, #decode_base58, #decode_hex, #hex, #int_to_byte_array
Constructor Details
#initialize(options, network: nil) ⇒ Output
Takes a Hash with required keys:
-
either :transaction (instance of Transaction) or :transaction_hash (hex-encoded hash of a Bitcoin transaction)
-
:index
-
:value
optional keys:
-
either :script (a value usable in Script.new) or :address (a valid Bitcoin address)
-
:metadata (a Hash with arbitrary contents)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/coin-op/bit/output.rb', line 23 def initialize(, network: nil) network_name = [:network] || network raise(ArgumentError, 'Network cannot be nil!') unless network_name if [:transaction] @transaction = [:transaction] elsif [:transaction_hash] @transaction_hash = [:transaction_hash] end # FIXME: be aware of string bitcoin values versus # integer satoshi values @index, @value, @address, confirmations = .values_at :index, :value, :address, :confirmations @metadata = [:metadata] || {} @metadata[:confirmations] ||= confirmations if [:script] @script = Script.new([:script], network: network_name) elsif @address @script = Script.new(address: @address, network: network_name) end @native = Bitcoin::Protocol::TxOut.from_hash( "value" => @value.to_s, "scriptPubKey" => @script.to_s ) end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
8 9 10 |
# File 'lib/coin-op/bit/output.rb', line 8 def index @index end |
#metadata ⇒ Object
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/coin-op/bit/output.rb', line 7 def @metadata end |
#native ⇒ Object (readonly)
Returns the value of attribute native.
8 9 10 |
# File 'lib/coin-op/bit/output.rb', line 8 def native @native end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
8 9 10 |
# File 'lib/coin-op/bit/output.rb', line 8 def script @script end |
#transaction ⇒ Object (readonly)
Returns the value of attribute transaction.
8 9 10 |
# File 'lib/coin-op/bit/output.rb', line 8 def transaction @transaction end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/coin-op/bit/output.rb', line 8 def value @value end |
Instance Method Details
#address ⇒ Object
The bitcoin address generated from the associated Script.
54 55 56 57 58 |
# File 'lib/coin-op/bit/output.rb', line 54 def address if @script @script.address end end |
#confirmations ⇒ Object
60 61 62 |
# File 'lib/coin-op/bit/output.rb', line 60 def confirmations @metadata[:confirmations] end |
#set_transaction(transaction, index) ⇒ Object
DEPRECATED
65 66 67 68 |
# File 'lib/coin-op/bit/output.rb', line 65 def set_transaction(transaction, index) @transaction_hash = nil @transaction, @index = transaction, index end |
#to_hash ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/coin-op/bit/output.rb', line 82 def to_hash { :transaction_hash => self.transaction_hash, :index => self.index, :value => self.value, :script => self.script, :address => self.address, :metadata => self. } end |
#to_json(*a) ⇒ Object
93 94 95 |
# File 'lib/coin-op/bit/output.rb', line 93 def to_json(*a) self.to_hash.to_json(*a) end |
#transaction_hash ⇒ Object
Returns the transaction hash for this output.
71 72 73 74 75 76 77 78 79 |
# File 'lib/coin-op/bit/output.rb', line 71 def transaction_hash if @transaction @transaction.hex_hash elsif @transaction_hash @transaction_hash else "" end end |