Esempio n. 1
0
 def __init__(self, state, tx):
     self.specials = {k: v for k, v in default_specials.items()}
     for k, v in state.config["CUSTOM_SPECIALS"]:
         self.specials[k] = v
     self._state = state
     self.get_code = state.get_code
     self.set_code = state.set_code
     self.get_balances = state.get_balances  # gets token balances dict
     self.get_balance = (
         state.get_balance
     )  # gets default_chain_token balance if no token_id is passed in
     self.set_balances = state.set_balances  # sets token balances dict
     self.set_token_balance = state.set_token_balance
     self.set_balance = state.set_balance  # gets default_chain_token balance
     self.get_nonce = state.get_nonce
     self.set_nonce = state.set_nonce
     self.increment_nonce = state.increment_nonce
     self.set_storage_data = state.set_storage_data
     self.get_storage_data = state.get_storage_data
     self.log_storage = lambda x: state.account_to_dict(x)
     self.add_suicide = lambda x: state.add_suicide(x)
     self.add_refund = lambda x: state.set_param("refunds", state.refunds + x)
     self.block_hash = (
         lambda x: state.get_block_hash(state.block_number - x - 1)
         if (1 <= state.block_number - x <= 256 and x <= state.block_number)
         else b""
     )
     self.block_coinbase = state.block_coinbase
     self.block_timestamp = state.timestamp
     self.block_number = state.block_number
     self.block_difficulty = state.block_difficulty
     self.block_gas_limit = state.gas_limit
     self.log = lambda addr, topics, data: state.add_log(Log(addr, topics, data))
     self.create = lambda msg: create_contract(self, msg)
     self.msg = lambda msg: _apply_msg(self, msg, self.get_code(msg.code_address))
     self.account_exists = state.account_exists
     self.post_homestead_hardfork = lambda: state.is_HOMESTEAD()
     self.post_metropolis_hardfork = lambda: state.is_METROPOLIS()
     self.post_constantinople_hardfork = lambda: state.is_CONSTANTINOPLE()
     self.post_serenity_hardfork = lambda: state.is_SERENITY()
     self.post_anti_dos_hardfork = lambda: state.is_ANTI_DOS()
     self.post_spurious_dragon_hardfork = lambda: state.is_SPURIOUS_DRAGON()
     self.blockhash_store = state.config["METROPOLIS_BLOCKHASH_STORE"]
     self.snapshot = state.snapshot
     self.revert = state.revert
     self.transfer_value = state.transfer_value
     self.deduct_value = state.deduct_value
     self.add_cross_shard_transaction_deposit = lambda deposit: state.xshard_list.append(
         deposit
     )
     self.reset_storage = state.reset_storage
     self.tx_origin = tx.sender if tx else b"\x00" * 20
     self.tx_gasprice = tx.gasprice if tx else 0
     self.sender_disallow_list = state.sender_disallow_list
     self.default_state_token = state.shard_config.default_chain_token
Esempio n. 2
0
 def __init__(self, state, sender, gas_price):
     self.specials = {k: v for k, v in default_specials.items()}
     for k, v in state.config["CUSTOM_SPECIALS"]:
         self.specials[k] = v
     self._state = state
     self.get_code = state.get_code
     self.set_code = state.set_code
     self.get_balances = state.get_balances  # gets token balances dict
     self.get_balance = (
         state.get_balance
     )  # gets default_chain_token balance if no token_id is passed in
     self.set_balances = state.set_balances  # sets token balances dict
     self.set_token_balance = state.set_token_balance
     self.set_balance = state.set_balance  # gets default_chain_token balance
     self.get_nonce = state.get_nonce
     self.set_nonce = state.set_nonce
     self.increment_nonce = state.increment_nonce
     self.set_storage_data = state.set_storage_data
     self.get_storage_data = state.get_storage_data
     self.log_storage = lambda x: state.account_to_dict(x)
     self.add_suicide = lambda x: state.add_suicide(x)
     self.add_refund = lambda x: state.set_param("refunds", state.refunds + x)
     self.block_hash = (
         lambda x: state.get_block_hash(state.block_number - x - 1)
         if (1 <= state.block_number - x <= 256 and x <= state.block_number)
         else b""
     )
     self.block_coinbase = state.block_coinbase
     self.block_timestamp = state.timestamp
     self.block_number = state.block_number
     self.block_difficulty = state.block_difficulty
     self.block_gas_limit = state.gas_limit
     self.log = lambda addr, topics, data: state.add_log(Log(addr, topics, data))
     self.create = lambda msg, salt: create_contract(
         self, msg, contract_recipient=b"", salt=salt
     )
     self.msg = lambda msg: _apply_msg(self, msg, self.get_code(msg.code_address))
     self.account_exists = state.account_exists
     self.blockhash_store = 0x20
     self.snapshot = state.snapshot
     self.revert = state.revert
     self.transfer_value = state.transfer_value
     self.deduct_value = state.deduct_value
     self.add_cross_shard_transaction_deposit = lambda deposit: state.xshard_list.append(
         deposit
     )
     self.reset_storage = state.reset_storage
     self.tx_origin = sender
     self.tx_gasprice = gas_price
     self.sender_disallow_map = state.sender_disallow_map
     self.default_state_token = state.shard_config.default_chain_token