Class: OpenAssets::Protocol::AssetDefinitionLoader
- Inherits:
-
Object
- Object
- OpenAssets::Protocol::AssetDefinitionLoader
- 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
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
Class Method Summary collapse
-
.create_pointer_p2sh(url, to) ⇒ Object
create ps2s script which specify asset definition pointer @param url The asset definition url.
-
.create_pointer_redeem_script(url, to) ⇒ Object
create redeem script of asset definition file using p2sh @param url The asset definition url.
Instance Method Summary collapse
-
#initialize(url) ⇒ AssetDefinitionLoader
constructor
A new instance of AssetDefinitionLoader.
-
#load_definition ⇒ Object
load Asset Definition File @return loaded asset definition object.
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
#loader ⇒ Object (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
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
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_definition ⇒ Object
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 |