def print_shard_balance(env, rb, full_shard_id): shard = Shard(env, full_shard_id, None) state = shard.state state.init_from_root_block(rb) print("Full shard id: %d" % full_shard_id) print("Block height: %d" % state.header_tip.height) print("Trie hash: %s" % state.meta_tip.hash_evm_state_root.hex()) trie = Trie(state.raw_db, state.meta_tip.hash_evm_state_root) key = trie.next(bytes(32)) total = 0 while key is not None: rlpdata = trie.get(key) o = rlp.decode(rlpdata, _Account) tb = TokenBalances(o.token_balances, state.raw_db) balance = tb.balance(token_id_encode("QKC")) print("Key: %s, Balance: %s" % (key.hex(), balance)) total += balance key = trie.next(key) print("Total balance in shard: %d" % total) return total, state.header_tip.height
async def create_shards(self, root_block: RootBlock): """ Create shards based on GENESIS config and root block height if they have not been created yet.""" async def __init_shard(shard): await shard.init_from_root_block(root_block) await shard.create_peer_shard_connections(self.cluster_peer_ids, self.master) branch = Branch(shard.full_shard_id) self.shards[branch] = shard if self.mining: shard.miner.start() new_shards = [] for (full_shard_id, shard_config) in self.env.quark_chain_config.shards.items(): branch = Branch(full_shard_id) if branch in self.shards: continue if not self.__cover_shard_id( full_shard_id) or not shard_config.GENESIS: continue if root_block.header.height >= shard_config.GENESIS.ROOT_HEIGHT: new_shards.append(Shard(self.env, full_shard_id, self)) await asyncio.gather(*[__init_shard(shard) for shard in new_shards])
def print_all_shard_balances(env, rb, args): total = 0 accounts = 0 if args.recipient: for full_shard_id in env.quark_chain_config.shards: shard = Shard(env, full_shard_id, None) state = shard.state state.init_from_root_block(rb) total += sum(state.get_balances(args.recipient).values()) print("\nTotal balance of recipient %d: %d" % (args.recipient, total)) else: balance_list = [] for full_shard_id in env.quark_chain_config.shards: balance_list.append( print_shard_balance(env, rb, full_shard_id, args)) total += balance_list[-1][0] accounts += balance_list[-1][2] print("Summary:") print("Root block height: %d" % rb.header.height) for idx, full_shard_id in enumerate(env.quark_chain_config.shards): print("Shard id: %d, height: %d, balance: %d, accounts: %d" % ( full_shard_id, balance_list[idx][1], balance_list[idx][0], balance_list[idx][2], )) print("\nTotal accounts in network: %d" % accounts) print("Total balance in network: %d" % total)
async def create_shards(self, root_block: RootBlock): """ Create shards based on GENESIS config and root block height if they have not been created yet.""" futures = [] for shard_id, shard_config in enumerate(self.env.quark_chain_config.SHARD_LIST): branch = Branch.create(self.env.quark_chain_config.SHARD_SIZE, shard_id) if branch in self.shards: continue if not self.__cover_shard_id(shard_id) or not shard_config.GENESIS: continue if root_block.header.height >= shard_config.GENESIS.ROOT_HEIGHT: shard = Shard(self.env, shard_id, self) futures.append(shard.init_from_root_block(root_block)) self.shards[branch] = shard if self.mining: shard.miner.start() await asyncio.gather(*futures)
def print_recipient_balance(env, rb, args): assert args.recipient.startswith("0x") recipient = bytes.fromhex(args.recipient[2:]) shard = Shard(env, args.full_shard_id, None) state = shard.state state.init_from_root_block(rb) if args.minor_block_height: balance = state.get_balances(recipient, args.minor_block_height) else: balance = state.get_balances(recipient) print("Recipient: %s\nBalances: " % args.recipient, end="", flush=True) pprint(balance)
def print_recipient_balance(env, rb, args): recipient = args.recipient shard = Shard(env, args.full_shard_id, None) state = shard.state state.init_from_root_block(rb) if args.minor_block_height: balance = state.get_balances(recipient, args.minor_block_height) else: balance = state.get_balances(recipient) if balance: print("Recipient: %d,balance: %d" % (recipient, balance)) else: print("Recipient not found.")
def get_shard_state(full_shard_id): env, args = parse_args() shard = Shard(env, full_shard_id, None) return shard.state