Sha256: 835b76e9da3697487611f1e4bd7db4de1e03e4e99cfac5b3ca93461a7d994f65
Contents?: true
Size: 1003 Bytes
Versions: 4
Compression:
Stored size: 1003 Bytes
Contents
module Platon class Function attr_accessor :name, :inputs, :outputs, :signature, :constant, :function_string def initialize(data) @name = data["name"] @constant = data["constant"] @inputs = data["inputs"].map do |input| Platon::FunctionInput.new(input) end @outputs = data["outputs"].collect do |output| Platon::FunctionOutput.new(output) end @function_string = self.class.calc_signature(@name, @inputs) @signature = self.class.calc_id(@function_string) end 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 def self.calc_signature(name, inputs) "#{name}(#{inputs.collect {|x| self.to_canonical_type(x.type) }.join(",")})" end def self.calc_id(signature) Digest::SHA3.hexdigest(signature, 256)[0..7] end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
platon-1.0.1 | lib/platon/function.rb |
platon-1.0.0 | lib/platon/function.rb |
platon-0.2.9 | lib/platon/function.rb |
platon-0.2.7 | lib/platon/function.rb |