Beispiel #1
0
    def register(cls, names, block_date):
        """Block processing: register "candidate" names.

        There are four ops which can result in account creation:
        *account_create*, *account_create_with_delegation*, *pow*,
        and *pow2*. *pow* ops result in account creation only when
        the account they name does not already exist!
        """

        # filter out names which already registered
        new_names = list(filter(lambda n: not cls.exists(n), set(names)))
        if not new_names:
            return

        for name in new_names:
            DB.query(
                "INSERT INTO hive_accounts (name, created_at) "
                "VALUES (:name, :date)",
                name=name,
                date=block_date)

        # pull newly-inserted ids and merge into our map
        sql = "SELECT name, id FROM hive_accounts WHERE name IN :names"
        for name, _id in DB.query_all(sql, names=tuple(new_names)):
            cls._ids[name] = _id

        # post-insert: pass to communities to check for new registrations
        from hive.indexer.community import Community, START_DATE
        if block_date > START_DATE:
            Community.register(new_names, block_date)
Beispiel #2
0
    def register(cls, name, op_details, block_date, block_num):
        """Block processing: register "candidate" names.

        There are four ops which can result in account creation:
        *account_create*, *account_create_with_delegation*, *pow*,
        and *pow2*. *pow* ops result in account creation only when
        the account they name does not already exist!
        """

        if name is None:
            return False

        # filter out names which already registered
        if cls.exists(name):
            return True

        ( _posting_json_metadata, _json_metadata ) = get_profile_str( op_details )

        sql = """
                  INSERT INTO hive_accounts (name, created_at, posting_json_metadata, json_metadata )
                  VALUES ( '{}', '{}', {}, {} )
                  RETURNING id
              """.format( name, block_date, cls.get_json_data( _posting_json_metadata ), cls.get_json_data( _json_metadata ) )

        new_id = DB.query_one( sql )
        if new_id is None:
             return False
        cls._ids[name] = new_id

        # post-insert: pass to communities to check for new registrations
        from hive.indexer.community import Community
        if block_num > Community.start_block:
            Community.register(name, block_date, block_num)

        return True