Class: C3D::ConnectEth
- Inherits:
-
Object
- Object
- C3D::ConnectEth
- Includes:
- Celluloid
- Defined in:
- lib/c3d/connectors/connect_ethereum.rb
Instance Method Summary collapse
- #get_key ⇒ Object
- #get_storage_at(address, storage_location) ⇒ Object
-
#initialize(client) ⇒ ConnectEth
constructor
A new instance of ConnectEth.
- #transact(recipient, data = '', value = '', gas = '100000', gas_price = '100000000000000') ⇒ Object
Constructor Details
#initialize(client) ⇒ ConnectEth
Returns a new instance of ConnectEth.
7 8 9 10 11 12 13 14 15 |
# File 'lib/c3d/connectors/connect_ethereum.rb', line 7 def initialize client @client = client @uri = URI.parse "http://#{ENV['ETH_HOST']}:#{ENV['ETH_PORT']}" @question_socket = Net::HTTP.new @uri.host, @uri.port @request = Net::HTTP::Post.new @uri.request_uri @request.content_type = 'application/json' @last_push = Time.now puts "[C3D::#{Time.now.strftime( "%F %T" )}] c3D->eth via RPC on port >>\t#{ENV['ETH_PORT']}" end |
Instance Method Details
#get_key ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/c3d/connectors/connect_ethereum.rb', line 82 def get_key case @client when :go request = { id: 'c3d-client', method: "EthereumApi.GetKey", params: [{}] } when :cpp request = { id: 'c3d-client', method: "key", params: {}, jsonrpc: '2.0' } end send_command request end |
#get_storage_at(address, storage_location) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/c3d/connectors/connect_ethereum.rb', line 17 def get_storage_at address, storage_location address = guard_addresses address storage_location = guard_addresses storage_location case @client when :go request = { id: 'c3d-client', method: "EthereumApi.GetStorageAt", params: [{ address: address, key: storage_location }] } when :cpp request = { method: "storageAt", params: { a: address, x: storage_location }, id: 'c3d-client', jsonrpc: '2.0' } end send_command request end |
#transact(recipient, data = '', value = '', gas = '100000', gas_price = '100000000000000') ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/c3d/connectors/connect_ethereum.rb', line 46 def transact recipient, data='', value='', gas='100000', gas_price='100000000000000' sleep 0.5 if ( Time.now - @last_push < 0.5 ) recipient = guard_addresses recipient data = build_data data case @client when :go request = { id: 'c3d-client', method: "EthereumApi.Transact", params: [{ recipient: recipient, value: value, gas: gas, gasprice: gas_price }] } when :cpp request = { method: 'transact', params: { sec: ENV['ETH_KEY'], xValue: value.to_s, aDest: recipient, bData: data, xGas: gas.to_s, xGasPrice: gas_price.to_s }, id: 'c3d-client', jsonrpc: '2.0' } end @last_push = Time.now send_command request end |