Class: BTC::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/btcruby/open_assets/asset.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(asset_id: nil, script: nil, output: nil, network: nil) ⇒ Asset

Initializes assets with one of the following:

  • script - a BTC::Script instance.
  • output - a BTC::TransactionOutput instance that issues the asset.
  • asset_id - a Base58 identifier of the asset or BTC::AssetID instance.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/btcruby/open_assets/asset.rb', line 20

def initialize(asset_id: nil, script: nil, output: nil, network: nil)
  if script || output
    script ||= output.script
    @output = output
    @script = script
    @identifier_binary = BTC::Data.hash160(script.data)
    @asset_id = AssetID.new(hash: @identifier_binary, network: network)
  elsif asset_id
    @asset_id = Address.parse(asset_id)
    @identifier_binary = @asset_id.hash
  else
    raise ArgumentError, "Either asset_id, script or output must be specified."
  end
end

Instance Attribute Details

#asset_idObject

BTC::AssetID instance identifying this asset.



7
8
9
# File 'lib/btcruby/open_assets/asset.rb', line 7

def asset_id
  @asset_id
end

#identifier_binaryObject

Binary 160-bit identifier of the asset (same as asset_id.hash)



10
11
12
# File 'lib/btcruby/open_assets/asset.rb', line 10

def identifier_binary
  @identifier_binary
end

#outputObject

Returns the value of attribute output.



14
15
16
# File 'lib/btcruby/open_assets/asset.rb', line 14

def output
  @output
end

#scriptObject

Optional attributes, set either by initializer when possible, or externally.



13
14
15
# File 'lib/btcruby/open_assets/asset.rb', line 13

def script
  @script
end