Class: EvmClient::Function
- Inherits:
-
Object
- Object
- EvmClient::Function
- Defined in:
- lib/evm_client/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.
-
#minified_signature ⇒ Object
Returns the value of attribute minified_signature.
-
#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.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/evm_client/function.rb', line 6 def initialize(data) @name = data["name"] @constant = data["constant"] @inputs = data["inputs"].map do |input| EvmClient::FunctionInput.new(input) end @outputs = data["outputs"].collect do |output| EvmClient::FunctionOutput.new(output) end @function_string = self.class.calc_signature(@name, @inputs) @signature = self.class.calc_id(@function_string) @minified_signature = signature[0..7] end |
Instance Attribute Details
#constant ⇒ Object
Returns the value of attribute constant.
4 5 6 |
# File 'lib/evm_client/function.rb', line 4 def constant @constant end |
#function_string ⇒ Object
Returns the value of attribute function_string.
4 5 6 |
# File 'lib/evm_client/function.rb', line 4 def function_string @function_string end |
#inputs ⇒ Object
Returns the value of attribute inputs.
4 5 6 |
# File 'lib/evm_client/function.rb', line 4 def inputs @inputs end |
#minified_signature ⇒ Object
Returns the value of attribute minified_signature.
4 5 6 |
# File 'lib/evm_client/function.rb', line 4 def minified_signature @minified_signature end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/evm_client/function.rb', line 4 def name @name end |
#outputs ⇒ Object
Returns the value of attribute outputs.
4 5 6 |
# File 'lib/evm_client/function.rb', line 4 def outputs @outputs end |
#signature ⇒ Object
Returns the value of attribute signature.
4 5 6 |
# File 'lib/evm_client/function.rb', line 4 def signature @signature end |
Class Method Details
.calc_id(signature) ⇒ Object
35 36 37 |
# File 'lib/evm_client/function.rb', line 35 def self.calc_id(signature) Digest::SHA3.hexdigest(signature, 256) end |
.calc_signature(name, inputs) ⇒ Object
31 32 33 |
# File 'lib/evm_client/function.rb', line 31 def self.calc_signature(name, inputs) "#{name}(#{inputs.collect {|x| self.to_canonical_type(x.type) }.join(",")})" end |
.to_canonical_type(type) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/evm_client/function.rb', line 23 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 |