Exemplo n.º 1
0
    def sequencing_hook(self, db_session, parent_block_data, parent_sequenced_block_data):

        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=ss58_encode_account_index(
                        account_index_audit.account_index_id,
                        SUBSTRATE_ADDRESS_TYPE
                    ),
                    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
    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'] = ss58_encode(item['value'].replace('0x', ''),
                                            SUBSTRATE_ADDRESS_TYPE)

            elif item['type'] in ['AccountIndex'] and item['value']:
                # SS58 format Account index
                item['orig_value'] = item['value']
                item['value'] = ss58_encode_account_index(
                    item['value'], SUBSTRATE_ADDRESS_TYPE)
            elif item['type'] in ['AuthorityList'] and item['value']:
                for idx, vec_item in enumerate(item['value']):
                    item['value'][idx]['AuthorityId'] = {
                        'name':
                        'AuthorityId',
                        'type':
                        'Address',
                        'value':
                        ss58_encode(vec_item['AuthorityId'].replace('0x', ''),
                                    SUBSTRATE_ADDRESS_TYPE),
                        'orig_value':
                        vec_item['AuthorityId'].replace('0x', '')
                    }
            elif item['type'] == 'Vec<IdentificationTuple>':
                for idx, vec_item in enumerate(item['value']):
                    item['value'][idx]['validatorId'] = {
                        'name':
                        'validatorId',
                        'type':
                        'Address',
                        'value':
                        ss58_encode(vec_item['validatorId'].replace('0x', ''),
                                    SUBSTRATE_ADDRESS_TYPE),
                        'orig_value':
                        vec_item['validatorId'].replace('0x', '')
                    }

                    for other_idx, other_item in enumerate(
                            vec_item['exposure']['others']):
                        item['value'][idx]['exposure']['others'][other_idx][
                            'who'] = {
                                'name':
                                'validatorId',
                                'type':
                                'Address',
                                'value':
                                ss58_encode(
                                    other_item['who'].replace('0x', ''),
                                    SUBSTRATE_ADDRESS_TYPE),
                                'orig_value':
                                other_item['who'].replace('0x', '')
                            }

        return obj_dict
Exemplo n.º 3
0
    def sequencing_hook(self, db_session, parent_block_data, parent_sequenced_block_data):

        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 == settings.ACCOUNT_INDEX_AUDIT_TYPE_NEW:

                # Check if account index already exists
                account_index = AccountIndex.query(db_session).filter_by(
                    id=account_index_audit.account_index_id
                ).first()

                if not account_index:

                    account_index = AccountIndex(
                        id=account_index_audit.account_index_id,
                        created_at_block=self.block.id
                    )

                account_index.account_id = account_index_audit.account_id
                account_index.short_address = ss58_encode_account_index(
                    account_index_audit.account_index_id,
                    settings.SUBSTRATE_ADDRESS_TYPE
                )
                account_index.updated_at_block = self.block.id

                account_index.save(db_session)

                # Update index in corresponding account
                account = Account.query(db_session).get(account_index.account_id)

                if account:
                    account.index_address = account_index.short_address
                    account.save(db_session)

            elif account_index_audit.type_id == settings.ACCOUNT_INDEX_AUDIT_TYPE_REAPED:

                if account_index_audit.account_index_id:
                    account_index_list = AccountIndex.query(db_session).filter_by(
                        id=account_index_audit.account_index_id
                    )
                else:
                    account_index_list = AccountIndex.query(db_session).filter_by(
                        account_id=account_index_audit.account_id
                    )

                for account_index in account_index_list:

                    account_index.account_id = None
                    account_index.is_reclaimable = True
                    account_index.updated_at_block = self.block.id
                    account_index.save(db_session)
Exemplo n.º 4
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'] = ss58_encode(item['value'].replace('0x', ''), SUBSTRATE_ADDRESS_TYPE)

            elif item['type'] in ['AccountIndex'] and item['value']:
                # SS58 format Account index
                item['orig_value'] = item['value']
                item['value'] = ss58_encode_account_index(item['value'], SUBSTRATE_ADDRESS_TYPE)

        return obj_dict