Class: Etheruby::ContractMethodDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/etheruby/contract_method_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ContractMethodDSL

Returns a new instance of ContractMethodDSL.



9
10
11
# File 'lib/etheruby/contract_method_dsl.rb', line 9

def initialize(name)
  @data = { name: name }
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/etheruby/contract_method_dsl.rb', line 7

def data
  @data
end

Instance Method Details

#array(type, size = nil) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/etheruby/contract_method_dsl.rb', line 17

def array(type, size=nil)
  if size
    "#{type}[#{size}]"
  else
    "#{type}[]"
  end
end

#force_transaction!Object



45
46
47
# File 'lib/etheruby/contract_method_dsl.rb', line 45

def force_transaction!
  data[:force_transac] = true
end

#from(_address) ⇒ Object



29
30
31
# File 'lib/etheruby/contract_method_dsl.rb', line 29

def from(_address)
  data[:from] = "0x#{_address.to_s(16)}"
end

#gas(_gas) ⇒ Object



33
34
35
# File 'lib/etheruby/contract_method_dsl.rb', line 33

def gas(_gas)
  data[:gas] = "0x#{_gas.to_s(16)}"
end

#gasPrice(_gp) ⇒ Object



37
38
39
# File 'lib/etheruby/contract_method_dsl.rb', line 37

def gasPrice(_gp)
  data[:gasPrice] = "0x#{_gas.to_s(16)}"
end

#parameters(*args) ⇒ Object



13
14
15
# File 'lib/etheruby/contract_method_dsl.rb', line 13

def parameters(*args)
  data[:params] = args
end

#returns(args) ⇒ Object



25
26
27
# File 'lib/etheruby/contract_method_dsl.rb', line 25

def returns(args)
  data[:returns] = args
end

#validate!Object



49
50
51
52
53
54
55
# File 'lib/etheruby/contract_method_dsl.rb', line 49

def validate!
  data[:params] = [] unless data.has_key? :params
  signature = "#{@data[:name]}(#{data[:params].join(',')})"
  hashed_signature = ::SHA3::Digest.new(:sha256).hexdigest(signature)
  data[:signature] = "0x#{hashed_signature[0..7]}"
  data
end

#value(_v) ⇒ Object



41
42
43
# File 'lib/etheruby/contract_method_dsl.rb', line 41

def value(_v)
  data[:value] = "0x#{_gas.to_s(16)}"
end