Class: EPM::Transact

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

Instance Method Summary collapse

Constructor Details

#initialize(recipient, data, settings = {}) ⇒ Transact

Returns a new instance of Transact.



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

def initialize recipient, data, settings={}
  @uri       = URI.parse "http://localhost:#{settings['json-port']}"
  setup settings
  @recipient = EPM::HexData.hex_guard recipient
  @data      = EPM::HexData.construct_data data
end

Instance Method Details

#setup(settings) ⇒ Object



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

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

#transact(value = '') ⇒ Object



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

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