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.
- checksums.yaml +4 -4
- data/README.md +1 -9
- data/lib/ethereum/abi.rb +79 -44
- data/lib/ethereum/abi/contract_translator.rb +142 -97
- data/lib/ethereum/abi/type.rb +4 -4
- data/lib/ethereum/address.rb +2 -0
- data/lib/ethereum/block.rb +38 -3
- data/lib/ethereum/constant.rb +8 -6
- data/lib/ethereum/env.rb +15 -1
- data/lib/ethereum/external_call.rb +43 -20
- data/lib/ethereum/tester/abi_contract.rb +12 -15
- data/lib/ethereum/tester/solidity_wrapper.rb +249 -81
- data/lib/ethereum/tester/state.rb +50 -36
- data/lib/ethereum/utils.rb +23 -0
- data/lib/ethereum/version.rb +1 -1
- data/lib/ethereum/vm.rb +1 -1
- metadata +2 -2
@@ -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
|
14
|
-
|
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
|
-
@
|
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,
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
50
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
62
|
-
|
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(
|
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,
|
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: '',
|
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 ?
|
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 ?
|
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
|
data/lib/ethereum/utils.rb
CHANGED
@@ -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
|
data/lib/ethereum/version.rb
CHANGED
data/lib/ethereum/vm.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.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-
|
11
|
+
date: 2016-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rlp
|