Class: OpenAssets::Protocol::AssetDefinitionLoader

Inherits:
Object
  • Object
show all
Extended by:
Bitcoin::Util, Util
Defined in:
lib/openassets/protocol/asset_definition_loader.rb

Constant Summary

Constants included from Util

Util::OA_NAMESPACE, Util::OA_VERSION_BYTE, Util::OA_VERSION_BYTE_TESTNET

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

address_to_oa_address, coin_to_satoshi, decode_leb128, encode_leb128, generate_asset_id, hash_to_asset_id, oa_address_to_address, pubkey_hash_to_asset_id, read_leb128, read_var_integer, satoshi_to_coin, script_to_address, script_to_asset_id, to_bytes, valid_asset_id?, validate_address

Constructor Details

#initialize(url) ⇒ AssetDefinitionLoader

Returns a new instance of AssetDefinitionLoader.



10
11
12
13
14
# File 'lib/openassets/protocol/asset_definition_loader.rb', line 10

def initialize(url)
  if url.start_with?('http://') || url.start_with?('https://')
    @loader = HttpAssetDefinitionLoader.new(url)
  end
end

Instance Attribute Details

#loaderObject (readonly)

Returns the value of attribute loader.



8
9
10
# File 'lib/openassets/protocol/asset_definition_loader.rb', line 8

def loader
  @loader
end

Class Method Details

.create_pointer_p2sh(url, to) ⇒ Object

create ps2s script which specify asset definition pointer @param url The asset definition url. @param to The open asset address to send the asset to. @return p2sh script.



37
38
39
40
# File 'lib/openassets/protocol/asset_definition_loader.rb', line 37

def self.create_pointer_p2sh(url, to)
  redeem_script = create_pointer_redeem_script(url, to)
  Bitcoin::Script.new(Bitcoin::Script.to_p2sh_script(hash160(redeem_script.to_payload.bth)))
end

.create_pointer_redeem_script(url, to) ⇒ Object

create redeem script of asset definition file using p2sh @param url The asset definition url. @param to The open asset address to send the asset to. @return redeem script.



26
27
28
29
30
31
# File 'lib/openassets/protocol/asset_definition_loader.rb', line 26

def self.create_pointer_redeem_script(url, to)
  asset_def = "u=#{url}".bytes.map{|b|b.to_s(16)}.join
  btc_addr = oa_address_to_address(to)
  script = Bitcoin::Script.from_string("#{asset_def}")
  Bitcoin::Script.new(script.append_opcode(Bitcoin::Script::OP_DROP).to_payload + Bitcoin::Script.to_address_script(btc_addr))
end

Instance Method Details

#load_definitionObject

load Asset Definition File @return loaded asset definition object



18
19
20
# File 'lib/openassets/protocol/asset_definition_loader.rb', line 18

def load_definition
  @loader.load if @loader
end