ruby-ethereum 0.9.4 → 0.9.6
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/ethereum/abi/contract_translator.rb +1 -0
- data/lib/ethereum/tester/abi_contract.rb +5 -3
- data/lib/ethereum/tester/language.rb +2 -2
- data/lib/ethereum/tester/solidity_wrapper.rb +6 -2
- data/lib/ethereum/tester/state.rb +24 -14
- 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: b148ff5fc474e2b43055a78679a76e13911534ed
|
4
|
+
data.tar.gz: 8d19a27b24c3e44c6826418c6062d5d5feccc5c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bc3e0f52812048175c9e939ae8250f7a8086365970df3779ff0edfdd6a4faf88015c53365b8e72160739455fd5b2b9ea3c806140a2d6d1f6e8c7fbf0a302c39
|
7
|
+
data.tar.gz: 9e4c2c2a1182e11a4064a59fe4c8d50c6b51a1b5dcbb79d1407200156b919b6c1d4a7589fc7be4e74eea10859199d94301da44788eee470f7f3e5e08eab876c9
|
@@ -16,7 +16,9 @@ module Ethereum
|
|
16
16
|
if listen
|
17
17
|
listener = ->(log) {
|
18
18
|
result = @translator.listen log, noprint: false
|
19
|
-
|
19
|
+
# result could be nil if the log cannot be parsed into an event
|
20
|
+
# in that case we just pass raw log to listener
|
21
|
+
log_listener.call(result || log) if log_listener
|
20
22
|
}
|
21
23
|
@state.block.log_listeners.push listener
|
22
24
|
end
|
@@ -26,8 +28,8 @@ module Ethereum
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
def listen(x)
|
30
|
-
@translator.listen x
|
31
|
+
def listen(x, noprint: true)
|
32
|
+
@translator.listen x, noprint: noprint
|
31
33
|
end
|
32
34
|
|
33
35
|
private
|
@@ -89,7 +89,11 @@ module Ethereum
|
|
89
89
|
pipe = IO.popen(args, 'w', [:out, :err] => out)
|
90
90
|
pipe.write code
|
91
91
|
pipe.close_write
|
92
|
-
|
92
|
+
unless $?.success?
|
93
|
+
out.rewind
|
94
|
+
output = out.read
|
95
|
+
raise CompileError, "compilation failed:\n#{output}"
|
96
|
+
end
|
93
97
|
|
94
98
|
out.rewind
|
95
99
|
solc_parse_output out.read
|
@@ -247,7 +251,7 @@ module Ethereum
|
|
247
251
|
|
248
252
|
def compiler_version
|
249
253
|
output = `#{solc_path} --version`.strip
|
250
|
-
output =~ /^Version: ([0-9a-
|
254
|
+
output =~ /^Version: ([0-9a-zA-Z.\-+]+)/m ? $1 : nil
|
251
255
|
end
|
252
256
|
|
253
257
|
##
|
@@ -10,7 +10,7 @@ module Ethereum
|
|
10
10
|
|
11
11
|
attr :env, :block, :blocks
|
12
12
|
|
13
|
-
def initialize(env: nil,
|
13
|
+
def initialize(env: nil, privkeys: Fixture.keys, start_alloc: nil, gas_price: Fixture.gas_price, gas_limit: Fixture.gas_limit)
|
14
14
|
if env
|
15
15
|
@db = env.db
|
16
16
|
@env = env
|
@@ -21,9 +21,15 @@ module Ethereum
|
|
21
21
|
|
22
22
|
@temp_data_dir = Dir.mktmpdir TMP_DIR_PREFIX
|
23
23
|
|
24
|
-
@
|
24
|
+
@privkeys = privkeys
|
25
|
+
@accounts = @privkeys.map {|k| PrivateKey.new(k).to_address }
|
26
|
+
@gas_price = gas_price
|
27
|
+
@gas_limit = gas_limit
|
28
|
+
|
29
|
+
start_alloc ||= get_start_alloc()
|
30
|
+
@block = Block.genesis @env, start_alloc: start_alloc
|
25
31
|
@block.timestamp = 1410973349
|
26
|
-
@block.coinbase =
|
32
|
+
@block.coinbase = @accounts[0]
|
27
33
|
@block.gas_limit = 10**9
|
28
34
|
|
29
35
|
@blocks = [@block]
|
@@ -32,7 +38,11 @@ module Ethereum
|
|
32
38
|
ObjectSpace.define_finalizer(self) {|id| FileUtils.rm_rf(@temp_data_dir) }
|
33
39
|
end
|
34
40
|
|
35
|
-
def
|
41
|
+
def head
|
42
|
+
@blocks.last
|
43
|
+
end
|
44
|
+
|
45
|
+
def contract(code, sender: @privkeys[0], endowment: 0, language: :serpent,
|
36
46
|
libraries: nil, path: nil, constructor_call: nil, **kwargs)
|
37
47
|
code = Language.format_spaces code
|
38
48
|
compiler = Language.get language
|
@@ -46,7 +56,7 @@ module Ethereum
|
|
46
56
|
address
|
47
57
|
end
|
48
58
|
|
49
|
-
def abi_contract(code, sender:
|
59
|
+
def abi_contract(code, sender: @privkeys[0], endowment: 0, language: :serpent,
|
50
60
|
libraries: nil, path: nil, constructor_parameters: nil,
|
51
61
|
log_listener: nil, listen: true, **kwargs)
|
52
62
|
code = Language.format_spaces code
|
@@ -63,13 +73,13 @@ module Ethereum
|
|
63
73
|
libraries: libraries, path: path, constructor_call: encoded_parameters,
|
64
74
|
**kwargs)
|
65
75
|
|
66
|
-
ABIContract.new(self, translator, address, listen: listen, log_listener: log_listener)
|
76
|
+
ABIContract.new(self, translator, address, listen: listen, log_listener: log_listener, default_key: sender)
|
67
77
|
end
|
68
78
|
|
69
|
-
def evm(bytecode, sender:
|
79
|
+
def evm(bytecode, sender: @privkeys[0], endowment: 0, gas: nil)
|
70
80
|
sendnonce = @block.get_nonce PrivateKey.new(sender).to_address
|
71
81
|
|
72
|
-
tx = Transaction.contract sendnonce,
|
82
|
+
tx = Transaction.contract sendnonce, @gas_price, @gas_limit, endowment, bytecode
|
73
83
|
tx.sign sender
|
74
84
|
tx.startgas = gas if gas
|
75
85
|
|
@@ -94,7 +104,7 @@ module Ethereum
|
|
94
104
|
|
95
105
|
t1, g1 = Time.now, @block.gas_used
|
96
106
|
sendnonce = @block.get_nonce PrivateKey.new(sender).to_address
|
97
|
-
tx = Transaction.new(sendnonce,
|
107
|
+
tx = Transaction.new(sendnonce, @gas_price, @gas_limit, to, value, evmdata)
|
98
108
|
@last_tx = tx
|
99
109
|
tx.sign(sender)
|
100
110
|
|
@@ -136,7 +146,7 @@ module Ethereum
|
|
136
146
|
sendnonce = @block.get_nonce PrivateKey.new(sender).to_address
|
137
147
|
evmdata = funid ? serpent.encode_abi(funid, *abi) : serpent.encode_datalist(*data)
|
138
148
|
|
139
|
-
tx = Transaction.new(sendnonce,
|
149
|
+
tx = Transaction.new(sendnonce, @gas_price, @gas_limit, to, value, evmdata)
|
140
150
|
@last_tx = tx
|
141
151
|
tx.sign(sender)
|
142
152
|
|
@@ -152,7 +162,7 @@ module Ethereum
|
|
152
162
|
sendnonce = @block.get_nonce PrivateKey.new(sender).to_address
|
153
163
|
evmdata = funid ? serpent.encode_abi(funid, *abi) : serpent.encode_datalist(*data)
|
154
164
|
|
155
|
-
tx = Transaction.new(sendnonce,
|
165
|
+
tx = Transaction.new(sendnonce, @gas_price, @gas_limit, to, value, evmdata)
|
156
166
|
@last_tx = tx
|
157
167
|
tx.sign(sender)
|
158
168
|
|
@@ -165,7 +175,7 @@ module Ethereum
|
|
165
175
|
recorder.pop_records # TODO: implement recorder
|
166
176
|
end
|
167
177
|
|
168
|
-
def mine(n=1, coinbase:
|
178
|
+
def mine(n=1, coinbase: @accounts[0])
|
169
179
|
n.times do |i|
|
170
180
|
@block.finalize
|
171
181
|
@block.commit_state
|
@@ -196,10 +206,10 @@ module Ethereum
|
|
196
206
|
|
197
207
|
private
|
198
208
|
|
199
|
-
def get_start_alloc
|
209
|
+
def get_start_alloc
|
200
210
|
o = {}
|
201
|
-
num_accounts.times {|i| o[Fixture.accounts[i]] = {wei: 10**24} }
|
202
211
|
(1...5).each {|i| o[Utils.int_to_addr(i)] = {wei: 1} }
|
212
|
+
@accounts.each {|addr| o[addr] = {wei: 10**24} }
|
203
213
|
o
|
204
214
|
end
|
205
215
|
|
data/lib/ethereum/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-ethereum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Xie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rlp
|