Class: Trx::Abi::Function
- Inherits:
-
Object
- Object
- Trx::Abi::Function
- Defined in:
- lib/trx/abi/function.rb
Instance Attribute Summary collapse
-
#constant ⇒ Object
Returns the value of attribute constant.
-
#function_string ⇒ Object
Returns the value of attribute function_string.
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#name ⇒ Object
Returns the value of attribute name.
-
#outputs ⇒ Object
Returns the value of attribute outputs.
-
#signature ⇒ Object
Returns the value of attribute signature.
Class Method Summary collapse
- .calc_id(signature) ⇒ Object
- .calc_signature(name, inputs) ⇒ Object
- .to_canonical_type(type) ⇒ Object
Instance Method Summary collapse
-
#initialize(data) ⇒ Function
constructor
A new instance of Function.
Constructor Details
#initialize(data) ⇒ Function
Returns a new instance of Function.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/trx/abi/function.rb', line 7 def initialize(data) @name = data["name"] @constant = data["constant"] @inputs = data.fetch("inputs", []).map do |input| FunctionInput.new(input) end @outputs = data.fetch("outputs", []).map do |output| FunctionOutput.new(output) end @function_string = self.class.calc_signature(@name, @inputs) @signature = self.class.calc_id(@function_string) end |
Instance Attribute Details
#constant ⇒ Object
Returns the value of attribute constant.
5 6 7 |
# File 'lib/trx/abi/function.rb', line 5 def constant @constant end |
#function_string ⇒ Object
Returns the value of attribute function_string.
5 6 7 |
# File 'lib/trx/abi/function.rb', line 5 def function_string @function_string end |
#inputs ⇒ Object
Returns the value of attribute inputs.
5 6 7 |
# File 'lib/trx/abi/function.rb', line 5 def inputs @inputs end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/trx/abi/function.rb', line 5 def name @name end |
#outputs ⇒ Object
Returns the value of attribute outputs.
5 6 7 |
# File 'lib/trx/abi/function.rb', line 5 def outputs @outputs end |
#signature ⇒ Object
Returns the value of attribute signature.
5 6 7 |
# File 'lib/trx/abi/function.rb', line 5 def signature @signature end |
Class Method Details
.calc_id(signature) ⇒ Object
32 33 34 |
# File 'lib/trx/abi/function.rb', line 32 def self.calc_id(signature) Digest::Keccak.hexdigest(signature, 256)[0..7] end |
.calc_signature(name, inputs) ⇒ Object
28 29 30 |
# File 'lib/trx/abi/function.rb', line 28 def self.calc_signature(name, inputs) "#{name}(#{inputs.map {|x| self.to_canonical_type(x.type) }.join(",")})" end |
.to_canonical_type(type) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/trx/abi/function.rb', line 20 def self.to_canonical_type(type) type .gsub(/(int)(\z|\D)/, '\1256\2') .gsub(/(uint)(\z|\D)/, '\1256\2') .gsub(/(fixed)(\z|\D)/, '\1128x128\2') .gsub(/(ufixed)(\z|\D)/, '\1128x128\2') end |