Class: OpenAssets::Protocol::MarkerOutput
- Inherits:
-
Object
- Object
- OpenAssets::Protocol::MarkerOutput
- Extended by:
- Util
- Includes:
- Util
- Defined in:
- lib/openassets/protocol/marker_output.rb
Constant Summary collapse
- MAX_ASSET_QUANTITY =
2 ** 63 -1
- OAP_MARKER =
A tag indicating thath this transaction is an Open Assets transaction.
"4f41"
- VERSION =
The major revision number of the Open Assets Protocol.(1=0x0100)
"0100"
Constants included from Util
Util::OA_NAMESPACE, Util::OA_VERSION_BYTE, Util::OA_VERSION_BYTE_TESTNET
Instance Attribute Summary collapse
-
#asset_quantities ⇒ Object
Returns the value of attribute asset_quantities.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
Class Method Summary collapse
-
.deserialize_payload(payload) ⇒ OpenAssets::Protocol::MarkerOutput
Deserialize the marker output payload.
-
.parse_script(output_script) ⇒ String
Parses an output and returns the payload if the output matches the right pattern for a marker output,.
Instance Method Summary collapse
-
#build_script ⇒ Bitcoin::Script
Creates an output script containing an OP_RETURN and a PUSHDATA from payload.
-
#initialize(asset_quantities, metadata = '') ⇒ MarkerOutput
constructor
A new instance of MarkerOutput.
-
#to_payload ⇒ String
Serialize the marker output into a Open Assets Payload buffer.
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(asset_quantities, metadata = '') ⇒ MarkerOutput
Returns a new instance of MarkerOutput.
21 22 23 24 |
# File 'lib/openassets/protocol/marker_output.rb', line 21 def initialize(asset_quantities, = '') @asset_quantities = asset_quantities @metadata = end |
Instance Attribute Details
#asset_quantities ⇒ Object
Returns the value of attribute asset_quantities.
16 17 18 |
# File 'lib/openassets/protocol/marker_output.rb', line 16 def asset_quantities @asset_quantities end |
#metadata ⇒ Object
Returns the value of attribute metadata.
17 18 19 |
# File 'lib/openassets/protocol/marker_output.rb', line 17 def @metadata end |
Class Method Details
.deserialize_payload(payload) ⇒ OpenAssets::Protocol::MarkerOutput
Deserialize the marker output payload.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/openassets/protocol/marker_output.rb', line 43 def self.deserialize_payload(payload) return nil unless valid?(payload) payload = payload[8..-1] # exclude OAP_MARKER,VERSION asset_quantity, payload = parse_asset_qty(payload) list = to_bytes(payload).map{|x|(x.to_i(16)>=128 ? x : x+"|")}.join.split('|')[0..(asset_quantity - 1)].join asset_quantities = decode_leb128(list) = to_bytes(payload[list.size..-1]) = .empty? ? '' : [1..-1].map{|x|x.to_i(16).chr}.join new(asset_quantities, ) end |
.parse_script(output_script) ⇒ String
Parses an output and returns the payload if the output matches the right pattern for a marker output,
57 58 59 60 |
# File 'lib/openassets/protocol/marker_output.rb', line 57 def self.parse_script(output_script) data = Bitcoin::Script.new(output_script).get_op_return_data return data if valid?(data) end |
Instance Method Details
#build_script ⇒ Bitcoin::Script
Creates an output script containing an OP_RETURN and a PUSHDATA from payload.
64 65 66 |
# File 'lib/openassets/protocol/marker_output.rb', line 64 def build_script Bitcoin::Script.from_string("OP_RETURN #{to_payload}") end |
#to_payload ⇒ String
Serialize the marker output into a Open Assets Payload buffer.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/openassets/protocol/marker_output.rb', line 28 def to_payload payload = [OAP_MARKER, VERSION] asset_quantity_count = Bitcoin::Protocol.pack_var_int(@asset_quantities.length).unpack("H*") payload << sort_count(asset_quantity_count[0]) @asset_quantities.map{|q|payload << encode_leb128(q)} @metadata ||= '' = Bitcoin::Protocol.pack_var_int(@metadata.length).unpack("H*") payload << sort_count([0]) payload << @metadata.bytes.map{|b| sprintf("%02x", b)}.join payload.join end |