def sequencing_hook(self, db_session, parent_block_data, parent_sequenced_block_data):

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

            if proposal_audit.type_id == DEMOCRACY_PROPOSAL_AUDIT_TYPE_PROPOSED:
                status = 'Proposed'
            elif proposal_audit.type_id == DEMOCRACY_PROPOSAL_AUDIT_TYPE_TABLED:
                status = 'Tabled'
            else:
                status = '[unknown]'

            try:
                proposal = DemocracyProposal.query(db_session).filter_by(id=proposal_audit.democracy_proposal_id).one()

                proposal.status = status
                proposal.updated_at_block = self.block.id

            except NoResultFound:

                proposal = DemocracyProposal(
                    id=proposal_audit.democracy_proposal_id,
                    proposal=proposal_audit.data['proposal'],
                    bond=proposal_audit.data['bond'],
                    created_at_block=self.block.id,
                    updated_at_block=self.block.id,
                    status=status
                )

            proposal.save(db_session)
    def accumulation_hook(self, db_session):

        # Check event requirements
        if len(self.event.attributes) == 3 and self.event.attributes[0]['type'] == 'PropIndex' \
                and self.event.attributes[1]['type'] == 'Balance' and \
                self.event.attributes[2]['type'] == 'Vec<AccountId>':

            proposal_audit = DemocracyProposalAudit(
                democracy_proposal_id=self.event.attributes[0]['value'],
                block_id=self.event.block_id,
                extrinsic_idx=self.event.extrinsic_idx,
                event_idx=self.event.event_idx,
                type_id=DEMOCRACY_PROPOSAL_AUDIT_TYPE_TABLED)

            proposal_audit.data = self.event.attributes

            proposal_audit.save(db_session)
    def accumulation_hook(self, db_session):

        # Check event requirements
        if len(self.event.attributes) == 2 and \
                self.event.attributes[0]['type'] == 'PropIndex' and self.event.attributes[1]['type'] == 'Balance':

            proposal_audit = DemocracyProposalAudit(
                democracy_proposal_id=self.event.attributes[0]['value'],
                block_id=self.event.block_id,
                extrinsic_idx=self.event.extrinsic_idx,
                event_idx=self.event.event_idx,
                type_id=DEMOCRACY_PROPOSAL_AUDIT_TYPE_PROPOSED
            )

            proposal_audit.data = {'bond': self.event.attributes[1]['value'], 'proposal': None}

            for param in self.extrinsic.params:
                if param.get('name') == 'proposal':
                    proposal_audit.data['proposal'] = param.get('value')

            proposal_audit.save(db_session)
 def accumulation_revert(self, db_session):
     for item in DemocracyProposalAudit.query(db_session).filter_by(block_id=self.block.id):
         db_session.delete(item)