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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5dea8f0df777458359a58003ad2c36d5bab5c97
4
- data.tar.gz: 3ad437895256c6a02baf5a65502e87f6fc2d3b3d
3
+ metadata.gz: b148ff5fc474e2b43055a78679a76e13911534ed
4
+ data.tar.gz: 8d19a27b24c3e44c6826418c6062d5d5feccc5c4
5
5
  SHA512:
6
- metadata.gz: f85feb3ff2fadd5822eb1927d714f3afa6c9bdab8fa4a475e1e34cbdad8b3e901a907395ad69fbe3f284ee23bc0b7f01c17729b684c379f2b7f57aeb26ae9814
7
- data.tar.gz: 63eeecac33f4f8a60cc1274097d8871cc708debff8e6e304279485e34a22b1fd8bce2bb64f4db4023e59d4e56d91440c66a7a9faa6f49e5911f138e9c4ad4430
6
+ metadata.gz: 1bc3e0f52812048175c9e939ae8250f7a8086365970df3779ff0edfdd6a4faf88015c53365b8e72160739455fd5b2b9ea3c806140a2d6d1f6e8c7fbf0a302c39
7
+ data.tar.gz: 9e4c2c2a1182e11a4064a59fe4c8d50c6b51a1b5dcbb79d1407200156b919b6c1d4a7589fc7be4e74eea10859199d94301da44788eee470f7f3e5e08eab876c9
@@ -155,6 +155,7 @@ module Ethereum
155
155
  def listen(log, noprint: true)
156
156
  result = decode_event log.topics, log.data
157
157
  p result if noprint
158
+ result['_from'] = Utils.encode_hex(log.address)
158
159
  result
159
160
  rescue ValueError
160
161
  nil # api compatibility
@@ -16,7 +16,9 @@ module Ethereum
16
16
  if listen
17
17
  listener = ->(log) {
18
18
  result = @translator.listen log, noprint: false
19
- log_listener(result) if result && log_listener
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
@@ -13,8 +13,8 @@ module Ethereum
13
13
  begin
14
14
  require 'serpent'
15
15
  @all[:serpent] = Serpent
16
- rescue LoadError
17
- # do nothing
16
+ rescue LoadError => e
17
+ puts "Failed to load serpent"
18
18
  end
19
19
 
20
20
  if SolidityWrapper.solc_path
@@ -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
- raise CompileError, 'compilation failed' unless $?.success?
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-z.-]+)\///m ? $1 : nil
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, num_accounts: Fixture::NUM_ACCOUNTS)
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
- @block = Block.genesis @env, start_alloc: get_start_alloc(num_accounts)
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 = Fixture.accounts[0]
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 contract(code, sender: Fixture.keys[0], endowment: 0, language: :serpent,
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: Fixture.keys[0], endowment: 0, language: :serpent,
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: Fixture.keys[0], endowment: 0, gas: nil)
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, Fixture.gas_price, Fixture.gas_limit, endowment, bytecode
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, Fixture.gas_price, Fixture.gas_limit, to, value, evmdata)
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, Fixture.gas_price, Fixture.gas_limit, to, value, evmdata)
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, Fixture.gas_price, Fixture.gas_limit, to, value, evmdata)
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: Fixture.accounts[0])
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(num_accounts)
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
 
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : ascii-8bit -*-
2
2
 
3
3
  module Ethereum
4
- VERSION = '0.9.4'
4
+ VERSION = '0.9.6'
5
5
  end
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
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-08-20 00:00:00.000000000 Z
11
+ date: 2016-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rlp