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 +4 -4
- data/PREREQUISITES.md +1 -1
- data/README.md +2 -2
- data/lib/ethereum/client.rb +1 -1
- data/lib/ethereum/contract.rb +10 -6
- data/lib/ethereum/deployment.rb +2 -2
- data/lib/ethereum/encoder.rb +3 -3
- data/lib/ethereum/formatter.rb +2 -3
- data/lib/ethereum/http_client.rb +5 -2
- data/lib/ethereum/transaction.rb +7 -3
- data/lib/ethereum/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afa7f2461a4f8f594fc3e8d57cf53d92e8540a55
|
4
|
+
data.tar.gz: 88e3b4d2066800644e8f1b82a6afaf8eb876fa47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1caa864078b37ff71e1e48e779a6f595a42a31e8bd839bf8cd886a397ab90efd6dbee68f4f22e858df89aa227497450ef5a3d04c62a2aec48a0a85fc2d3a3294
|
7
|
+
data.tar.gz: 28eaa1419c7cde34d3daadc452178d03baa92fd24b49a85b1768896c2b678438105ce4e0f4289ec828603d7c7f8fa5320d4cb6c29ebb11324ae161ce19b261dd
|
data/PREREQUISITES.md
CHANGED
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.
|
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
|
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
|
|
data/lib/ethereum/client.rb
CHANGED
data/lib/ethereum/contract.rb
CHANGED
@@ -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
|
33
|
-
|
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
|
data/lib/ethereum/deployment.rb
CHANGED
@@ -18,7 +18,7 @@ module Ethereum
|
|
18
18
|
|
19
19
|
def mined?
|
20
20
|
return true if @mined
|
21
|
-
@mined = @connection.
|
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
|
|
data/lib/ethereum/encoder.rb
CHANGED
@@ -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.
|
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
|
|
data/lib/ethereum/formatter.rb
CHANGED
@@ -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
|
-
|
data/lib/ethereum/http_client.rb
CHANGED
@@ -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(
|
34
|
-
|
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
|
|
data/lib/ethereum/transaction.rb
CHANGED
@@ -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
|
27
|
+
def wait_for_miner(timeout: DEFAULT_TIMEOUT, step: DEFAULT_STEP)
|
24
28
|
start_time = Time.now
|
25
|
-
|
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
|
|
data/lib/ethereum/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|