Class: Keoken::Token
Instance Attribute Summary collapse
-
#data_script ⇒ Object
Returns the value of attribute data_script.
-
#id ⇒ Object
Returns the value of attribute id.
Attributes inherited from Parser
#amount, #data, #name, #transaction_type
Instance Method Summary collapse
-
#create(amount) ⇒ Keoken::Token
Generate the script to create a token.
-
#hex ⇒ String
Hexadecimal value of script.
-
#initialize(options = {}) ⇒ Token
constructor
Creates a new token object.
-
#send_amount(amount) ⇒ Keoken::Token
Generate the script to send an amount from one address to another.
-
#to_hash ⇒ Object
Deserialization of object.
-
#to_json ⇒ Object
JSON serialization of object.
Constructor Details
#initialize(options = {}) ⇒ Token
Creates a new token object.
12 13 14 15 16 17 18 |
# File 'lib/keoken/token.rb', line 12 def initialize( = {}) @name = [:name] @id = [:id] return unless [:script] super([:script]) parse_script end |
Instance Attribute Details
#data_script ⇒ Object
Returns the value of attribute data_script
3 4 5 |
# File 'lib/keoken/token.rb', line 3 def data_script @data_script end |
#id ⇒ Object
Returns the value of attribute id
3 4 5 |
# File 'lib/keoken/token.rb', line 3 def id @id end |
Instance Method Details
#create(amount) ⇒ Keoken::Token
Generate the script to create a token.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/keoken/token.rb', line 26 def create(amount) raise Keoken::Error::NameNotFound unless @name @data_script = [ Keoken::VERSION_NODE, Keoken::TYPE_CREATE_ASSET, name_to_hex(@name), Keoken::PREFIX_BYTE_AMOUNT[0..prefix_length(amount)] + amount.to_s(16) ].flatten.join self end |
#hex ⇒ String
Hexadecimal value of script.
60 61 62 63 64 65 66 67 |
# File 'lib/keoken/token.rb', line 60 def hex [ Bitcoin::Script::OP_RETURN.to_s(16), Keoken::PREFIX_SIZE, Keoken::PREFIX, data_length ].join + @data_script end |
#send_amount(amount) ⇒ Keoken::Token
Generate the script to send an amount from one address to another.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/keoken/token.rb', line 44 def send_amount(amount) raise Keoken::Error::IdNotFound unless @id asset_length = Keoken::ASSET_ID_SIZE - @id.to_s.length @data_script = [ Keoken::VERSION_NODE, Keoken::TYPE_SEND_TOKEN, Keoken::PREFIX_BYTE_ASSET_ID[0..(asset_length - 1)] + @id.to_s, Keoken::PREFIX_BYTE_AMOUNT[0..prefix_length(amount)] + amount.to_s(16) ].flatten.join self end |
#to_hash ⇒ Object
Deserialization of object
return [Hash] Deserialization of token object.
84 85 86 87 88 89 90 91 |
# File 'lib/keoken/token.rb', line 84 def to_hash { id: @id, name: @name, amount: @amount, transaction_type: @transaction_type } end |
#to_json ⇒ Object
JSON serialization of object
return [String] JSON serialization of token object.
72 73 74 75 76 77 78 79 |
# File 'lib/keoken/token.rb', line 72 def to_json { id: @id, name: @name, amount: @amount, transaction_type: @transaction_type }.to_json end |