Пример #1
0
    def serialize_formatting_hook(self, obj_dict):
        obj_dict['attributes']['validator_stash_id'] = self.validator_stash
        if self.validator_stash:
            obj_dict['attributes']['validator_stash'] = bech32.encode(
                HRP,
                bytes().fromhex(self.validator_stash.replace('0x', '')))
        else:
            obj_dict['attributes']['validator_stash'] = None

        obj_dict['attributes'][
            'validator_controller_id'] = self.validator_controller

        if self.validator_controller:
            obj_dict['attributes']['validator_controller'] = bech32.encode(
                HRP,
                bytes().fromhex(self.validator_controller.replace('0x', '')))
        else:
            obj_dict['attributes']['validator_controller'] = None

        obj_dict['attributes']['validator_session_id'] = self.validator_session
        if self.validator_session:
            obj_dict['attributes']['validator_session'] = bech32.encode(
                HRP,
                bytes().fromhex(self.validator_session.replace('0x', '')))
        else:
            obj_dict['attributes']['validator_session'] = None

        return obj_dict
Пример #2
0
 def serialize_formatting_hook(self, obj_dict):
     obj_dict['attributes']['vote_address'] = bech32.encode(
         HRP,
         bytes().fromhex(self.vote_account_id.replace('0x', '')))
     obj_dict['attributes']['stash_address'] = bech32.encode(
         HRP,
         bytes().fromhex(self.stash_account_id.replace('0x', '')))
     return obj_dict
Пример #3
0
    def serialize_formatting_hook(self, obj_dict):
        obj_dict['attributes']['nominator_stash_id'] = self.nominator_stash
        obj_dict['attributes']['nominator_stash'] = bech32.encode(
            HRP,
            bytes().fromhex(self.nominator_stash.replace('0x', '')))

        if self.nominator_controller:
            obj_dict['attributes'][
                'nominator_controller_id'] = self.nominator_controller
            obj_dict['attributes']['nominator_controller'] = bech32.encode(
                HRP,
                bytes().fromhex(self.nominator_controller.replace('0x', '')))

        return obj_dict
Пример #4
0
    def sequencing_hook(self, db_session, parent_block_data,
                        parent_sequenced_block_data):
        #print('start add_block Process block processors {} =='.format("Process block AccountIndexBlockProcessor "))

        for account_index_audit in AccountIndexAudit.query(
                db_session).filter_by(
                    block_id=self.block.id).order_by('event_idx'):

            if account_index_audit.type_id == ACCOUNT_INDEX_AUDIT_TYPE_NEW:

                account_index = AccountIndex(
                    id=account_index_audit.account_index_id,
                    account_id=account_index_audit.account_id,
                    short_address=bech32.encode(
                        HRP,
                        bytes().fromhex(account_index_audit.account_index_id)),
                    created_at_block=self.block.id,
                    updated_at_block=self.block.id)

                account_index.save(db_session)

            elif account_index_audit.type_id == ACCOUNT_INDEX_AUDIT_TYPE_REAPED:

                for account_index in AccountIndex.query(db_session).filter_by(
                        account_id=account_index_audit.account_id):

                    account_index.account_id = None
                    account_index.is_reclaimable = True
                    account_index.updated_at_block = self.block.id
Пример #5
0
    def sequencing_hook(self, db_session, parent_block_data,
                        parent_sequenced_block_data):

        for account_audit in AccountAudit.query(db_session).filter_by(
                block_id=self.block.id).order_by('event_idx'):
            try:
                account = Account.query(db_session).filter_by(
                    id=account_audit.account_id).one()

                if account_audit.type_id == ACCOUNT_AUDIT_TYPE_REAPED:
                    account.count_reaped += 1
                    account.is_reaped = True

                elif account_audit.type_id == ACCOUNT_AUDIT_TYPE_NEW:
                    account.is_reaped = False

                account.updated_at_block = self.block.id

            except NoResultFound:

                account = Account(id=account_audit.account_id,
                                  address=bech32.encode(
                                      HRP,
                                      bytes().fromhex(
                                          account_audit.account_id)),
                                  created_at_block=self.block.id,
                                  updated_at_block=self.block.id,
                                  balance=0)

                # If reaped but does not exist, create new account for now
                if account_audit.type_id != ACCOUNT_AUDIT_TYPE_NEW:
                    account.is_reaped = True
                    account.count_reaped = 1
            account.shard_num = random.randint(1, 10000)
            account.save(db_session)
 def serialize_item(self, item):
     if item.address is None:
         return None
     else:
         sender = bech32.encode(
             'yee',
             bytes().fromhex(
                 '3abc90b67dadf98f01633ffc6ffc51fe3953b9ce81da4b7b266684897042992c'
             ))
Пример #7
0
    def serialize_formatting_hook(self, obj_dict):
        obj_dict['attributes']['account_id'] = self.account_id
        if self.account_id:
            obj_dict['attributes']['address'] = bech32.encode(
                HRP,
                bytes().fromhex(self.account_id.replace('0x', '')))
        else:
            obj_dict['attributes']['address'] = None

        return obj_dict
Пример #8
0
    def serialize_formatting_hook(self, obj_dict):

        if self.type_id == LOG_TYPE_AUTHORITIESCHANGE:

            for idx, item in enumerate(
                    obj_dict['attributes']['data']['value']):
                obj_dict['attributes']['data']['value'][idx] = bech32.encode(
                    HRP,
                    bytes().fromhex(item.replace('0x', '')))
        return obj_dict
    def serialize_item(self, item):
        print(item.success)
        if item.datetime is not None:
            dt = datetime.fromtimestamp(time.mktime(item.datetime.timetuple()),
                                        timezone(timedelta(hours=8)))
            it = datetime.strftime(dt, '%Y-%m-%d %H:%M:%S')
        else:
            it = ''

        return {
            'type': 'balancetransfer',
            'id': item.extrinsic_hash,
            'attributes': {
                'block_id':
                item.block_id,
                'extrinsic':
                item.extrinsic,
                'extrinsic_hash':
                item.extrinsic_hash,
                'extrinsic_idx':
                item.extrinsic_idx,
                'sender':
                bech32.encode(HRP,
                              bytes().fromhex(item.address)),
                'sender_id':
                item.address,
                'destination':
                bech32.encode(HRP,
                              bytes().fromhex(item.params[0]['value'])),
                'destination_id':
                item.params[0]['value'].replace('0x', ''),
                'value':
                item.params[1]['value'],
                'shard_num':
                item.shard_num,
                'success':
                item.success,
                'error':
                item.error,
                'datetime':
                it
            }
        }
    def serialize_item(self, item):
        address = bech32.encode(HRP, bytes().fromhex(item.id))

        substrate = SubstrateInterface(
            SUBSTRATE_RPC_URL, metadata_version=SUBSTRATE_METADATA_VERSION)
        data = item.serialize()
        data['attributes']['free_balance'] = int(
            substrate.get_Balance(address), 16)

        data['attributes']['nonce'] = int(substrate.get_Nonce(address), 16)

        return data
 def serialize_item(self, item):
     json_dic = []
     attributes = None
     if item.module_id == 'assets' and item.event_id == 'Issued':
         json_dic = [{
             "type": "AssetDetail",
             "value": {
                 "shard_code": '',
                 "id": '',
                 "name": '',
                 "issuer": '',
                 "decimals": '',
                 "total_supply": ''
             },
             "valueRaw": ""
         }]
         json_str = json_dic[0]['value']
         shard_code_hex = item.attributes[0]['valueRaw'].upper()
         shard_code_10 = int(shard_code_hex.upper(), 16)
         shard_code_2 = str(bin(shard_code_10))
         shard_count = 4
         shard_num_2 = shard_code_2[-int(math.log2(shard_count)):]
         shard_num = int(shard_num_2, 2)
         print(shard_num)
         json_str['shard_code'] = item.attributes[0]['valueRaw']
         json_str['id'] = item.attributes[1]['value']
         json_str['name'] = item.attributes[2]['value']
         json_str['issuer'] = bech32.encode(
             HRP,
             bytes().fromhex(item.attributes[3]['value'].replace('0x', '')))
         json_str['decimals'] = item.attributes[5]['value']
         json_str['total_supply'] = item.attributes[4]['value']
         attributes = json_dic
     else:
         attributes = item.attributes
     return {
         'type': 'event',
         'id': item.id,
         'attributes': {
             'id': item.id,
             'block_id': item.block_id,
             'event_idx': item.event_idx,
             'extrinsic_idx': item.extrinsic_idx,
             'type': item.type,
             'module_id': item.module_id,
             'event_id': item.event_id,
             'system': item.system,
             'module': item.module,
             'phase': item.module,
             'attributes': attributes,
             'shard_num': item.shard_num
         }
     }
Пример #12
0
    def serialize_formatting_hook(self, obj_dict):

        for item in obj_dict['attributes']['attributes']:
            if item['type'] in ['AccountId', 'AuthorityId', 'Address'
                                ] and item['value']:
                # SS58 format AccountId public keys
                item['orig_value'] = item['value'].replace('0x', '')
                item['value'] = bech32.encode(
                    HRP,
                    bytes().fromhex(item['value'].replace('0x', '')))
            # bech32.encode(HRP, bytes().fromhex(item['value'].replace('0x', '')))

            elif item['type'] in ['AccountIndex'] and item['value']:
                # SS58 format Account index
                # {'type': 'AccountIndex', 'value': 9, 'valueRaw': '09000000'}
                item['orig_value'] = item['value']
                item['orig_value'] = item['value']
                if not str(item['value']).isdigit():
                    item['value'] = bech32.encode(
                        HRP,
                        bytes().fromhex(item['value']))

        return obj_dict
Пример #13
0
    def serialize_formatting_hook(self, obj_dict):

        if obj_dict['attributes'].get('address'):
            obj_dict['attributes']['address_id'] = obj_dict['attributes'][
                'address'].replace('0x', '')
            obj_dict['attributes']['address'] = bech32.encode(
                HRP,
                bytes().fromhex(obj_dict['attributes']['address'].replace(
                    '0x', '')))

        for item in obj_dict['attributes']['params']:
            # SS58 format Addresses public keys
            if item['type'] in ['Address', 'AccountId'] and item['value']:
                self.format_address(item)
            elif item['type'] in [
                    'Vec<Address>', 'Vec<AccountId>',
                    'Vec<<Lookup as StaticLookup>::Source>'
            ] and item['value']:
                for idx, vec_item in enumerate(item['value']):
                    item['value'][idx] = {
                        'name':
                        idx,
                        'type':
                        'Address',
                        'value':
                        bech32.encode(
                            HRP,
                            bytes().fromhex(vec_item.replace('0x', ''))),
                        'orig_value':
                        vec_item.replace('0x', '')
                    }
            elif item['type'] == 'Box<Proposal>':
                for proposal_param in item['value'].get('params', []):
                    if proposal_param['type'] == 'Address':
                        self.format_address(proposal_param)

        return obj_dict
    def get_relationships(self, include_list, item):
        relationships = {}

        if 'recent_extrinsics' in include_list:
            relationships['recent_extrinsics'] = Extrinsic.query(
                self.session).filter_by(address=item.id).order_by(
                    Extrinsic.block_id.desc())[:10]

        if 'indices' in include_list:
            relationships['indices'] = AccountIndex.query(
                self.session).filter_by(account_id=item.id).order_by(
                    AccountIndex.updated_at_block.desc())

        if 'rewards' in include_list:
            relationships['rewards'] = Block.query(self.session).filter_by(
                coinbase=bech32.encode(HRP,
                                       bytes().fromhex(item.id))).order_by(
                                           Block.id.desc())

            #  Block.query(self.session).order_by(Block.id.desc()
            # count = self.session.query(func.count(Block.id)).filter(Block.coinbase == item_id).scalar()

        return relationships
Пример #15
0
 def format_address(self, item):
     item['orig_value'] = item['value'].replace('0x', '')
     item['value'] = bech32.encode(
         HRP,
         bytes().fromhex(item['value'].replace('0x', '')))
     return item