class OpenAssets::Protocol::AssetDefinitionLoader

Attributes

loader[R]

Public Class Methods

create_pointer_p2sh(url, to) click to toggle source

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.

# 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) click to toggle source

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.

# 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
new(url) click to toggle source
# 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

Public Instance Methods

load_definition() click to toggle source

load Asset Definition File @return loaded asset definition object

# File lib/openassets/protocol/asset_definition_loader.rb, line 18
def load_definition
  @loader.load if @loader
end