Class: OpenAssets::Protocol::TransactionOutput
- Inherits:
-
Object
- Object
- OpenAssets::Protocol::TransactionOutput
- Defined in:
- lib/openassets/protocol/transaction_output.rb
Overview
Represents a transaction output and its asset ID and asset quantity.
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#asset_definition_url ⇒ Object
Returns the value of attribute asset_definition_url.
-
#asset_id ⇒ Object
Returns the value of attribute asset_id.
-
#asset_quantity ⇒ Object
Returns the value of attribute asset_quantity.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#output_type ⇒ Object
Returns the value of attribute output_type.
-
#script ⇒ Object
Returns the value of attribute script.
-
#valid_asset_definition ⇒ Object
Returns the value of attribute valid_asset_definition.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#asset_amount ⇒ Object
calculate asset amount.
-
#divisibility ⇒ Object
get divisibility defined by asset definition file.
-
#initialize(value, script, asset_id = nil, asset_quantity = 0, output_type = OutputType::UNCOLORED, metadata = '') ⇒ TransactionOutput
constructor
A new instance of TransactionOutput.
Constructor Details
#initialize(value, script, asset_id = nil, asset_quantity = 0, output_type = OutputType::UNCOLORED, metadata = '') ⇒ TransactionOutput
Returns a new instance of TransactionOutput.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/openassets/protocol/transaction_output.rb', line 25 def initialize(value, script, asset_id = nil, asset_quantity = 0, output_type = OutputType::UNCOLORED, = '') raise ArgumentError, "invalid output_type : #{output_type}" unless OutputType.all.include?(output_type) raise ArgumentError, "invalid asset_quantity. asset_quantity should be unsignd integer. " unless asset_quantity.between?(0, MarkerOutput::MAX_ASSET_QUANTITY) @value = value @script = script @asset_id = asset_id @asset_quantity = asset_quantity @output_type = output_type = load_asset_definition_url end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
14 15 16 |
# File 'lib/openassets/protocol/transaction_output.rb', line 14 def account @account end |
#asset_definition_url ⇒ Object
Returns the value of attribute asset_definition_url.
16 17 18 |
# File 'lib/openassets/protocol/transaction_output.rb', line 16 def asset_definition_url @asset_definition_url end |
#asset_id ⇒ Object
Returns the value of attribute asset_id.
10 11 12 |
# File 'lib/openassets/protocol/transaction_output.rb', line 10 def asset_id @asset_id end |
#asset_quantity ⇒ Object
Returns the value of attribute asset_quantity.
11 12 13 |
# File 'lib/openassets/protocol/transaction_output.rb', line 11 def asset_quantity @asset_quantity end |
#metadata ⇒ Object
Returns the value of attribute metadata.
15 16 17 |
# File 'lib/openassets/protocol/transaction_output.rb', line 15 def end |
#output_type ⇒ Object
Returns the value of attribute output_type.
12 13 14 |
# File 'lib/openassets/protocol/transaction_output.rb', line 12 def output_type @output_type end |
#script ⇒ Object
Returns the value of attribute script.
9 10 11 |
# File 'lib/openassets/protocol/transaction_output.rb', line 9 def script @script end |
#valid_asset_definition ⇒ Object
Returns the value of attribute valid_asset_definition.
17 18 19 |
# File 'lib/openassets/protocol/transaction_output.rb', line 17 def valid_asset_definition @valid_asset_definition end |
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/openassets/protocol/transaction_output.rb', line 8 def value @value end |
Instance Method Details
#asset_amount ⇒ Object
calculate asset amount. asset amount is the value obtained by converting the asset quantity to the unit of divisibility that are defined in the Asset definition file.
39 40 41 42 |
# File 'lib/openassets/protocol/transaction_output.rb', line 39 def asset_amount d = divisibility d > 0 ? (@asset_quantity.to_f / (10 ** d)).to_f : @asset_quantity end |
#divisibility ⇒ Object
get divisibility defined by asset definition file.
45 46 47 48 49 |
# File 'lib/openassets/protocol/transaction_output.rb', line 45 def divisibility return 0 unless @valid_asset_definition json = (json.nil? || json.length == 0) ? 0 : json['divisibility'] end |