Class: BTC::AssetTransactionOutput
- Inherits:
-
Object
- Object
- BTC::AssetTransactionOutput
- Defined in:
- lib/btcruby/open_assets/asset_transaction_output.rb
Constant Summary collapse
- KIND_ISSUE =
:issue- KIND_TRANSFER =
:transfer- KIND_MARKER =
:marker
Instance Attribute Summary collapse
-
#asset_id ⇒ Object
Verified outputs with
asset_id == nilare uncolored. -
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#issue ⇒ Object
(also: #issue?)
Returns
trueif this output may issue new amount of some asset. -
#kind ⇒ Object
Returns the value of attribute kind.
-
#marker ⇒ Object
Returns
trueif this output corresponds to a marker output (always uncolored). -
#transaction_output ⇒ Object
BTC::TransactionOutput.
-
#transfer ⇒ Object
(also: #transfer?)
Returns
trueif this output may transfer new amount of some asset. -
#value ⇒ Object
Returns the value of attribute value.
-
#verified ⇒ Object
true if asset_id and value are verified and can be used.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #assets_data ⇒ Object
-
#colored? ⇒ Boolean
Output is colored when it has AssetID and a positive value.
- #has_value? ⇒ Boolean
-
#initialize(transaction_output: nil, asset_id: nil, value: nil, verified: false, issue: nil, transfer: nil, marker: nil) ⇒ AssetTransactionOutput
constructor
A new instance of AssetTransactionOutput.
- #marker? ⇒ Boolean
- #outpoint ⇒ Object
- #outpoint_id ⇒ Object
-
#parse_assets_data(data, offset: 0) ⇒ Object
Returns total length read.
- #transaction_hash ⇒ Object
- #transaction_id ⇒ Object
-
#verified? ⇒ Boolean
Output is verified when we know for sure if it's colored or not and if it is, what asset and how much is associated with it.
Constructor Details
#initialize(transaction_output: nil, asset_id: nil, value: nil, verified: false, issue: nil, transfer: nil, marker: nil) ⇒ AssetTransactionOutput
Returns a new instance of AssetTransactionOutput.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 23 def initialize(transaction_output: nil, asset_id: nil, value: nil, verified: false, issue: nil, transfer: nil, marker: nil) raise ArgumentError, "No transaction_output provided" if !transaction_output @transaction_output = transaction_output @index = transaction_output ? transaction_output.index : nil @asset_id = asset_id @value = value @verified = !!verified self.issue = issue if issue self.transfer = transfer if transfer self.marker = marker if marker end |
Instance Attribute Details
#asset_id ⇒ Object
Verified outputs with asset_id == nil are uncolored.
Non-verified outputs are not known to have assets associated with them.
19 20 21 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 19 def asset_id @asset_id end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
9 10 11 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 9 def index @index end |
#issue ⇒ Object Also known as: issue?
Returns true if this output may issue new amount of some asset.
13 14 15 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 13 def issue @issue end |
#kind ⇒ Object
Returns the value of attribute kind.
12 13 14 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 12 def kind @kind end |
#marker ⇒ Object
Returns true if this output corresponds to a marker output (always uncolored)
15 16 17 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 15 def marker @marker end |
#transaction_output ⇒ Object
BTC::TransactionOutput
10 11 12 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 10 def transaction_output @transaction_output end |
#transfer ⇒ Object Also known as: transfer?
Returns true if this output may transfer new amount of some asset.
14 15 16 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 14 def transfer @transfer end |
#value ⇒ Object
Returns the value of attribute value.
20 21 22 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 20 def value @value end |
#verified ⇒ Object
true if asset_id and value are verified and can be used.
21 22 23 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 21 def verified @verified end |
Instance Method Details
#==(other) ⇒ Object
136 137 138 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 136 def ==(other) super(other) || self.transaction_output == other.transaction_output end |
#assets_data ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 114 def assets_data data = "".b data << WireFormat.encode_uint8(@verified ? 1 : 0) data << WireFormat.encode_string(@asset_id ? @asset_id.hash : "".b) data << WireFormat.encode_int64le(@value.to_i) data end |
#colored? ⇒ Boolean
Output is colored when it has AssetID and a positive value.
42 43 44 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 42 def colored? !!@asset_id && has_value? end |
#has_value? ⇒ Boolean
46 47 48 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 46 def has_value? !!@value && @value > 0 end |
#marker? ⇒ Boolean
90 91 92 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 90 def marker? !!marker end |
#outpoint ⇒ Object
106 107 108 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 106 def outpoint @transaction_output.outpoint end |
#outpoint_id ⇒ Object
110 111 112 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 110 def outpoint_id @transaction_output.outpoint_id end |
#parse_assets_data(data, offset: 0) ⇒ Object
Returns total length read
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 123 def parse_assets_data(data, offset: 0) v, len = WireFormat.read_uint8(data: data, offset: offset) raise ArgumentError, "Invalid data: verified flag" if !v asset_hash, len = WireFormat.read_string(data: data, offset: len) # empty or 20 bytes raise ArgumentError, "Invalid data: asset hash" if !asset_hash value, len = WireFormat.read_int64le(data: data, offset: len) raise ArgumentError, "Invalid data: value" if !value @verified = (v == 1) @asset_id = asset_hash.bytesize > 0 ? AssetID.new(hash: asset_hash) : nil @value = value len end |
#transaction_hash ⇒ Object
98 99 100 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 98 def transaction_hash @transaction_output.transaction_hash end |
#transaction_id ⇒ Object
102 103 104 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 102 def transaction_id @transaction_output.transaction_id end |
#verified? ⇒ Boolean
Output is verified when we know for sure if it's colored or not and if it is, what asset and how much is associated with it.
37 38 39 |
# File 'lib/btcruby/open_assets/asset_transaction_output.rb', line 37 def verified? !!@verified end |