示例#1
0
 def run(self, *args, **kwargs):
     port = kwargs.pop('port', DEFAULT_PORT)
     self.port = port
     try:
         self.app.run(*args, port=port, **kwargs)
     except socket.error:
         print("\tOops, couldn't connect on port %d.  Is it busy?" % port)
         self.run(*args, **assoc(kwargs, 'port', port + 1))
示例#2
0
 def create_header_from_parent(cls, parent_header, **header_params):
     """
     Call the parent class method maintaining the same gas_limit as the
     previous block.
     """
     return super(MaintainGasLimitMixin, cls).create_header_from_parent(
         parent_header,
         **assoc(header_params, 'gas_limit', parent_header.gas_limit)
     )
示例#3
0
    def middleware(method, params):
        result = make_request(method, params)

        # As of v1.8, Geth returns errors when you request a
        # receipt for a transaction that is not in the chain.
        # It used to return a result of None, so we simulate the old behavior.

        if method == 'eth_getTransactionReceipt' and 'error' in result:
            is_geth = web3.version.node.startswith('Geth')
            if is_geth and result['error']['code'] == -32000:
                return assoc(
                    dissoc(result, 'error'),
                    'result',
                    None,
                )
            else:
                return result
        else:
            return result
示例#4
0
文件: chain.py 项目: firefox0x/py-evm
    def from_genesis(cls,
                     chaindb,
                     genesis_params,
                     genesis_state=None):
        """
        Initializes the Chain from a genesis state.
        """
        state_db = chaindb.get_state_db(chaindb.empty_root_hash, read_only=False)

        if genesis_state is None:
            genesis_state = {}

        for account, account_data in genesis_state.items():
            state_db.set_balance(account, account_data['balance'])
            state_db.set_nonce(account, account_data['nonce'])
            state_db.set_code(account, account_data['code'])

            for slot, value in account_data['storage'].items():
                state_db.set_storage(account, slot, value)

        if 'state_root' not in genesis_params:
            # If the genesis state_root was not specified, use the value
            # computed from the initialized state database.
            genesis_params = assoc(genesis_params, 'state_root', state_db.root_hash)
        elif genesis_params['state_root'] != state_db.root_hash:
            # If the genesis state_root was specified, validate that it matches
            # the computed state from the initialized state database.
            raise ValidationError(
                "The provided genesis state root does not match the computed "
                "genesis state root.  Got {0}.  Expected {1}".format(
                    state_db.root_hash,
                    genesis_params['state_root'],
                )
            )

        genesis_header = BlockHeader(**genesis_params)
        genesis_chain = cls(chaindb, genesis_header)
        chaindb.persist_block_to_db(genesis_chain.get_block())
        return cls.from_genesis_header(chaindb, genesis_header)
示例#5
0
def process(mj, since, till, path, threshold):
	base_ini_fn = '%s/atx300/set/base/base.ini' % path
	base_to_ior, ior_to_base = atxutils.build_signal_maps(base_ini_fn)

	signals_fns = utils.get_signals_files(path, since, till)

	signal_stream = atxsignals.read(signals_fns, since, till)
	signal_stream_digital = filter(lambda x: '_DI' in x['k'], signal_stream)
	pulses = get_pulses(signal_stream_digital)
	short_pulses = filter(lambda x: x['t_diff'] < threshold, pulses)
	pulses_with_base_names = map(lambda x: add_base_name(x, ior_to_base), short_pulses)
	#pulses_with_base_names = thread_last(
	#	signal_stream,
	#	(filter, lambda x: '_DI' in x['k']),
	#	get_pulses,
	#	(filter, lambda x: x['t_diff'] < threshold),
	#	(map, lambda x: add_base_name(x, ior_to_base)),
	#)()
	for i in pulses_with_base_names:
		i = assoc(i, 't_begin_isoformat', arrow.get(i['t_begin']).to('Europe/Prague').isoformat())
		i['mj'] = mj
		#pprint.pprint(i)
		yield i
def segments(ctx, cfg):
    '''Return saved segments'''
    logger.info("getting segments for cx:{} cy:{}".format(
        ctx['cx'], ctx['cy']))
    with ceph.connect(cfg) as c:
        return assoc(ctx, 'segments', c.select_segments(ctx['cx'], ctx['cy']))
 def make_request(method, params):
     return assoc(response, 'id', str(uuid.uuid4()))
示例#8
0
def fill_default(field, guess_func, web3, transaction):
    if field in transaction and transaction[field] is not None:
        return transaction
    else:
        guess_val = guess_func(web3, transaction)
        return assoc(transaction, field, guess_val)
def add_average_reflectance(ctx):
    return assoc(ctx, 'data', segaux.average_reflectance(ctx['data']))
示例#10
0
 def decode(self, data):
     raw_decoded = super(Disconnect, self).decode(data)
     return assoc(raw_decoded, 'reason_name',
                  self.get_reason_name(raw_decoded['reason']))
@pytest.mark.parametrize(
    'txn_dict, bad_fields',
    (
        (dict(GOOD_TXN), {}),
        (dict(GOOD_TXN, to=None), {}),
        (dict(GOOD_TXN, to=b''), {}),
        (dict(GOOD_TXN, to='0x' + '00' * 20), {}),
        (dict(GOOD_TXN, to='0xF0109fC8DF283027b6285cc889F5aA624EaC1F55'), {}),
        (dict(GOOD_TXN,
              to='0xf0109Fc8df283027B6285CC889f5Aa624eAc1f55'), {'to'}),
        (dict(GOOD_TXN, to='0x' + '00' * 19), {'to'}),
        (dict(GOOD_TXN, to='0x' + '00' * 21), {'to'}),
        (dict(GOOD_TXN, to=b'\0' * 20), {}),
        (dict(GOOD_TXN, to=b'\0' * 21), {'to'}),
        # from with the right address is allowed
        (assoc(GOOD_TXN, 'from',
               '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5'), {}),
        # from with a non-checksum address is not
        (assoc(GOOD_TXN, 'from',
               '0x3f17f1962b36e491b30a40b2405849e597ba5fb5'), {'from'}),
        # from with the wrong address is not
        (assoc(GOOD_TXN, 'from',
               '0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf'), {'from'}),
        (dict(GOOD_TXN, gas='0e1'), {'gas'}),
        (dict(GOOD_TXN, gasPrice='0e1'), {'gasPrice'}),
        (dict(GOOD_TXN, value='0e1'), {'value'}),
        (dict(GOOD_TXN, nonce='0e1'), {'nonce'}),
        (dict(GOOD_TXN, gas='0b1'), {'gas'}),
        (dict(GOOD_TXN, gasPrice='0b1'), {'gasPrice'}),
        (dict(GOOD_TXN, value='0b1'), {'value'}),
        (dict(GOOD_TXN, nonce='0b1'), {'nonce'}),
        (dict(GOOD_TXN, chainId=None), {}),
示例#12
0
@pytest.mark.parametrize(
    'txn_dict, bad_fields',
    (
        (dict(GOOD_TXN), {}),
        (dict(GOOD_TXN, to=None), {}),
        (dict(GOOD_TXN, to=b''), {}),
        (dict(GOOD_TXN, to='0x' + '00' * 20), {}),
        (dict(GOOD_TXN, to='0xF0109fC8DF283027b6285cc889F5aA624EaC1F55'), {}),
        (dict(GOOD_TXN,
              to='0xf0109Fc8df283027B6285CC889f5Aa624eAc1f55'), {'to'}),
        (dict(GOOD_TXN, to='0x' + '00' * 19), {'to'}),
        (dict(GOOD_TXN, to='0x' + '00' * 21), {'to'}),
        (dict(GOOD_TXN, to=b'\0' * 20), {}),
        (dict(GOOD_TXN, to=b'\0' * 21), {'to'}),
        # from with the right address is allowed
        (assoc(GOOD_TXN, 'from',
               '0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf'), {}),
        # from with a non-checksum address is not
        (assoc(GOOD_TXN, 'from',
               '0x7e5f4552091a69125d5dfcb7b8c2659029395bdf'), {'from'}),
        # from with the wrong address is not
        (assoc(GOOD_TXN, 'from',
               '0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF'), {'from'}),
        (dict(GOOD_TXN, gas='0e1'), {'gas'}),
        (dict(GOOD_TXN, gasPrice='0e1'), {'gasPrice'}),
        (dict(GOOD_TXN, value='0e1'), {'value'}),
        (dict(GOOD_TXN, nonce='0e1'), {'nonce'}),
        (dict(GOOD_TXN, gas='0b1'), {'gas'}),
        (dict(GOOD_TXN, gasPrice='0b1'), {'gasPrice'}),
        (dict(GOOD_TXN, value='0b1'), {'value'}),
        (dict(GOOD_TXN, nonce='0b1'), {'nonce'}),
        (dict(GOOD_TXN, chainId=None), {}),
示例#13
0
def add_training_dates(ctx):
    fn = partial(training_date, date=ctx['date'])
    return assoc(ctx, 'data', list(map(fn, ctx['data'])))
示例#14
0
def add_base_name(e, ior_to_base):
	return assoc(e, 'k_base_name', ior_to_base.get(e['k']))
示例#15
0
def load_fixture_data(fixture_path):
    fixture_path = absolute_datadir(fixture_path)
    config_path = os.path.join(fixture_path, 'config.json')
    with open(config_path) as config_file:
        loaded_data = json.loads(config_file.read())
        return assoc(loaded_data, 'datadir', fixture_path)
示例#16
0
 def decode(self, data: bytes) -> _DecodedMsgType:
     raw_decoded = cast(Dict[str, int],
                        super(Disconnect, self).decode(data))
     return assoc(raw_decoded, 'reason_name',
                  self.get_reason_name(raw_decoded['reason']))
示例#17
0
    def estimate_gas(self, transaction):
        evm_transaction = self._get_normalized_and_unsigned_evm_transaction(assoc(
            transaction, 'gas', 21000))
        spoofed_transaction = EVMSpoofTransaction(evm_transaction, from_=transaction['from'])

        return self.chain.estimate_gas(spoofed_transaction)
def _flatten_days(all_data):
    hourly_data = [[tlz.assoc(hour_data, 'date', day_data['value']) for hour_data in day_data['Rep']]
                   for day_data in all_data]
    return it.chain(*hourly_data)
示例#19
0
def training_format(ctx):

    d = [standard_format(sm) for sm in ctx['data']]
    return assoc(ctx, 'data', to_numpy(d))
示例#20
0
 def decode(self, data: bytes) -> _DecodedMsgType:
     raw_decoded = cast(Dict[str, int], super(Disconnect, self).decode(data))
     return assoc(raw_decoded, 'reason_name', self.get_reason_name(raw_decoded['reason']))
示例#21
0
def fill_default(field, guess_func, web3, transaction):
    if field in transaction and transaction[field] is not None:
        return transaction
    else:
        guess_val = guess_func(web3, transaction)
        return assoc(transaction, field, guess_val)
示例#22
0
def default_predictions(ctx):
    default = lambda x: assoc(x, 'prob', [])
    return assoc(
        ctx, 'predictions',
        add(list(map(default, get('defaults', ctx, []))), ctx['predictions']))
示例#23
0
def matrix(ctx):

    return assoc(
        ctx, 'ndata',
        numpy.array([d['independent'] for d in ctx['data']], dtype='float32'))
示例#24
0
def training_date(data, date):
    return assoc(data, 'date', date)