def mk_contract_address(sender, nonce, full_shard_key): if full_shard_key is not None: to_encode = [utils.normalize_address(sender), full_shard_key, nonce] else: # only happens for backward-compatible EVM tests to_encode = [utils.normalize_address(sender), nonce] return utils.sha3(rlp.encode(to_encode))[12:]
def del_account(self, address): self.set_balance(address, 0) self.set_nonce(address, 0) self.set_code(address, b'') self.reset_storage(address) self.set_and_journal( self.get_and_cache_account(utils.normalize_address(address)), 'deleted', True) self.set_and_journal( self.get_and_cache_account(utils.normalize_address(address)), 'touched', False)
def del_account(self, address): self.set_balance(address, 0) self.set_nonce(address, 0) self.set_code(address, b"") self.reset_storage(address) self.set_and_journal( self.get_and_cache_account(utils.normalize_address(address)), "deleted", True, ) self.set_and_journal( self.get_and_cache_account(utils.normalize_address(address)), "touched", False, )
def __init__(self, nonce, gasprice, startgas, to, value, data, v=0, r=0, s=0, from_full_shard_id=0, to_full_shard_id=0, network_id=1, version=0): self.data = None self.shard_size = 0 to = utils.normalize_address(to, allow_blank=True) super( Transaction, self).__init__( nonce, gasprice, startgas, to, value, data, from_full_shard_id, to_full_shard_id, network_id, version, v, r, s) if self.gasprice >= TT256 or self.startgas >= TT256 or \ self.value >= TT256 or self.nonce >= TT256: raise InvalidTransaction("Values way too high!")
def set_token_balance(self, address, token_id, val): acct = self.get_and_cache_account(utils.normalize_address(address)) if val == self.get_balance(address, token_id=token_id): self.set_and_journal(acct, "touched", True) return self._set_token_balance_and_journal(acct, token_id, val) self.set_and_journal(acct, "touched", True)
def set_balances(self, address, token_balances: dict): acct = self.get_and_cache_account(utils.normalize_address(address)) if self.get_balances(address) == token_balances: self.set_and_journal(acct, "touched", True) return self.set_and_journal(acct.token_balances, "balances", token_balances) self.set_and_journal(acct, "touched", True)
def delta_balance(self, address, value, token_id): address = utils.normalize_address(address) acct = self.get_and_cache_account(address) acct.multibalance[token_id] = acct.multibalance[token_id] + value newbal = acct.multibalance #self.set_and_journal(acct, 'balance', newbal) self.set_and_journal(acct, 'multibalance', newbal) self.set_and_journal(acct, 'touched', True)
def delta_token_balance(self, address, token_id, value): address = utils.normalize_address(address) acct = self.get_and_cache_account(address) if value == 0: self.set_and_journal(acct, "touched", True) return newbal = acct.token_balances.balance(token_id) + value self._set_token_balance_and_journal(acct, token_id, newbal) self.set_and_journal(acct, "touched", True)
def account_exists(self, address): if self.is_SPURIOUS_DRAGON(): o = not self.get_and_cache_account( utils.normalize_address(address)).is_blank() else: a = self.get_and_cache_account(address) if a.deleted and not a.touched: return False if a.touched: return True else: return a.existent_at_start return o
def __init__( self, nonce, gasprice, startgas, to, value, data, gas_token_id, transfer_token_id, v=0, r=0, s=0, from_full_shard_key=0, to_full_shard_key=0, network_id=1, version=0, is_testing=False, ): self.quark_chain_config = None self.is_testing = is_testing to = utils.normalize_address(to, allow_blank=True) super(Transaction, self).__init__( nonce, gasprice, startgas, to, value, data, network_id, from_full_shard_key, to_full_shard_key, gas_token_id, transfer_token_id, version, v, r, s, ) if (self.gasprice >= TT256 or self.startgas >= TT256 or self.value >= TT256 or self.nonce >= TT256 or self.version >= TT256 or self.gas_token_id > TOKEN_ID_MAX or self.transfer_token_id > TOKEN_ID_MAX or self.from_full_shard_key > SHARD_KEY_MAX or self.to_full_shard_key > SHARD_KEY_MAX): raise InvalidTransaction("Values way too high!")
def __init__( self, nonce, gasprice, startgas, to, value, data, v=0, r=0, s=0, from_full_shard_key=0, to_full_shard_key=0, network_id=1, version=0, ): self.quark_chain_config = None to = utils.normalize_address(to, allow_blank=True) super(Transaction, self).__init__( nonce, gasprice, startgas, to, value, data, from_full_shard_key, to_full_shard_key, network_id, version, v, r, s, ) if ( self.gasprice >= TT256 or self.startgas >= TT256 or self.value >= TT256 or self.nonce >= TT256 ): raise InvalidTransaction("Values way too high!")
def delta_balance(self, address, value): address = utils.normalize_address(address) acct = self.get_and_cache_account(address) newbal = acct.balance + value self.set_and_journal(acct, "balance", newbal) self.set_and_journal(acct, "touched", True)
def set_nonce(self, address, value): acct = self.get_and_cache_account(utils.normalize_address(address)) self.set_and_journal(acct, "nonce", value) self.set_and_journal(acct, "touched", True)
def set_code(self, address, value): # assert is_string(value) acct = self.get_and_cache_account(utils.normalize_address(address)) self.set_and_journal(acct, "code", value) self.set_and_journal(acct, "touched", True)
def get_full_shard_id(self, address): return self.get_and_cache_account( utils.normalize_address(address)).full_shard_id
def get_nonce(self, address): return self.get_and_cache_account( utils.normalize_address(address)).nonce
def reset_balances(self, address): acct = self.get_and_cache_account(utils.normalize_address(address)) acct.token_balances.reset(self.journal)
def set_storage_data(self, address, key, value): acct = self.get_and_cache_account(utils.normalize_address(address)) preval = acct.get_storage_data(key) acct.set_storage_data(key, value) self.journal.append(lambda: acct.set_storage_data(key, preval)) self.set_and_journal(acct, "touched", True)
def set_balance(self, address, value): acct = self.get_and_cache_account(utils.normalize_address(address)) self.set_and_journal(acct, 'balance', value) self.set_and_journal(acct, 'touched', True)
def set_balance(self, address, value, token_id): acct = self.get_and_cache_account(utils.normalize_address(address)) acct.multibalance[token_id] = acct.multibalance[token_id] + value self.set_and_journal(acct, 'multibalance', acct.multibalance) self.set_and_journal(acct, 'touched', True)
def account_to_dict(self, address): return self.get_and_cache_account( utils.normalize_address(address)).to_dict()
def account_exists(self, address): o = not self.get_and_cache_account(utils.normalize_address(address)).is_blank() return o
def get_balances(self, address) -> dict: return self.get_and_cache_account( utils.normalize_address(address) ).token_balances.to_dict()
def increment_nonce(self, address): address = utils.normalize_address(address) acct = self.get_and_cache_account(address) newnonce = acct.nonce + 1 self.set_and_journal(acct, "nonce", newnonce) self.set_and_journal(acct, "touched", True)
def get_storage_data(self, address, key): return self.get_and_cache_account( utils.normalize_address(address)).get_storage_data(key)
def mk_contract_address2(sender, salt: bytes, init_code_hash: bytes): return utils.sha3(b"\xff" + utils.normalize_address(sender) + salt + init_code_hash)[12:]
def mk_contract_address(sender, full_shard_key, nonce): return utils.sha3( rlp.encode([utils.normalize_address(sender), full_shard_key, nonce]))[12:]
def get_balance(self, address, token_id=None): if token_id is None: token_id = self.shard_config.default_chain_token return self.get_and_cache_account( utils.normalize_address(address) ).token_balances.balance(token_id)
# Metropolis fork METROPOLIS_FORK_BLKNUM=4370000, METROPOLIS_ENTRY_POINT=2**160 - 1, METROPOLIS_STATEROOT_STORE=0x10, METROPOLIS_BLOCKHASH_STORE=0x20, METROPOLIS_WRAPAROUND=65536, METROPOLIS_GETTER_CODE=decode_hex('6000355460205260206020f3'), METROPOLIS_DIFF_ADJUSTMENT_CUTOFF=9, # Constantinople fork CONSTANTINOPLE_FORK_BLKNUM=2**100, # DAO fork DAO_FORK_BLKNUM=1920000, DAO_FORK_BLKHASH=decode_hex( '4985f5ca3d2afbec36529aa96f74de3cc10a2a4a6c44f2157a57d2c6059a11bb'), DAO_FORK_BLKEXTRA=decode_hex('64616f2d686172642d666f726b'), DAO_WITHDRAWER=utils.normalize_address( '0xbf4ed7b27f1d666546e30d74d50d173d20bca754'), # Anti-DoS fork ANTI_DOS_FORK_BLKNUM=2463000, SPURIOUS_DRAGON_FORK_BLKNUM=2675000, CONTRACT_CODE_SIZE_LIMIT=0x6000, # Default consensus strategy: ethash, poa, casper, pbft CONSENSUS_STRATEGY='ethash', # Serenity fork SERENITY_FORK_BLKNUM=2**99, PREV_HEADER_DEPTH=256, SYSTEM_ENTRY_POINT=utils.int_to_addr(2**160 - 2), SERENITY_HEADER_VERIFIER=utils.int_to_addr(255), SERENITY_HEADER_POST_FINALIZER=utils.int_to_addr(254), SERENITY_GETTER_CODE=decode_hex( '60ff331436604014161560155760203560003555005b6000355460205260206020f3' ),
def get_balance(self, address, token_id): return self.get_and_cache_account( utils.normalize_address(address)).multibalance[token_id]