ethereum.rb 2.1.7 → 2.1.8

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: e53cfb3e0ec04452936380a3efe4959598ee1551
4
- data.tar.gz: 86a0d4366ca9796e9d9efa1b1f5bb90c89728522
3
+ metadata.gz: afa7f2461a4f8f594fc3e8d57cf53d92e8540a55
4
+ data.tar.gz: 88e3b4d2066800644e8f1b82a6afaf8eb876fa47
5
5
  SHA512:
6
- metadata.gz: e9d8cc30f9d56fec26463ba96040f687db1872e69c8c343c6e6d25aecc6d8e8289cb7ce5207e8d0eade0d70a07889955a92777f41cc0daf4580d1d67e7c0009d
7
- data.tar.gz: 402a8b9741e1700b2561b76c1217c6a22e7b53c2340665bdf469895381303c94168e836801f9d74e0ab406aad53ed5d38770475f8345fe82066581260c74e796
6
+ metadata.gz: 1caa864078b37ff71e1e48e779a6f595a42a31e8bd839bf8cd886a397ab90efd6dbee68f4f22e858df89aa227497450ef5a3d04c62a2aec48a0a85fc2d3a3294
7
+ data.tar.gz: 28eaa1419c7cde34d3daadc452178d03baa92fd24b49a85b1768896c2b678438105ce4e0f4289ec828603d7c7f8fa5320d4cb6c29ebb11324ae161ce19b261dd
@@ -52,7 +52,7 @@ And then execute:
52
52
 
53
53
  Or install it yourself as:
54
54
 
55
- $ gem install ethereum.eb
55
+ $ gem install ethereum.rb
56
56
 
57
57
  ### Running a node
58
58
 
data/README.md CHANGED
@@ -37,7 +37,7 @@ And then execute:
37
37
 
38
38
  Or install it yourself as:
39
39
 
40
- $ gem install ethereum.eb
40
+ $ gem install ethereum.rb
41
41
 
42
42
  ## Basic Usage
43
43
 
@@ -70,7 +70,7 @@ contract2 = MyContract2.new
70
70
  contract2 = contract.deploy_and_wait
71
71
  ```
72
72
 
73
- All names used to name contract in solidity source will transalte to name of classes in ruby (camelized).
73
+ All names used to name contract in solidity source will translate to name of classes in ruby (camelized).
74
74
 
75
75
  Note: If class of given name exist it will be undefined first to avoid name collision.
76
76
 
@@ -73,7 +73,7 @@ module Ethereum
73
73
  end
74
74
 
75
75
  def get_nonce(address)
76
- eth_get_transaction_count(address)["result"].to_i(16)
76
+ eth_get_transaction_count(address, "latest")["result"].to_i(16)
77
77
  end
78
78
 
79
79
 
@@ -25,12 +25,16 @@ module Ethereum
25
25
  @gas_price = @client.gas_price
26
26
  end
27
27
 
28
- def self.create(file: nil, client: Ethereum::Singleton.instance, code: nil, abi: nil, address: nil, name: nil)
28
+ def self.create(file: nil, client: Ethereum::Singleton.instance, code: nil, abi: nil, address: nil, name: nil, contract_index: nil)
29
29
  contract = nil
30
30
  if file.present?
31
31
  contracts = Ethereum::Initializer.new(file, client).build_all
32
- raise "No contracts complied" if contracts.empty?
33
- contract = contracts.first.class_object.new
32
+ raise "No contracts compiled" if contracts.empty?
33
+ if contract_index
34
+ contract = contracts[contract_index].class_object.new
35
+ else
36
+ contract = contracts.first.class_object.new
37
+ end
34
38
  else
35
39
  abi = JSON.parse(abi) if abi.is_a? String
36
40
  contract = Ethereum::Contract.new(name, code, abi, client)
@@ -69,7 +73,7 @@ module Ethereum
69
73
  Eth.configure { |c| c.chain_id = @client.net_version["result"].to_i }
70
74
  @nonce ||= @client.get_nonce(key.address) - 1
71
75
  @nonce += 1
72
- args = {
76
+ args = {
73
77
  from: key.address,
74
78
  value: 0,
75
79
  data: payload,
@@ -163,11 +167,11 @@ module Ethereum
163
167
  logs["result"].each do |result|
164
168
  inputs = evt.input_types
165
169
  outputs = inputs.zip(result["topics"][1..-1])
166
- data = {blockNumber: result["blockNumber"].hex, transactionHash: result["transactionHash"], blockHash: result["blockHash"], transactionIndex: result["transactionIndex"].hex, topics: []}
170
+ data = {blockNumber: result["blockNumber"].hex, transactionHash: result["transactionHash"], blockHash: result["blockHash"], transactionIndex: result["transactionIndex"].hex, topics: []}
167
171
  outputs.each do |output|
168
172
  data[:topics] << formatter.from_payload(output)
169
173
  end
170
- collection << data
174
+ collection << data
171
175
  end
172
176
  return collection
173
177
  end
@@ -18,7 +18,7 @@ module Ethereum
18
18
 
19
19
  def mined?
20
20
  return true if @mined
21
- @mined = @connection.get_transaction_by_hash(@id)["result"]["blockNumber"].present? rescue nil
21
+ @mined = @connection.eth_get_transaction_by_hash(@id)["result"]["blockNumber"].present?
22
22
  @mined ||= false
23
23
  end
24
24
 
@@ -39,9 +39,9 @@ module Ethereum
39
39
  start_time = Time.now
40
40
  loop do
41
41
  raise "Transaction #{@id} timed out." if ((Time.now - start_time) > timeout)
42
- sleep step
43
42
  yield if block_given?
44
43
  return true if deployed?
44
+ sleep step
45
45
  end
46
46
  end
47
47
 
@@ -56,9 +56,9 @@ module Ethereum
56
56
  def encode_bytes(value, subtype)
57
57
  subtype.nil? ? encode_dynamic_bytes(value) : encode_static_bytes(value)
58
58
  end
59
-
59
+
60
60
  def encode_static_bytes(value)
61
- value.each_char.map {|x| x.ord.to_s(16)}.join("").ljust(64, '0')
61
+ value.bytes.map {|x| x.to_s(16).rjust(2, '0')}.join("").ljust(64, '0')
62
62
  end
63
63
 
64
64
  def encode_dynamic_bytes(value)
@@ -71,7 +71,7 @@ module Ethereum
71
71
  def encode_string(value, _)
72
72
  location = encode_uint(@inputs ? size_of_inputs(@inputs) + @tail.size/2 : 32)
73
73
  size = encode_uint(value.bytes.size)
74
- content = value.bytes.map {|x| x.to_s(16)}.join("").ljust(64, '0')
74
+ content = value.bytes.map {|x| x.to_s(16).rjust(2, '0')}.join("").ljust(64, '0')
75
75
  [location, size + content]
76
76
  end
77
77
 
@@ -50,7 +50,7 @@ module Ethereum
50
50
  return nil if hexstring.nil?
51
51
  hexstring.gsub(/^0x/,'').scan(/.{2}/).collect {|x| x.hex}.pack("c*")
52
52
  end
53
-
53
+
54
54
  def to_utf8(hexstring)
55
55
  return nil if hexstring.nil?
56
56
  hexstring.gsub(/^0x/,'').scan(/.{2}/).collect {|x| x.hex}.pack("U*").delete("\u0000")
@@ -63,7 +63,7 @@ module Ethereum
63
63
 
64
64
  def from_utf8(utf8_string)
65
65
  return nil if utf8_string.nil?
66
- utf8_string.force_encoding('UTF-8').split("").collect {|x| x.ord.to_s(16)}.join("")
66
+ utf8_string.force_encoding('UTF-8').split("").collect {|x| x.ord.to_s(16).rjust(2, '0')}.join("")
67
67
  end
68
68
 
69
69
  def to_address(hexstring)
@@ -144,4 +144,3 @@ module Ethereum
144
144
  end
145
145
 
146
146
  end
147
-
@@ -1,4 +1,5 @@
1
1
  require 'net/http'
2
+ require 'json'
2
3
  module Ethereum
3
4
  class HttpClient < Client
4
5
  attr_accessor :host, :port, :uri, :ssl
@@ -30,8 +31,10 @@ module Ethereum
30
31
  return response.body
31
32
  end
32
33
 
33
- def send_batch(_batch)
34
- raise NotImplementedError
34
+ def send_batch(batch)
35
+ result = send_single(batch.to_json)
36
+ result = JSON.parse(result)
37
+ return result.sort_by! { |c| c['id'] }
35
38
  end
36
39
  end
37
40
 
@@ -1,6 +1,10 @@
1
1
  module Ethereum
2
2
 
3
3
  class Transaction
4
+
5
+ DEFAULT_TIMEOUT = 300.seconds
6
+ DEFAULT_STEP = 5.seconds
7
+
4
8
  attr_accessor :id, :mined, :connection, :input, :input_parameters
5
9
 
6
10
  def initialize(id, connection, data, input_parameters = [])
@@ -20,12 +24,12 @@ module Ethereum
20
24
  @mined = @connection.eth_get_transaction_by_hash(@id)["result"]["blockNumber"].present?
21
25
  end
22
26
 
23
- def wait_for_miner(timeout = 1500.seconds)
27
+ def wait_for_miner(timeout: DEFAULT_TIMEOUT, step: DEFAULT_STEP)
24
28
  start_time = Time.now
25
- while self.mined? == false
29
+ loop do
26
30
  raise Timeout::Error if ((Time.now - start_time) > timeout)
27
- sleep 5
28
31
  return true if self.mined?
32
+ sleep step
29
33
  end
30
34
  end
31
35
 
@@ -1,3 +1,3 @@
1
1
  module Ethereum
2
- VERSION = "2.1.7"
2
+ VERSION = "2.1.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethereum.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.7
4
+ version: 2.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Kirejczyk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-25 00:00:00.000000000 Z
11
+ date: 2017-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler