Class: Eth::Contract::Function
- Inherits:
-
Object
- Object
- Eth::Contract::Function
- Defined in:
- lib/eth/contract/function.rb
Overview
Provides the methods for smart contract function.
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_signature(name, inputs) ⇒ String
Creates function strings.
-
.encoded_function_signature(signature) ⇒ String
Encodes a function signature.
Instance Method Summary collapse
-
#initialize(data) ⇒ Function
constructor
Constructor of the Function class.
Constructor Details
#initialize(data) ⇒ Function
Constructor of the Function class.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/eth/contract/function.rb', line 27 def initialize(data) @name = data["name"] @constant = data["constant"] @inputs = data["inputs"].map do |input| Eth::Contract::FunctionInput.new(input) end @outputs = data["outputs"].collect do |output| Eth::Contract::FunctionOutput.new(output) end @function_string = self.class.calc_signature(@name, @inputs) @signature = self.class.encoded_function_signature(@function_string) end |
Instance Attribute Details
#constant ⇒ Object
Returns the value of attribute constant.
22 23 24 |
# File 'lib/eth/contract/function.rb', line 22 def constant @constant end |
#function_string ⇒ Object
Returns the value of attribute function_string.
22 23 24 |
# File 'lib/eth/contract/function.rb', line 22 def function_string @function_string end |
#inputs ⇒ Object
Returns the value of attribute inputs.
22 23 24 |
# File 'lib/eth/contract/function.rb', line 22 def inputs @inputs end |
#name ⇒ Object
Returns the value of attribute name.
22 23 24 |
# File 'lib/eth/contract/function.rb', line 22 def name @name end |
#outputs ⇒ Object
Returns the value of attribute outputs.
22 23 24 |
# File 'lib/eth/contract/function.rb', line 22 def outputs @outputs end |
#signature ⇒ Object
Returns the value of attribute signature.
22 23 24 |
# File 'lib/eth/contract/function.rb', line 22 def signature @signature end |
Class Method Details
.calc_signature(name, inputs) ⇒ String
Creates function strings.
45 46 47 |
# File 'lib/eth/contract/function.rb', line 45 def self.calc_signature(name, inputs) "#{name}(#{inputs.map { |x| x.parsed_type.to_s }.join(",")})" end |
.encoded_function_signature(signature) ⇒ String
Encodes a function signature.
53 54 55 |
# File 'lib/eth/contract/function.rb', line 53 def self.encoded_function_signature(signature) Util.bin_to_hex Util.keccak256(signature)[0..3] end |