|
5 | 5 | from ethereum.consensus_strategy import get_consensus_strategy
|
6 | 6 | from ethereum.config import config_homestead, config_tangerine, config_spurious, config_metropolis, default_config, Env
|
7 | 7 | from ethereum.pow.ethpow import Miner
|
8 |
| -from ethereum.messages import apply_transaction |
| 8 | +from ethereum.messages import apply_transaction, apply_message |
9 | 9 | from ethereum.common import verify_execution_results, mk_block_from_prevstate, set_execution_results
|
10 | 10 | from ethereum.meta import make_head_candidate
|
11 | 11 | from ethereum.abi import ContractTranslator
|
@@ -136,15 +136,11 @@ def tx(self, sender=k0, to=b'\x00' * 20, value=0, data=b'', startgas=STARTGAS, g
|
136 | 136 | return output
|
137 | 137 |
|
138 | 138 | def call(self, sender=k0, to=b'\x00' * 20, value=0, data=b'', startgas=STARTGAS, gasprice=GASPRICE):
|
139 |
| - state = self.state |
140 |
| - self.state = self.state.ephemeral_clone() |
141 |
| - try: |
142 |
| - output = self.tx(sender, to, value, data, startgas, gasprice) |
143 |
| - self.state = state |
144 |
| - return output |
145 |
| - except Exception as e: |
146 |
| - self.state = state |
147 |
| - raise e |
| 139 | + sender_addr = privtoaddr(sender) |
| 140 | + result = apply_message(self.state.ephemeral_clone(), sender=sender_addr, to=to, value=value, data=data, gas=startgas) |
| 141 | + if result is None: |
| 142 | + raise TransactionFailed() |
| 143 | + return result |
148 | 144 |
|
149 | 145 | class Chain(object):
|
150 | 146 | def __init__(self, alloc=base_alloc, env=None, genesis=None):
|
@@ -176,14 +172,11 @@ def tx(self, sender=k0, to=b'\x00' * 20, value=0, data=b'', startgas=STARTGAS, g
|
176 | 172 | return output
|
177 | 173 |
|
178 | 174 | def call(self, sender=k0, to=b'\x00' * 20, value=0, data=b'', startgas=STARTGAS, gasprice=GASPRICE):
|
179 |
| - snapshot = self.snapshot() |
180 |
| - try: |
181 |
| - output = self.tx(sender, to, value, data, startgas, gasprice) |
182 |
| - self.revert(snapshot) |
183 |
| - return output |
184 |
| - except Exception as e: |
185 |
| - self.revert(snapshot) |
186 |
| - raise e |
| 175 | + sender_addr = privtoaddr(sender) |
| 176 | + result = apply_message(self.head_state.ephemeral_clone(), sender=sender_addr, to=to, value=value, data=data, gas=startgas) |
| 177 | + if result is None: |
| 178 | + raise TransactionFailed() |
| 179 | + return result |
187 | 180 |
|
188 | 181 | def contract(self, sourcecode, args=[], sender=k0, value=0, language='evm', startgas=STARTGAS, gasprice=GASPRICE):
|
189 | 182 | if language == 'evm':
|
|
0 commit comments