ruby-ethereum 0.9.3 → 0.9.4

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.
@@ -8,13 +8,18 @@ module Ethereum
8
8
 
9
9
  TMP_DIR_PREFIX = 'eth-tester-'.freeze
10
10
 
11
- attr :block, :blocks
11
+ attr :env, :block, :blocks
12
12
 
13
- def initialize(num_accounts=Fixture::NUM_ACCOUNTS)
14
- @temp_data_dir = Dir.mktmpdir TMP_DIR_PREFIX
13
+ def initialize(env: nil, num_accounts: Fixture::NUM_ACCOUNTS)
14
+ if env
15
+ @db = env.db
16
+ @env = env
17
+ else
18
+ @db = DB::EphemDB.new
19
+ @env = Env.new @db
20
+ end
15
21
 
16
- @db = DB::EphemDB.new
17
- @env = Env.new @db
22
+ @temp_data_dir = Dir.mktmpdir TMP_DIR_PREFIX
18
23
 
19
24
  @block = Block.genesis @env, start_alloc: get_start_alloc(num_accounts)
20
25
  @block.timestamp = 1410973349
@@ -27,45 +32,44 @@ module Ethereum
27
32
  ObjectSpace.define_finalizer(self) {|id| FileUtils.rm_rf(@temp_data_dir) }
28
33
  end
29
34
 
30
- def contract(code, sender: Fixture.keys[0], endowment: 0, language: :serpent, gas: nil)
35
+ def contract(code, sender: Fixture.keys[0], endowment: 0, language: :serpent,
36
+ libraries: nil, path: nil, constructor_call: nil, **kwargs)
31
37
  code = Language.format_spaces code
32
- opcodes = Language.get(language).compile(code)
33
- addr = evm(opcodes, sender: sender, endowment: endowment)
34
- raise AssertError, "Contract code empty" if @block.get_code(addr).empty?
35
- addr
36
- end
38
+ compiler = Language.get language
39
+
40
+ bytecode = compiler.compile code, path: path, libraries: libraries, **kwargs
41
+ bytecode += constructor_call if constructor_call
37
42
 
38
- def abi_contract(code, **kwargs)
39
- sender = kwargs.delete(:sender) || Fixture.keys[0]
40
- endowment = kwargs.delete(:endowment) || 0
41
- language = kwargs.delete(:language) || :serpent
42
- contract_name = kwargs.delete(:contract_name) || ''
43
- gas = kwargs.delete(:gas) || nil
44
- log_listener = kwargs.delete(:log_listener) || nil
45
- listen = kwargs.delete(:listen) || true
43
+ address = evm bytecode, sender: sender, endowment: endowment
44
+ raise AssertError, "Contract code empty" if @block.get_code(address).empty?
45
+
46
+ address
47
+ end
46
48
 
49
+ def abi_contract(code, sender: Fixture.keys[0], endowment: 0, language: :serpent,
50
+ libraries: nil, path: nil, constructor_parameters: nil,
51
+ log_listener: nil, listen: true, **kwargs)
47
52
  code = Language.format_spaces code
53
+ compiler = Language.get language
48
54
 
49
- if contract_name.true?
50
- raise ArgumentError, "language must be solidity when contract name is given" unless language == :solidity
51
- cn_args = {contract_name: contract_name}
52
- else
53
- cn_args = kwargs
54
- end
55
+ contract_interface = compiler.mk_full_signature code, path: path, **kwargs
56
+ translator = ABI::ContractTranslator.new contract_interface
55
57
 
56
- lang = Language.get language
57
- opcodes = lang.compile code, **cn_args
58
- addr = evm(opcodes, sender: sender, endowment: endowment, gas: gas)
59
- raise AssertError, "Contract code empty" if @block.get_code(addr).empty?
58
+ encoded_parameters = constructor_parameters ?
59
+ translator.encode_constructor_arguments(constructor_parameters) :
60
+ nil
60
61
 
61
- abi = lang.mk_full_signature(code, **cn_args)
62
- ABIContract.new(self, abi, addr, listen: listen, log_listener: log_listener)
62
+ address = contract(code, sender: sender, endowment: endowment, language: language,
63
+ libraries: libraries, path: path, constructor_call: encoded_parameters,
64
+ **kwargs)
65
+
66
+ ABIContract.new(self, translator, address, listen: listen, log_listener: log_listener)
63
67
  end
64
68
 
65
- def evm(opcodes, sender: Fixture.keys[0], endowment: 0, gas: nil)
69
+ def evm(bytecode, sender: Fixture.keys[0], endowment: 0, gas: nil)
66
70
  sendnonce = @block.get_nonce PrivateKey.new(sender).to_address
67
71
 
68
- tx = Transaction.contract sendnonce, Fixture.gas_price, Fixture.gas_limit, endowment, opcodes
72
+ tx = Transaction.contract sendnonce, Fixture.gas_price, Fixture.gas_limit, endowment, bytecode
69
73
  tx.sign sender
70
74
  tx.startgas = gas if gas
71
75
 
@@ -83,7 +87,7 @@ module Ethereum
83
87
  _send_tx(*args, **kwargs)[:output]
84
88
  end
85
89
 
86
- def _send_tx(sender, to, value, evmdata: '', output: nil, funid: nil, abi: nil, profiling: 0)
90
+ def _send_tx(sender, to, value, evmdata: '', funid: nil, abi: nil, profiling: 0)
87
91
  if funid || abi
88
92
  raise ArgumentError, "Send with funid+abi is deprecated. Please use the abi_contract mechanism."
89
93
  end
@@ -124,8 +128,13 @@ module Ethereum
124
128
  end
125
129
 
126
130
  def mkspv(sender, to, value, data: [], funid: nil, abi: nil)
131
+ raise NotImplemented
132
+
133
+ serpent = Language.get :serpent
134
+ raise "ruby-serpent not installed" unless serpent
135
+
127
136
  sendnonce = @block.get_nonce PrivateKey.new(sender).to_address
128
- evmdata = funid ? Serpent.encode_abi(funid, *abi) : Serpent.encode_datalist(*data)
137
+ evmdata = funid ? serpent.encode_abi(funid, *abi) : serpent.encode_datalist(*data)
129
138
 
130
139
  tx = Transaction.new(sendnonce, Fixture.gas_price, Fixture.gas_limit, to, value, evmdata)
131
140
  @last_tx = tx
@@ -135,8 +144,13 @@ module Ethereum
135
144
  end
136
145
 
137
146
  def verifyspv(sender, to, value, data: [], funid: nil, abi: nil, proof: [])
147
+ raise NotImplemented
148
+
149
+ serpent = Language.get(:serpent)
150
+ raise "ruby-serpent not installed" unless serpent
151
+
138
152
  sendnonce = @block.get_nonce PrivateKey.new(sender).to_address
139
- evmdata = funid ? Serpent.encode_abi(funid, *abi) : Serpent.encode_datalist(*data)
153
+ evmdata = funid ? serpent.encode_abi(funid, *abi) : serpent.encode_datalist(*data)
140
154
 
141
155
  tx = Transaction.new(sendnonce, Fixture.gas_price, Fixture.gas_limit, to, value, evmdata)
142
156
  @last_tx = tx
@@ -187,6 +187,10 @@ module Ethereum
187
187
  keccak256_rlp([normalize_address(sender), nonce])[12..-1]
188
188
  end
189
189
 
190
+ def mk_metropolis_contract_address(sender, initcode)
191
+ keccak256(normalize_address(sender) + initcode)[12..-1]
192
+ end
193
+
190
194
  def remove_0x_head(s)
191
195
  s[0,2] == '0x' ? s[2..-1] : s
192
196
  end
@@ -209,5 +213,24 @@ module Ethereum
209
213
  end
210
214
  end
211
215
 
216
+ def child_dao_list
217
+ source = '0x4a574510c7014e4ae985403536074abe582adfc8'
218
+
219
+ main = [
220
+ '0xbb9bc244d798123fde783fcc1c72d3bb8c189413', # TheDAO
221
+ '0x807640a13483f8ac783c557fcdf27be11ea4ac7a' # TheDAO extrabalance
222
+ ]
223
+
224
+ child_daos = []
225
+ child_extra_balances = []
226
+ (1...58).each do |i|
227
+ child_addr = "0x#{encode_hex mk_contract_address(source, i)}"
228
+ child_daos.push child_addr
229
+ child_extra_balances.push "0x#{encode_hex mk_contract_address(child_addr, 0)}"
230
+ end
231
+
232
+ main + child_daos + child_extra_balances
233
+ end
234
+
212
235
  end
213
236
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : ascii-8bit -*-
2
2
 
3
3
  module Ethereum
4
- VERSION = '0.9.3'
4
+ VERSION = '0.9.4'
5
5
  end
data/lib/ethereum/vm.rb CHANGED
@@ -273,7 +273,7 @@ module Ethereum
273
273
  case op
274
274
  when :BLOCKHASH
275
275
  s0 = stk.pop
276
- stk.push Utils.big_endian_to_int(ext.block_hash(s0))
276
+ stk.push ext.block_hash(s0)
277
277
  when :COINBASE
278
278
  stk.push Utils.big_endian_to_int(ext.block_coinbase)
279
279
  when :TIMESTAMP
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.3
4
+ version: 0.9.4
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-06-28 00:00:00.000000000 Z
11
+ date: 2016-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rlp