etheruby 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/etheruby/contract.rb +39 -7
 - data/lib/etheruby/railtie.rb +8 -2
 - data/lib/etheruby/response_parser.rb +25 -25
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: af7e8f1646fb49e6c917b515320bc07b9f9413a8
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 799fc6b8aefea6413ae6d664db3620788ea625ac
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2c997b1010710a80a3e28f28511cb4de3518cbca6d9ee1a186f484b89021dca5078029d11903deacff7280768ddcd0c3eca10307e04b66507726b8fff54b1a88
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 158181e1ed668c808d58ab4cbc82bd8e86c4e6ca001e0a39754f571153e6a928e487194855339f1bbacd87241e124bc3f8d7dfb40fae6a7154388904d1a423bc
         
     | 
    
        data/lib/etheruby/contract.rb
    CHANGED
    
    | 
         @@ -5,6 +5,22 @@ require_relative 'response_parser' 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            module Etheruby
         
     | 
| 
       7 
7 
     | 
    
         
             
              class NoContractMethodError < StandardError; end
         
     | 
| 
      
 8 
     | 
    
         
            +
              class NoPasswordForAddress < StandardError; end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              class TransactionInformation
         
     | 
| 
      
 11 
     | 
    
         
            +
                @@info = nil
         
     | 
| 
      
 12 
     | 
    
         
            +
                def self.information=(_info)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @@info = _info
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
                def self.set?() @@set end
         
     | 
| 
      
 16 
     | 
    
         
            +
                def self.default_from() @@info[:default_from] end
         
     | 
| 
      
 17 
     | 
    
         
            +
                def self.address_password(address)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  unless @@info
         
     | 
| 
      
 19 
     | 
    
         
            +
                    raise NoPasswordForAddress.new("No password for address #{address}")
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @@info[:addresses][address]
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
       8 
24 
     | 
    
         | 
| 
       9 
25 
     | 
    
         
             
              def contract
         
     | 
| 
       10 
26 
     | 
    
         
             
                Class.new do
         
     | 
| 
         @@ -46,20 +62,36 @@ module Etheruby 
     | 
|
| 
       46 
62 
     | 
    
         
             
                    }
         
     | 
| 
       47 
63 
     | 
    
         
             
                    @@logger.debug("Calling #{method_info[:name]} with parameters #{composed_body.inspect}")
         
     | 
| 
       48 
64 
     | 
    
         
             
                    response = call_api composed_body
         
     | 
| 
       49 
     | 
    
         
            -
                    if response.has_key? 'error'
         
     | 
| 
      
 65 
     | 
    
         
            +
                    if response.is_a? Hash and response.has_key? 'error'
         
     | 
| 
       50 
66 
     | 
    
         
             
                      @@logger.error("Failed contract execution #{response['error']['message']}")
         
     | 
| 
       51 
     | 
    
         
            -
                     
     | 
| 
      
 67 
     | 
    
         
            +
                    elsif response.is_a? Hash and response.has_key? 'result'
         
     | 
| 
       52 
68 
     | 
    
         
             
                      @@logger.debug("Response from API for #{method_info[:name]} : #{response.inspect}")
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                       
     | 
| 
      
 69 
     | 
    
         
            +
                      if method_info.has_key? :returns
         
     | 
| 
      
 70 
     | 
    
         
            +
                        ResponseParser.new(method_info[:returns], response['result']).parse
         
     | 
| 
      
 71 
     | 
    
         
            +
                      else
         
     | 
| 
      
 72 
     | 
    
         
            +
                        response['result']
         
     | 
| 
      
 73 
     | 
    
         
            +
                      end
         
     | 
| 
       56 
74 
     | 
    
         
             
                    else
         
     | 
| 
       57 
     | 
    
         
            -
                      response 
     | 
| 
      
 75 
     | 
    
         
            +
                      @@logger.error("Failed contract execution response : #{response.inspect}")
         
     | 
| 
       58 
76 
     | 
    
         
             
                    end
         
     | 
| 
       59 
77 
     | 
    
         
             
                  end
         
     | 
| 
       60 
78 
     | 
    
         | 
| 
       61 
79 
     | 
    
         
             
                  def self.call_api(composed_body)
         
     | 
| 
       62 
     | 
    
         
            -
                     
     | 
| 
      
 80 
     | 
    
         
            +
                    if composed_body.has_key? :gas or composed_body.has_key? :value
         
     | 
| 
      
 81 
     | 
    
         
            +
                      return do_eth_transaction(composed_body)
         
     | 
| 
      
 82 
     | 
    
         
            +
                    else
         
     | 
| 
      
 83 
     | 
    
         
            +
                      return do_eth_call(composed_body)
         
     | 
| 
      
 84 
     | 
    
         
            +
                    end
         
     | 
| 
      
 85 
     | 
    
         
            +
                  end
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                  def self.do_eth_call(composed_body)
         
     | 
| 
      
 88 
     | 
    
         
            +
                    Client.eth.call(composed_body, "latest")
         
     | 
| 
      
 89 
     | 
    
         
            +
                  end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                  def self.do_eth_transaction(composed_body)
         
     | 
| 
      
 92 
     | 
    
         
            +
                    from_address = composed_body[:from] || TransactionInformation.default_from
         
     | 
| 
      
 93 
     | 
    
         
            +
                    pwd = TransactionInformation.address_password(from_address)
         
     | 
| 
      
 94 
     | 
    
         
            +
                    return Client.personal.sendTransaction(composed_body.merge({from: from_address}), pwd)
         
     | 
| 
       63 
95 
     | 
    
         
             
                  end
         
     | 
| 
       64 
96 
     | 
    
         | 
| 
       65 
97 
     | 
    
         
             
                  def self.address
         
     | 
    
        data/lib/etheruby/railtie.rb
    CHANGED
    
    | 
         @@ -3,9 +3,15 @@ Dir["./app/contracts/**/*.rb"].each { |f| require f } 
     | 
|
| 
       3 
3 
     | 
    
         
             
            module Etheruby
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
              class Railtie < Rails::Railtie
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
6 
     | 
    
         
             
                initializer "etheruby.configure" do |app|
         
     | 
| 
       8 
     | 
    
         
            -
                   
     | 
| 
      
 7 
     | 
    
         
            +
                  if app.config.respond_to? :etheruby_uri
         
     | 
| 
      
 8 
     | 
    
         
            +
                    Etheruby::Client.uri = app.config.etheruby_uri
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  if app.config.respond_to? :etheruby_enable_transactions
         
     | 
| 
      
 12 
     | 
    
         
            +
                    Etheruby::TransactionInformation.information = \
         
     | 
| 
      
 13 
     | 
    
         
            +
                      app.config.etheruby_enable_transactions
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
       9 
15 
     | 
    
         
             
                end
         
     | 
| 
       10 
16 
     | 
    
         
             
              end
         
     | 
| 
       11 
17 
     | 
    
         | 
| 
         @@ -14,32 +14,32 @@ module Etheruby 
     | 
|
| 
       14 
14 
     | 
    
         
             
                end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                def parse
         
     | 
| 
       17 
     | 
    
         
            -
                   
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                     
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                     
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                       
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                          :decode
         
     | 
| 
       35 
     | 
    
         
            -
                        )
         
     | 
| 
       36 
     | 
    
         
            -
                      end
         
     | 
| 
       37 
     | 
    
         
            -
                      v = v.decode if v.is_a? Etheruby::Encoders::DynamicArray or v.is_a? Etheruby::Encoders::StaticArray
         
     | 
| 
       38 
     | 
    
         
            -
                      values << v
         
     | 
| 
       39 
     | 
    
         
            -
                      break if values.count == returns.count
         
     | 
| 
       40 
     | 
    
         
            -
                      real_response = real_response[s*2..real_response.length]
         
     | 
| 
       41 
     | 
    
         
            -
                      i += 1
         
     | 
| 
      
 17 
     | 
    
         
            +
                  real_response = @response
         
     | 
| 
      
 18 
     | 
    
         
            +
                  values = []
         
     | 
| 
      
 19 
     | 
    
         
            +
                  i = 0
         
     | 
| 
      
 20 
     | 
    
         
            +
                  loop do
         
     | 
| 
      
 21 
     | 
    
         
            +
                    return_type = returns[i]
         
     | 
| 
      
 22 
     | 
    
         
            +
                    if Etheruby::is_static_type?(return_type)
         
     | 
| 
      
 23 
     | 
    
         
            +
                      v, s = Etheruby::treat_variable(return_type, real_response, :decode)
         
     | 
| 
      
 24 
     | 
    
         
            +
                    else
         
     | 
| 
      
 25 
     | 
    
         
            +
                      value_position, s = Etheruby::Encoders::Uint.new(real_response).decode
         
     | 
| 
      
 26 
     | 
    
         
            +
                      v, take_size = Etheruby::treat_variable(
         
     | 
| 
      
 27 
     | 
    
         
            +
                        return_type,
         
     | 
| 
      
 28 
     | 
    
         
            +
                        @response[(value_position*2)..response.length],
         
     | 
| 
      
 29 
     | 
    
         
            +
                        :decode
         
     | 
| 
      
 30 
     | 
    
         
            +
                      )
         
     | 
| 
      
 31 
     | 
    
         
            +
                    end
         
     | 
| 
      
 32 
     | 
    
         
            +
                    if v.is_a? Etheruby::Encoders::DynamicArray or v.is_a? Etheruby::Encoders::StaticArray
         
     | 
| 
      
 33 
     | 
    
         
            +
                      v, s = v.decode
         
     | 
| 
       42 
34 
     | 
    
         
             
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
                    values << v
         
     | 
| 
      
 36 
     | 
    
         
            +
                    break if values.count == returns.count
         
     | 
| 
      
 37 
     | 
    
         
            +
                    real_response = real_response[s*2..real_response.length]
         
     | 
| 
      
 38 
     | 
    
         
            +
                    i += 1
         
     | 
| 
      
 39 
     | 
    
         
            +
                  end
         
     | 
| 
      
 40 
     | 
    
         
            +
                  if values.count == 1
         
     | 
| 
      
 41 
     | 
    
         
            +
                    values[0]
         
     | 
| 
      
 42 
     | 
    
         
            +
                  else
         
     | 
| 
       43 
43 
     | 
    
         
             
                    values
         
     | 
| 
       44 
44 
     | 
    
         
             
                  end
         
     | 
| 
       45 
45 
     | 
    
         
             
                end
         
     |