Class: EPM::Create

Inherits:
Object
  • Object
show all
Defined in:
lib/epm/create.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, settings = {}) ⇒ Create

Returns a new instance of Create.



5
6
7
8
9
10
11
# File 'lib/epm/create.rb', line 5

def initialize file, settings={}
  if file
    @uri      = URI.parse "http://localhost:#{settings['json-port']}"
    setup settings
    @contract = EPM::Compile.new(file, @settings).compile
  end
end

Instance Method Details

#deployObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/epm/create.rb', line 13

def deploy
  if @settings['preferred-client'] == 'cpp'
    params = {
      'sec' => @settings["address-private-key"],
      'xEndowment' => '',
      'bCode' => @contract,
      'xGas' => '100000',
      'xGasPrice' => ( @settings['gas-price'] || '100000000000000' )
    }
    post_body   = { 'method' => 'create', 'params' => params, 'id' => 'epm-rpc', "jsonrpc" => "2.0" }.to_json
  elsif @settings['preferred-client'] == ('go' || 'ethereal')
    params = {
      'body' => @contract,
      'value' => '',
      'gas' => '100000',
      'gasprice' => ( @settings['gas-price'] || '100000000000000' )
    }
    post_body   = { 'method' => 'EthereumApi.Create', 'params' => params, 'id' => 'epm-rpc', 'jsonrpc' => '2.0'}.to_json
  end
  return EPM::Server.http_post_request @uri, post_body
end

#setup(settings) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/epm/create.rb', line 35

def setup settings
  unless settings.empty?
    @settings = settings
  else
    @settings = EPM::Settings.check
  end
end