• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.get_db_path函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.get_db_path函数的典型用法代码示例。如果您正苦于以下问题:Python get_db_path函数的具体用法?Python get_db_path怎么用?Python get_db_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_db_path函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: configure

 def configure(self, config):
     self.config = config
     logger.info('Opening chain @ %s', utils.get_db_path())
     self.blockchain = DB(utils.get_db_path())
     logger.debug('Chain @ #%d %s', self.head.number, self.head.hex_hash())
     self.log_chain()
     self.new_miner()
开发者ID:mrmayfield,项目名称:pyethereum,代码行数:7,代码来源:chainmanager.py


示例2: configure

 def configure(self, config, genesis=None):
     self.config = config
     logger.info('Opening chain @ %s', utils.get_db_path())
     db = self.blockchain = DB(utils.get_db_path())
     self.index = Index(db)
     if genesis:
         self._initialize_blockchain(genesis)
     logger.debug('Chain @ #%d %s', self.head.number, self.head.hex_hash())
     self.new_miner()
开发者ID:csbitcoin,项目名称:pyethereum,代码行数:9,代码来源:chainmanager.py


示例3: __init__

    def __init__(self,
                 prevhash='',
                 uncles_hash=block_structure_rev['uncles_hash'][2],
                 coinbase=block_structure_rev['coinbase'][2],
                 state_root='',
                 tx_list_root='',
                 difficulty=block_structure_rev['difficulty'][2],
                 number=0,
                 min_gas_price=block_structure_rev['min_gas_price'][2],
                 gas_limit=block_structure_rev['gas_limit'][2],
                 gas_used=0, timestamp=0, extra_data='', nonce='',
                 transaction_list=[],
                 uncles=[]):

        self.prevhash = prevhash
        self.uncles_hash = uncles_hash
        self.coinbase = coinbase
        self.state_root = state_root
        self.tx_list_root = tx_list_root
        self.difficulty = difficulty
        self.number = number
        self.min_gas_price = min_gas_price
        self.gas_limit = gas_limit
        self.gas_used = gas_used
        self.timestamp = timestamp
        self.extra_data = extra_data
        self.nonce = nonce
        self.transaction_list = transaction_list
        self.uncles = uncles

        self.transactions = Trie(get_db_path())
        self.transaction_count = 0

        # Fill in nodes for transaction trie
        for tx in transaction_list:
            self.add_transaction_to_list(tx)

        self.state = Trie(get_db_path(), self.state_root)

        # Basic consistency verifications
        if self.state.root != '' and self.state.db.get(self.state.root) == '':
            raise Exception("State Merkle root not found in database!")
        if self.tx_list_root != self.transactions.root:
            raise Exception("Transaction list root hash does not match!")
        if sha3(rlp.encode(self.uncles)) != self.uncles_hash:
            raise Exception("Uncle root hash does not match!")
        if len(self.extra_data) > 1024:
            raise Exception("Extra data cannot exceed 1024 bytes")
        if self.coinbase == '':
            raise Exception("Coinbase cannot be empty address")
开发者ID:zancas,项目名称:pyethereum,代码行数:50,代码来源:blocks.py


示例4: _initialize_blockchain

 def _initialize_blockchain(self, genesis=None):
     logger.info('Initializing new chain @ %s', utils.get_db_path())
     if not genesis:
         genesis = blocks.genesis()
         self.index.add_block(genesis)
     self._store_block(genesis)
     self._update_head(genesis)
开发者ID:awrelll,项目名称:pyethereum,代码行数:7,代码来源:chainmanager.py


示例5: account_to_dict

 def account_to_dict(self, address, with_storage_root=False):
     if with_storage_root:
         assert len(self.journal) == 0
     med_dict = {}
     for i, val in enumerate(self.get_acct(address)):
         name, typ, default = acct_structure[i]
         key = acct_structure[i][0]
         if name == 'storage':
             strie = trie.Trie(utils.get_db_path(), val)
             if with_storage_root:
                 med_dict['storage_root'] = strie.get_root_hash().encode('hex')
         else:
             med_dict[key] = self.caches[key].get(address, utils.printers[typ](val))
     med_dict['storage'] = {}
     d = strie.to_dict()
     for k in d.keys() + self.caches['all'].keys():
         v = d.get(k, None)
         subcache = self.caches.get('storage:'+address, {})
         v2 = subcache.get(utils.big_endian_to_int(k), None)
         hexkey = '0x'+k.encode('hex')
         if v2 is not None:
             if v2 != 0:
                 med_dict['storage'][hexkey] = '0x'+utils.int_to_big_endian(v2).encode('hex')
         elif v is not None:
             med_dict['storage'][hexkey] = '0x'+rlp.decode(v).encode('hex')
     return med_dict
开发者ID:qualiabyte,项目名称:pyethereum,代码行数:26,代码来源:blocks.py


示例6: commit_state

 def commit_state(self):
     if not len(self.journal):
         return
     for address in self.caches['all']:
         acct = rlp.decode(self.state.get(address.decode('hex'))) \
             or self.mk_blank_acct()
         for i, (key, typ, default) in enumerate(acct_structure):
             if key == 'storage':
                 t = trie.Trie(utils.get_db_path(), acct[i])
                 t.proof_mode = self.proof_mode
                 t.proof_nodes = self.proof_nodes
                 for k, v in self.caches.get('storage:'+address, {}).iteritems():
                     enckey = utils.zpad(utils.coerce_to_bytes(k), 32)
                     val = rlp.encode(utils.int_to_big_endian(v))
                     if v:
                         t.update(enckey, val)
                     else:
                         t.delete(enckey)
                 acct[i] = t.root_hash
                 if self.proof_mode == RECORDING:
                     self.proof_nodes.extend(t.proof_nodes)
             else:
                 if address in self.caches[key]:
                     v = self.caches[key].get(address, default)
                     acct[i] = utils.encoders[acct_structure[i][1]](v)
         self.state.update(address.decode('hex'), rlp.encode(acct))
     if self.proof_mode == RECORDING:
         self.proof_nodes.extend(self.state.proof_nodes)
         self.state.proof_nodes = []
     self.reset_cache()
开发者ID:qualiabyte,项目名称:pyethereum,代码行数:30,代码来源:blocks.py


示例7: account_to_dict

 def account_to_dict(self, address):
     med_dict = {}
     for i, val in enumerate(self.get_acct(address)):
         med_dict[acct_structure[i][0]] = val
     strie = trie.Trie(utils.get_db_path(), med_dict['storage']).to_dict()
     med_dict['storage'] = {utils.decode_int(k): utils.decode_int(v)
                            for k, v in strie.iteritems()}
     return med_dict
开发者ID:VIAAC,项目名称:pyethereum,代码行数:8,代码来源:blocks.py


示例8: account_to_dict

 def account_to_dict(self, address):
     med_dict = {}
     for i, val in enumerate(self.get_acct(address)):
         med_dict[acct_structure[i][0]] = val
     med_dict['code_hash'] = utils.sha3(med_dict['code']).encode('hex')
     med_dict['code'] = med_dict['code'].encode('hex')
     strie = trie.Trie(utils.get_db_path(), med_dict['storage'])
     med_dict['storage'] = {k.encode('hex'): v.encode('hex')
                            for k, v in strie.to_dict().iteritems()}
     med_dict['storage_root'] = strie.root_hash.encode('hex')
     return med_dict
开发者ID:etc255,项目名称:pyethereum,代码行数:11,代码来源:blocks.py


示例9: account_to_dict

 def account_to_dict(self, address):
     self.commit_state()
     med_dict = {}
     for i, val in enumerate(self.get_acct(address)):
         name, typ, default = acct_structure[i]
         med_dict[acct_structure[i][0]] = utils.printers[typ](val)
         if name == 'storage':
             strie = trie.Trie(utils.get_db_path(), val)
     med_dict['storage'] = {'0x'+k.encode('hex'):
                            '0x'+rlp.decode(v).encode('hex')
                            for k, v in strie.to_dict().iteritems()}
     return med_dict
开发者ID:guyz,项目名称:pyethereum,代码行数:12,代码来源:blocks.py


示例10: _account_to_dict

 def _account_to_dict(self, acct):
     med_dict = {}
     for i, (name, typ, default) in enumerate(acct_structure):
         med_dict[name] = utils.decoders[typ](acct[i])
     chash = med_dict['code']
     strie = trie.Trie(utils.get_db_path(), med_dict['storage']).to_dict()
     med_dict['code'] = \
         self.state.db.get(chash).encode('hex') if chash else ''
     med_dict['storage'] = {
         utils.decode_int(k): utils.decode_int(strie[k]) for k in strie
     }
     return med_dict
开发者ID:mrmayfield,项目名称:pyethereum,代码行数:12,代码来源:blocks.py


示例11: deserialize

    def deserialize(cls, rlpdata):
        header_args, transaction_list, uncles = rlp.decode(rlpdata)
        kargs = cls.deserialize_header(header_args)
        kargs['transaction_list'] = transaction_list
        kargs['uncles'] = uncles

        # if we don't have the state we need to replay transactions
        _db = db.DB(utils.get_db_path())
        if len(kargs['state_root']) == 32 and kargs['state_root'] in _db:
            return Block(**kargs)
        elif kargs['prevhash'] == GENESIS_PREVHASH:
            return Block(**kargs)
        else:  # no state, need to replay
            try:
                parent = get_block(kargs['prevhash'])
            except KeyError:
                raise UnknownParentException(kargs['prevhash'].encode('hex'))
            return parent.deserialize_child(rlpdata)
开发者ID:andregoiano,项目名称:pyethereum,代码行数:18,代码来源:blocks.py


示例12: __init__

    def __init__(self, data=None):

        self.reward = 10 ** 18
        self.gas_consumed = 0
        self.gaslimit = 1000000  # for now

        if not data:
            self.number = 0
            self.prevhash = ''
            self.uncles_root = ''
            self.coinbase = '0' * 40
            self.state = Trie(get_db_path())
            self.transactions_root = ''
            self.transactions = []
            self.uncles = []
            self.difficulty = 2 ** 23
            self.timestamp = 0
            self.extradata = ''
            self.nonce = 0
            return

        if re.match('^[0-9a-fA-F]*$', data):
            data = data.decode('hex')

        header,  transaction_list, self.uncles = rlp.decode(data)
        self.number = decode_int(header[0])
        self.prevhash = header[1]
        self.uncles_root = header[2]
        self.coinbase = header[3].encode('hex')
        self.state = Trie(STATEDB_DIR, header[4])
        self.transactions_root = header[5]
        self.difficulty = decode_int(header[6])
        self.timestamp = decode_int(header[7])
        self.extradata = header[8]
        self.nonce = decode_int(header[9])
        self.transactions = [Transaction(x) for x in transaction_list]

        # Verifications
        if self.state.root != '' and self.state.db.get(self.state.root) == '':
            raise Exception("State Merkle root not found in database!")
        if sha3(rlp.encode(transaction_list)) != self.transactions_root:
            raise Exception("Transaction list root hash does not match!")
        if sha3(rlp.encode(self.uncles)) != self.uncles_root:
            raise Exception("Uncle root hash does not match!")
开发者ID:jo,项目名称:pyethereum,代码行数:44,代码来源:blocks.py


示例13: deserialize

    def deserialize(cls, rlpdata):
        header_args, transaction_list, uncles = rlp.decode(rlpdata)
        assert len(header_args) == len(block_structure)
        kargs = dict(transaction_list=transaction_list, uncles=uncles)
        # Deserialize all properties
        for i, (name, typ, default) in enumerate(block_structure):
            kargs[name] = utils.decoders[typ](header_args[i])

        # if we don't have the state we need to replay transactions
        _db = db.DB(utils.get_db_path())
        if len(kargs['state_root']) == 32 and kargs['state_root'] in _db:
            return Block(**kargs)
        elif kargs['prevhash'] == GENESIS_PREVHASH:
            return Block(**kargs)
        else:  # no state, need to replay
            try:
                parent = get_block(kargs['prevhash'])
            except KeyError:
                raise UnknownParentException(kargs['prevhash'].encode('hex'))
            return parent.deserialize_child(rlpdata)
开发者ID:etc255,项目名称:pyethereum,代码行数:20,代码来源:blocks.py


示例14: commit_state

 def commit_state(self):
     for address in self.caches['all']:
         acct = rlp.decode(self.state.get(address.decode('hex'))) \
             or self.mk_blank_acct()
         for i, (key, typ, default) in enumerate(acct_structure):
             if key == 'storage':
                 t = trie.Trie(utils.get_db_path(), acct[i])
                 for k, v in self.caches[key].get(address, {}).iteritems():
                     enckey = utils.zpad(utils.coerce_to_bytes(k), 32)
                     val = rlp.encode(utils.int_to_big_endian(v))
                     if v:
                         t.update(enckey, val)
                     else:
                         t.delete(enckey)
                 acct[i] = t.root_hash
             else:
                 if address in self.caches[key]:
                     v = self.caches[key].get(address, default)
                     acct[i] = utils.encoders[acct_structure[i][1]](v)
         self.state.update(address.decode('hex'), rlp.encode(acct))
     self.reset_cache()
开发者ID:andregoiano,项目名称:pyethereum,代码行数:21,代码来源:blocks.py


示例15: account_to_dict

 def account_to_dict(self, address, with_storage_root=False):
     if with_storage_root:
         assert len(self.journal) == 0
     med_dict = {}
     for i, val in enumerate(self.get_acct(address)):
         name, typ, default = acct_structure[i]
         key = acct_structure[i][0]
         if name == "storage":
             strie = trie.Trie(utils.get_db_path(), val)
             if with_storage_root:
                 med_dict["storage_root"] = strie.get_root_hash().encode("hex")
         else:
             med_dict[key] = self.caches[key].get(address, utils.printers[typ](val))
     med_dict["storage"] = {}
     for k, v in strie.to_dict().iteritems():
         subcache = self.caches.get("storage:" + address, {})
         v2 = subcache.get(utils.big_endian_to_int(k), None)
         hexkey = "0x" + k.encode("hex")
         if v2 is not None:
             med_dict["storage"][hexkey] = "0x" + utils.int_to_big_endian(v2).encode("hex")
         else:
             med_dict["storage"][hexkey] = "0x" + v.encode("hex")
     return med_dict
开发者ID:miro-blakeley,项目名称:pyethereum,代码行数:23,代码来源:blocks.py


示例16: __init__

 def __init__(self):
     self.db = db.DB(utils.get_db_path())
     self.pagenation = 1000
开发者ID:mrmayfield,项目名称:pyethereum,代码行数:3,代码来源:indexdb.py


示例17: has_block

def has_block(blockhash):
    return blockhash in db.DB(utils.get_db_path())
开发者ID:etc255,项目名称:pyethereum,代码行数:2,代码来源:blocks.py


示例18: get_block

def get_block(blockhash):
    return Block.deserialize(db.DB(utils.get_db_path()).get(blockhash))
开发者ID:etc255,项目名称:pyethereum,代码行数:2,代码来源:blocks.py


示例19: __init__

    def __init__(
        self,
        prevhash="\00" * 32,
        uncles_hash=block_structure_rev["uncles_hash"][2],
        coinbase=block_structure_rev["coinbase"][2],
        state_root=trie.BLANK_ROOT,
        tx_list_root=trie.BLANK_ROOT,
        difficulty=block_structure_rev["difficulty"][2],
        number=0,
        min_gas_price=block_structure_rev["min_gas_price"][2],
        gas_limit=block_structure_rev["gas_limit"][2],
        gas_used=0,
        timestamp=0,
        extra_data="",
        nonce="",
        transaction_list=[],
        uncles=[],
        header=None,
    ):

        self.prevhash = prevhash
        self.uncles_hash = uncles_hash
        self.coinbase = coinbase
        self.difficulty = difficulty
        self.number = number
        self.min_gas_price = min_gas_price
        self.gas_limit = gas_limit
        self.gas_used = gas_used
        self.timestamp = timestamp
        self.extra_data = extra_data
        self.nonce = nonce
        self.uncles = uncles
        self.suicides = []
        self.postqueue = []
        self.caches = {"balance": {}, "nonce": {}, "code": {}, "all": {}}
        self.journal = []

        self.transactions = trie.Trie(utils.get_db_path(), tx_list_root)
        self.transaction_count = 0

        self.state = trie.Trie(utils.get_db_path(), state_root)

        if transaction_list:
            # support init with transactions only if state is known
            assert self.state.root_hash_valid()
            for tx_lst_serialized, state_root, gas_used_encoded in transaction_list:
                self._add_transaction_to_list(tx_lst_serialized, state_root, gas_used_encoded)

        # make sure we are all on the same db
        assert self.state.db.db == self.transactions.db.db

        # use de/encoders to check type and validity
        for name, typ, d in block_structure:
            v = getattr(self, name)
            assert utils.decoders[typ](utils.encoders[typ](v)) == v

        # Basic consistency verifications
        if not self.state.root_hash_valid():
            raise Exception("State Merkle root not found in database! %r" % self)
        if tx_list_root != self.transactions.root_hash:
            raise Exception("Transaction list root hash does not match!")
        if not self.transactions.root_hash_valid():
            raise Exception("Transactions root not found in database! %r" % self)
        if len(self.extra_data) > 1024:
            raise Exception("Extra data cannot exceed 1024 bytes")
        if self.coinbase == "":
            raise Exception("Coinbase cannot be empty address")
        if not self.is_genesis() and self.nonce and not check_header_pow(header or self.list_header()):
            raise Exception("PoW check failed")
开发者ID:miro-blakeley,项目名称:pyethereum,代码行数:69,代码来源:blocks.py


示例20: get_storage

 def get_storage(self, address):
     storage_root = self._get_acct_item(address, 'storage')
     return trie.Trie(utils.get_db_path(), storage_root)
开发者ID:etc255,项目名称:pyethereum,代码行数:3,代码来源:blocks.py



注:本文中的utils.get_db_path函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_default_redirect函数代码示例发布时间:2022-05-26
下一篇:
Python utils.get_db函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap