etheruby 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69a49c095a9ddcee44a49105c2f212329520e0e7
4
- data.tar.gz: 44d3ffb4f1a9bc0c12e3fbb48d7c2284c14b7c33
3
+ metadata.gz: af7e8f1646fb49e6c917b515320bc07b9f9413a8
4
+ data.tar.gz: 799fc6b8aefea6413ae6d664db3620788ea625ac
5
5
  SHA512:
6
- metadata.gz: 64bee06d5c9bd73351cca313b7ac428c9e46d267f5838c88b91f8583cfd6bc5d6afea8ae6fb97918b358a92a356c4e912dd0e6ab55fb94467489706765cc1ee3
7
- data.tar.gz: 7b7739089daacb4b704ad68ea03098058821661e6849d8d3a9be2d90bb12c6da98619f7d862355e5aaaffabf8ee351427c9ba3926722812735a917dc98f65c85
6
+ metadata.gz: 2c997b1010710a80a3e28f28511cb4de3518cbca6d9ee1a186f484b89021dca5078029d11903deacff7280768ddcd0c3eca10307e04b66507726b8fff54b1a88
7
+ data.tar.gz: 158181e1ed668c808d58ab4cbc82bd8e86c4e6ca001e0a39754f571153e6a928e487194855339f1bbacd87241e124bc3f8d7dfb40fae6a7154388904d1a423bc
@@ -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
- else
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
- end
54
- if method_info.has_key? :returns
55
- ResponseParser.new(method_info[:returns], response['result']).parse
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['result']
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
- Client.eth.call composed_body, "latest"
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
@@ -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
- Etheruby::Client.uri = app.config.etheruby_uri if app.config.respond_to? :etheruby_uri
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
- if returns.count == 1
18
- v, s = Etheruby::treat_variable(returns[0], response, :decode)
19
- v = v.decode if v.is_a? Etheruby::Encoders::DynamicArray or v.is_a? Etheruby::Encoders::StaticArray
20
- v
21
- else
22
- real_response = @response
23
- values = []
24
- i = 0
25
- loop do
26
- return_type = returns[i]
27
- if Etheruby::is_static_type?(return_type)
28
- v, s = Etheruby::treat_variable(return_type, real_response, :decode)
29
- else
30
- value_position, s = Etheruby::Encoders::Uint.new(real_response).decode
31
- v, take_size = Etheruby::treat_variable(
32
- return_type,
33
- @response[(value_position*2)..response.length],
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etheruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérémy SEBAN